LEFT | RIGHT |
(no file at all) | |
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 Loading... |
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_EQ(0, value.AsInt()); |
225 } | 235 } |
LEFT | RIGHT |