Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: test/JsValue.cpp

Issue 29813591: Issue 6526 - Use Maybe<> version of soon to be deprecated API in v8 6.7 (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Left Patch Set: Created June 22, 2018, 8:54 p.m.
Right Patch Set: Throw on empty value (AsInt() and As Bool()) Created Aug. 7, 2018, 2:36 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« src/JsValue.cpp ('K') | « src/Utils.h ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include "BaseJsTest.h" 18 #include "BaseJsTest.h"
19 19
20 #include "../src/Utils.h"
21
20 namespace 22 namespace
21 { 23 {
22 class JsValueTest : public BaseJsTest 24 class JsValueTest : public BaseJsTest
23 { 25 {
24 }; 26 };
27 }
28
29 TEST_F(JsValueTest, Checked)
30 {
31 auto value = v8::MaybeLocal<bool>();
32 ASSERT_ANY_THROW(CHECKED_TO_LOCAL(GetJsEngine().GetIsolate(),
33 std::move(value)));
25 } 34 }
26 35
27 TEST_F(JsValueTest, UndefinedValue) 36 TEST_F(JsValueTest, UndefinedValue)
28 { 37 {
29 auto value = GetJsEngine().Evaluate("undefined"); 38 auto value = GetJsEngine().Evaluate("undefined");
30 ASSERT_TRUE(value.IsUndefined()); 39 ASSERT_TRUE(value.IsUndefined());
31 ASSERT_FALSE(value.IsNull()); 40 ASSERT_FALSE(value.IsNull());
32 ASSERT_FALSE(value.IsString()); 41 ASSERT_FALSE(value.IsString());
33 ASSERT_FALSE(value.IsBool()); 42 ASSERT_FALSE(value.IsBool());
34 ASSERT_FALSE(value.IsNumber()); 43 ASSERT_FALSE(value.IsNumber());
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 ASSERT_TRUE(value.AsBool()); 163 ASSERT_TRUE(value.AsBool());
155 ASSERT_ANY_THROW(value.AsList()); 164 ASSERT_ANY_THROW(value.AsList());
156 ASSERT_EQ(2, value.GetProperty("x").AsInt()); 165 ASSERT_EQ(2, value.GetProperty("x").AsInt());
157 value.SetProperty("x", 12); 166 value.SetProperty("x", 12);
158 ASSERT_EQ(12, value.GetProperty("x").AsInt()); 167 ASSERT_EQ(12, value.GetProperty("x").AsInt());
159 value.SetProperty("x", GetJsEngine().NewValue(15)); 168 value.SetProperty("x", GetJsEngine().NewValue(15));
160 ASSERT_EQ(15, value.GetProperty("x").AsInt()); 169 ASSERT_EQ(15, value.GetProperty("x").AsInt());
161 ASSERT_EQ("Foo", value.GetClass()); 170 ASSERT_EQ("Foo", value.GetClass());
162 ASSERT_EQ(3u, value.GetOwnPropertyNames().size()); 171 ASSERT_EQ(3u, value.GetOwnPropertyNames().size());
163 ASSERT_ANY_THROW(value.Call()); 172 ASSERT_ANY_THROW(value.Call());
173 ASSERT_TRUE(value.GetProperty("bar").IsUndefined());
164 } 174 }
165 175
166 TEST_F(JsValueTest, ArrayValue) 176 TEST_F(JsValueTest, ArrayValue)
167 { 177 {
168 auto value = GetJsEngine().Evaluate("[5,8,12]"); 178 auto value = GetJsEngine().Evaluate("[5,8,12]");
169 ASSERT_FALSE(value.IsUndefined()); 179 ASSERT_FALSE(value.IsUndefined());
170 ASSERT_FALSE(value.IsNull()); 180 ASSERT_FALSE(value.IsNull());
171 ASSERT_FALSE(value.IsString()); 181 ASSERT_FALSE(value.IsString());
172 ASSERT_FALSE(value.IsBool()); 182 ASSERT_FALSE(value.IsBool());
173 ASSERT_FALSE(value.IsNumber()); 183 ASSERT_FALSE(value.IsNumber());
(...skipping 30 matching lines...) Expand all
204 params.push_back(GetJsEngine().NewValue("xyz")); 214 params.push_back(GetJsEngine().NewValue("xyz"));
205 ASSERT_EQ("2/5/xyz", value.Call(params, thisPtr).AsString()); 215 ASSERT_EQ("2/5/xyz", value.Call(params, thisPtr).AsString());
206 } 216 }
207 217
208 TEST_F(JsValueTest, JsValueCallSingleArg) 218 TEST_F(JsValueTest, JsValueCallSingleArg)
209 { 219 {
210 auto func = GetJsEngine().Evaluate("(function(arg) {return arg * 2;})"); 220 auto func = GetJsEngine().Evaluate("(function(arg) {return arg * 2;})");
211 EXPECT_EQ(10, func.Call(GetJsEngine().NewValue(5)).AsInt()); 221 EXPECT_EQ(10, func.Call(GetJsEngine().NewValue(5)).AsInt());
212 } 222 }
213 223
214 TEST_F(JsValueTest, ThrowingConversion) 224 TEST_F(JsValueTest, ThrowingConversion)
sergei 2018/08/07 13:14:51 It's unrelated but OK.
215 { 225 {
216 const std::string source("\ 226 const std::string source("\
217 function Foo() {\ 227 function Foo() {\
218 this.toString = function() {throw 'test1';};\ 228 this.toString = function() {throw 'test1';};\
219 this.valueOf = function() {throw 'test2';};\ 229 this.valueOf = function() {throw 'test2';};\
220 };\ 230 };\
221 new Foo()"); 231 new Foo()");
222 auto value = GetJsEngine().Evaluate(source); 232 auto value = GetJsEngine().Evaluate(source);
223 ASSERT_EQ("", value.AsString()); 233 ASSERT_EQ("", value.AsString());
224 ASSERT_EQ(0, value.AsInt()); 234 ASSERT_ANY_THROW(value.AsInt());
225 } 235 }
LEFTRIGHT
« src/Utils.h ('k') | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld