| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 #include "v8-profiler.h" |
| 20 namespace | 20 namespace |
| 21 { | 21 { |
| 22 class JsValueTest : public BaseJsTest | 22 class JsValueTest : public BaseJsTest |
| 23 { | 23 { |
| 24 }; | 24 }; |
| 25 } | 25 } |
| 26 | 26 |
| 27 |
| 27 TEST_F(JsValueTest, UndefinedValue) | 28 TEST_F(JsValueTest, UndefinedValue) |
| 28 { | 29 { |
| 29 AdblockPlus::JsValuePtr value = jsEngine->Evaluate("undefined"); | 30 AdblockPlus::JsValuePtr value = jsEngine->Evaluate("undefined"); |
| 30 ASSERT_TRUE(value->IsUndefined()); | 31 ASSERT_TRUE(value->IsUndefined()); |
| 31 ASSERT_FALSE(value->IsNull()); | 32 ASSERT_FALSE(value->IsNull()); |
| 32 ASSERT_FALSE(value->IsString()); | 33 ASSERT_FALSE(value->IsString()); |
| 33 ASSERT_FALSE(value->IsBool()); | 34 ASSERT_FALSE(value->IsBool()); |
| 34 ASSERT_FALSE(value->IsNumber()); | 35 ASSERT_FALSE(value->IsNumber()); |
| 35 ASSERT_FALSE(value->IsObject()); | 36 ASSERT_FALSE(value->IsObject()); |
| 36 ASSERT_FALSE(value->IsArray()); | 37 ASSERT_FALSE(value->IsArray()); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 const std::string source("\ | 211 const std::string source("\ |
| 211 function Foo() {\ | 212 function Foo() {\ |
| 212 this.toString = function() {throw 'test1';};\ | 213 this.toString = function() {throw 'test1';};\ |
| 213 this.valueOf = function() {throw 'test2';};\ | 214 this.valueOf = function() {throw 'test2';};\ |
| 214 };\ | 215 };\ |
| 215 new Foo()"); | 216 new Foo()"); |
| 216 AdblockPlus::JsValuePtr value = jsEngine->Evaluate(source); | 217 AdblockPlus::JsValuePtr value = jsEngine->Evaluate(source); |
| 217 ASSERT_EQ("", value->AsString()); | 218 ASSERT_EQ("", value->AsString()); |
| 218 ASSERT_EQ(0, value->AsInt()); | 219 ASSERT_EQ(0, value->AsInt()); |
| 219 } | 220 } |
| 221 |
| 222 TEST_F(JsValueTest, PersistentWeakHandleDisposalComplex) |
| 223 { |
| 224 // Force GC |
| 225 v8::V8::AdjustAmountOfExternalAllocatedMemory(1000000000); |
| 226 while (!v8::V8::IdleNotification()) {}; |
| 227 _sleep(500); |
| 228 |
| 229 v8::HeapProfiler heapProfiler; |
| 230 int numberOfHandlesBefore = 0; |
| 231 |
| 232 // Create and destroy persistent handle for an object |
| 233 { |
| 234 numberOfHandlesBefore = heapProfiler.GetPersistentHandleCount(); |
| 235 AdblockPlus::JsValuePtr value = jsEngine->NewObject(); |
| 236 } |
| 237 |
| 238 // Force GC |
| 239 v8::V8::AdjustAmountOfExternalAllocatedMemory(1000000000); |
| 240 while (!v8::V8::IdleNotification()) {}; |
| 241 _sleep(500); |
| 242 |
| 243 ASSERT_EQ(numberOfHandlesBefore, heapProfiler.GetPersistentHandleCount()); |
| 244 } |
| 245 |
| 246 TEST_F(JsValueTest, PersistentWeakHandleDisposalPrimitive) |
| 247 { |
| 248 // Force GC |
| 249 v8::V8::AdjustAmountOfExternalAllocatedMemory(1000000000); |
| 250 while (!v8::V8::IdleNotification()) {}; |
| 251 _sleep(500); |
| 252 |
| 253 v8::HeapProfiler heapProfiler; |
| 254 int numberOfHandlesBefore = 0; |
| 255 |
| 256 // Create and destroy persistent handle for a primitive |
| 257 { |
| 258 numberOfHandlesBefore = heapProfiler.GetPersistentHandleCount(); |
| 259 AdblockPlus::JsValuePtr value = jsEngine->NewValue(false); |
| 260 AdblockPlus::JsValuePtr value2 = jsEngine->NewValue(0); |
| 261 } |
| 262 |
| 263 // Force GC |
| 264 v8::V8::AdjustAmountOfExternalAllocatedMemory(1000000000); |
| 265 while (!v8::V8::IdleNotification()) {}; |
| 266 _sleep(500); |
| 267 |
| 268 ASSERT_EQ(numberOfHandlesBefore, heapProfiler.GetPersistentHandleCount()); |
| 269 } |
| OLD | NEW |