| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. | 11 // with the distribution. |
| (...skipping 2848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2860 // Fraction. | 2860 // Fraction. |
| 2861 CompileRun("var obj = 42.3;"); | 2861 CompileRun("var obj = 42.3;"); |
| 2862 obj = env->Global()->Get(v8_str("obj")); | 2862 obj = env->Global()->Get(v8_str("obj")); |
| 2863 CHECK(!obj->IsInt32()); | 2863 CHECK(!obj->IsInt32()); |
| 2864 CHECK(!obj->IsUint32()); | 2864 CHECK(!obj->IsUint32()); |
| 2865 // Large negative fraction. | 2865 // Large negative fraction. |
| 2866 CompileRun("var obj = -5726623061.75;"); | 2866 CompileRun("var obj = -5726623061.75;"); |
| 2867 obj = env->Global()->Get(v8_str("obj")); | 2867 obj = env->Global()->Get(v8_str("obj")); |
| 2868 CHECK(!obj->IsInt32()); | 2868 CHECK(!obj->IsInt32()); |
| 2869 CHECK(!obj->IsUint32()); | 2869 CHECK(!obj->IsUint32()); |
| 2870 // Positive zero |
| 2871 CompileRun("var obj = 0.0;"); |
| 2872 obj = env->Global()->Get(v8_str("obj")); |
| 2873 CHECK(obj->IsInt32()); |
| 2874 CHECK(obj->IsUint32()); |
| 2875 // Positive zero |
| 2876 CompileRun("var obj = -0.0;"); |
| 2877 obj = env->Global()->Get(v8_str("obj")); |
| 2878 CHECK(!obj->IsInt32()); |
| 2879 CHECK(!obj->IsUint32()); |
| 2870 } | 2880 } |
| 2871 | 2881 |
| 2872 | 2882 |
| 2873 THREADED_TEST(ConversionException) { | 2883 THREADED_TEST(ConversionException) { |
| 2874 v8::HandleScope scope; | 2884 v8::HandleScope scope; |
| 2875 LocalContext env; | 2885 LocalContext env; |
| 2876 CompileRun( | 2886 CompileRun( |
| 2877 "function TestClass() { };" | 2887 "function TestClass() { };" |
| 2878 "TestClass.prototype.toString = function () { throw 'uncle?'; };" | 2888 "TestClass.prototype.toString = function () { throw 'uncle?'; };" |
| 2879 "var obj = new TestClass();"); | 2889 "var obj = new TestClass();"); |
| (...skipping 5054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7934 | 7944 |
| 7935 THREADED_TEST(CrossEval) { | 7945 THREADED_TEST(CrossEval) { |
| 7936 v8::HandleScope scope; | 7946 v8::HandleScope scope; |
| 7937 LocalContext other; | 7947 LocalContext other; |
| 7938 LocalContext current; | 7948 LocalContext current; |
| 7939 | 7949 |
| 7940 Local<String> token = v8_str("<security token>"); | 7950 Local<String> token = v8_str("<security token>"); |
| 7941 other->SetSecurityToken(token); | 7951 other->SetSecurityToken(token); |
| 7942 current->SetSecurityToken(token); | 7952 current->SetSecurityToken(token); |
| 7943 | 7953 |
| 7944 // Setup reference from current to other. | 7954 // Set up reference from current to other. |
| 7945 current->Global()->Set(v8_str("other"), other->Global()); | 7955 current->Global()->Set(v8_str("other"), other->Global()); |
| 7946 | 7956 |
| 7947 // Check that new variables are introduced in other context. | 7957 // Check that new variables are introduced in other context. |
| 7948 Local<Script> script = | 7958 Local<Script> script = |
| 7949 Script::Compile(v8_str("other.eval('var foo = 1234')")); | 7959 Script::Compile(v8_str("other.eval('var foo = 1234')")); |
| 7950 script->Run(); | 7960 script->Run(); |
| 7951 Local<Value> foo = other->Global()->Get(v8_str("foo")); | 7961 Local<Value> foo = other->Global()->Get(v8_str("foo")); |
| 7952 CHECK_EQ(1234, foo->Int32Value()); | 7962 CHECK_EQ(1234, foo->Int32Value()); |
| 7953 CHECK(!current->Global()->Has(v8_str("foo"))); | 7963 CHECK(!current->Global()->Has(v8_str("foo"))); |
| 7954 | 7964 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8014 | 8024 |
| 8015 // Test that calling eval in a context which has been detached from | 8025 // Test that calling eval in a context which has been detached from |
| 8016 // its global throws an exception. This behavior is consistent with | 8026 // its global throws an exception. This behavior is consistent with |
| 8017 // other JavaScript implementations. | 8027 // other JavaScript implementations. |
| 8018 THREADED_TEST(EvalInDetachedGlobal) { | 8028 THREADED_TEST(EvalInDetachedGlobal) { |
| 8019 v8::HandleScope scope; | 8029 v8::HandleScope scope; |
| 8020 | 8030 |
| 8021 v8::Persistent<Context> context0 = Context::New(); | 8031 v8::Persistent<Context> context0 = Context::New(); |
| 8022 v8::Persistent<Context> context1 = Context::New(); | 8032 v8::Persistent<Context> context1 = Context::New(); |
| 8023 | 8033 |
| 8024 // Setup function in context0 that uses eval from context0. | 8034 // Set up function in context0 that uses eval from context0. |
| 8025 context0->Enter(); | 8035 context0->Enter(); |
| 8026 v8::Handle<v8::Value> fun = | 8036 v8::Handle<v8::Value> fun = |
| 8027 CompileRun("var x = 42;" | 8037 CompileRun("var x = 42;" |
| 8028 "(function() {" | 8038 "(function() {" |
| 8029 " var e = eval;" | 8039 " var e = eval;" |
| 8030 " return function(s) { return e(s); }" | 8040 " return function(s) { return e(s); }" |
| 8031 "})()"); | 8041 "})()"); |
| 8032 context0->Exit(); | 8042 context0->Exit(); |
| 8033 | 8043 |
| 8034 // Put the function into context1 and call it before and after | 8044 // Put the function into context1 and call it before and after |
| (...skipping 17 matching lines...) Expand all Loading... |
| 8052 | 8062 |
| 8053 THREADED_TEST(CrossLazyLoad) { | 8063 THREADED_TEST(CrossLazyLoad) { |
| 8054 v8::HandleScope scope; | 8064 v8::HandleScope scope; |
| 8055 LocalContext other; | 8065 LocalContext other; |
| 8056 LocalContext current; | 8066 LocalContext current; |
| 8057 | 8067 |
| 8058 Local<String> token = v8_str("<security token>"); | 8068 Local<String> token = v8_str("<security token>"); |
| 8059 other->SetSecurityToken(token); | 8069 other->SetSecurityToken(token); |
| 8060 current->SetSecurityToken(token); | 8070 current->SetSecurityToken(token); |
| 8061 | 8071 |
| 8062 // Setup reference from current to other. | 8072 // Set up reference from current to other. |
| 8063 current->Global()->Set(v8_str("other"), other->Global()); | 8073 current->Global()->Set(v8_str("other"), other->Global()); |
| 8064 | 8074 |
| 8065 // Trigger lazy loading in other context. | 8075 // Trigger lazy loading in other context. |
| 8066 Local<Script> script = | 8076 Local<Script> script = |
| 8067 Script::Compile(v8_str("other.eval('new Date(42)')")); | 8077 Script::Compile(v8_str("other.eval('new Date(42)')")); |
| 8068 Local<Value> value = script->Run(); | 8078 Local<Value> value = script->Run(); |
| 8069 CHECK_EQ(42.0, value->NumberValue()); | 8079 CHECK_EQ(42.0, value->NumberValue()); |
| 8070 } | 8080 } |
| 8071 | 8081 |
| 8072 | 8082 |
| (...skipping 2090 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10163 } else { | 10173 } else { |
| 10164 // Otherwise select a new test and start that. | 10174 // Otherwise select a new test and start that. |
| 10165 NextThread(); | 10175 NextThread(); |
| 10166 } | 10176 } |
| 10167 } | 10177 } |
| 10168 | 10178 |
| 10169 | 10179 |
| 10170 static unsigned linear_congruential_generator; | 10180 static unsigned linear_congruential_generator; |
| 10171 | 10181 |
| 10172 | 10182 |
| 10173 void ApiTestFuzzer::Setup(PartOfTest part) { | 10183 void ApiTestFuzzer::SetUp(PartOfTest part) { |
| 10174 linear_congruential_generator = i::FLAG_testing_prng_seed; | 10184 linear_congruential_generator = i::FLAG_testing_prng_seed; |
| 10175 fuzzing_ = true; | 10185 fuzzing_ = true; |
| 10176 int count = RegisterThreadedTest::count(); | 10186 int count = RegisterThreadedTest::count(); |
| 10177 int start = count * part / (LAST_PART + 1); | 10187 int start = count * part / (LAST_PART + 1); |
| 10178 int end = (count * (part + 1) / (LAST_PART + 1)) - 1; | 10188 int end = (count * (part + 1) / (LAST_PART + 1)) - 1; |
| 10179 active_tests_ = tests_being_run_ = end - start + 1; | 10189 active_tests_ = tests_being_run_ = end - start + 1; |
| 10180 for (int i = 0; i < tests_being_run_; i++) { | 10190 for (int i = 0; i < tests_being_run_; i++) { |
| 10181 RegisterThreadedTest::nth(i)->fuzzer_ = new ApiTestFuzzer(i + start); | 10191 RegisterThreadedTest::nth(i)->fuzzer_ = new ApiTestFuzzer(i + start); |
| 10182 } | 10192 } |
| 10183 for (int i = 0; i < active_tests_; i++) { | 10193 for (int i = 0; i < active_tests_; i++) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10227 fuzzing_ = false; | 10237 fuzzing_ = false; |
| 10228 for (int i = 0; i < RegisterThreadedTest::count(); i++) { | 10238 for (int i = 0; i < RegisterThreadedTest::count(); i++) { |
| 10229 ApiTestFuzzer *fuzzer = RegisterThreadedTest::nth(i)->fuzzer_; | 10239 ApiTestFuzzer *fuzzer = RegisterThreadedTest::nth(i)->fuzzer_; |
| 10230 if (fuzzer != NULL) fuzzer->Join(); | 10240 if (fuzzer != NULL) fuzzer->Join(); |
| 10231 } | 10241 } |
| 10232 } | 10242 } |
| 10233 | 10243 |
| 10234 | 10244 |
| 10235 // Lets not be needlessly self-referential. | 10245 // Lets not be needlessly self-referential. |
| 10236 TEST(Threading) { | 10246 TEST(Threading) { |
| 10237 ApiTestFuzzer::Setup(ApiTestFuzzer::FIRST_PART); | 10247 ApiTestFuzzer::SetUp(ApiTestFuzzer::FIRST_PART); |
| 10238 ApiTestFuzzer::RunAllTests(); | 10248 ApiTestFuzzer::RunAllTests(); |
| 10239 ApiTestFuzzer::TearDown(); | 10249 ApiTestFuzzer::TearDown(); |
| 10240 } | 10250 } |
| 10241 | 10251 |
| 10242 TEST(Threading2) { | 10252 TEST(Threading2) { |
| 10243 ApiTestFuzzer::Setup(ApiTestFuzzer::SECOND_PART); | 10253 ApiTestFuzzer::SetUp(ApiTestFuzzer::SECOND_PART); |
| 10244 ApiTestFuzzer::RunAllTests(); | 10254 ApiTestFuzzer::RunAllTests(); |
| 10245 ApiTestFuzzer::TearDown(); | 10255 ApiTestFuzzer::TearDown(); |
| 10246 } | 10256 } |
| 10247 | 10257 |
| 10248 TEST(Threading3) { | 10258 TEST(Threading3) { |
| 10249 ApiTestFuzzer::Setup(ApiTestFuzzer::THIRD_PART); | 10259 ApiTestFuzzer::SetUp(ApiTestFuzzer::THIRD_PART); |
| 10250 ApiTestFuzzer::RunAllTests(); | 10260 ApiTestFuzzer::RunAllTests(); |
| 10251 ApiTestFuzzer::TearDown(); | 10261 ApiTestFuzzer::TearDown(); |
| 10252 } | 10262 } |
| 10253 | 10263 |
| 10254 TEST(Threading4) { | 10264 TEST(Threading4) { |
| 10255 ApiTestFuzzer::Setup(ApiTestFuzzer::FOURTH_PART); | 10265 ApiTestFuzzer::SetUp(ApiTestFuzzer::FOURTH_PART); |
| 10256 ApiTestFuzzer::RunAllTests(); | 10266 ApiTestFuzzer::RunAllTests(); |
| 10257 ApiTestFuzzer::TearDown(); | 10267 ApiTestFuzzer::TearDown(); |
| 10258 } | 10268 } |
| 10259 | 10269 |
| 10260 void ApiTestFuzzer::CallTest() { | 10270 void ApiTestFuzzer::CallTest() { |
| 10261 if (kLogThreading) | 10271 if (kLogThreading) |
| 10262 printf("Start test %d\n", test_number_); | 10272 printf("Start test %d\n", test_number_); |
| 10263 CallTestNumber(test_number_); | 10273 CallTestNumber(test_number_); |
| 10264 if (kLogThreading) | 10274 if (kLogThreading) |
| 10265 printf("End test %d\n", test_number_); | 10275 printf("End test %d\n", test_number_); |
| (...skipping 1838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12104 calling_context2->SetSecurityToken(token); | 12114 calling_context2->SetSecurityToken(token); |
| 12105 | 12115 |
| 12106 // Create an object with a C++ callback in context0. | 12116 // Create an object with a C++ callback in context0. |
| 12107 calling_context0->Enter(); | 12117 calling_context0->Enter(); |
| 12108 Local<v8::FunctionTemplate> callback_templ = | 12118 Local<v8::FunctionTemplate> callback_templ = |
| 12109 v8::FunctionTemplate::New(GetCallingContextCallback); | 12119 v8::FunctionTemplate::New(GetCallingContextCallback); |
| 12110 calling_context0->Global()->Set(v8_str("callback"), | 12120 calling_context0->Global()->Set(v8_str("callback"), |
| 12111 callback_templ->GetFunction()); | 12121 callback_templ->GetFunction()); |
| 12112 calling_context0->Exit(); | 12122 calling_context0->Exit(); |
| 12113 | 12123 |
| 12114 // Expose context0 in context1 and setup a function that calls the | 12124 // Expose context0 in context1 and set up a function that calls the |
| 12115 // callback function. | 12125 // callback function. |
| 12116 calling_context1->Enter(); | 12126 calling_context1->Enter(); |
| 12117 calling_context1->Global()->Set(v8_str("context0"), | 12127 calling_context1->Global()->Set(v8_str("context0"), |
| 12118 calling_context0->Global()); | 12128 calling_context0->Global()); |
| 12119 CompileRun("function f() { context0.callback() }"); | 12129 CompileRun("function f() { context0.callback() }"); |
| 12120 calling_context1->Exit(); | 12130 calling_context1->Exit(); |
| 12121 | 12131 |
| 12122 // Expose context1 in context2 and call the callback function in | 12132 // Expose context1 in context2 and call the callback function in |
| 12123 // context0 indirectly through f in context1. | 12133 // context0 indirectly through f in context1. |
| 12124 calling_context2->Enter(); | 12134 calling_context2->Enter(); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12262 | 12272 |
| 12263 result = CompileRun("var sum = 0;" | 12273 result = CompileRun("var sum = 0;" |
| 12264 "for (var i = 0; i < 8; i++) {" | 12274 "for (var i = 0; i < 8; i++) {" |
| 12265 " sum += pixels[i];" | 12275 " sum += pixels[i];" |
| 12266 "}" | 12276 "}" |
| 12267 "sum;"); | 12277 "sum;"); |
| 12268 CHECK_EQ(28, result->Int32Value()); | 12278 CHECK_EQ(28, result->Int32Value()); |
| 12269 | 12279 |
| 12270 i::Handle<i::Smi> value(i::Smi::FromInt(2)); | 12280 i::Handle<i::Smi> value(i::Smi::FromInt(2)); |
| 12271 i::Handle<i::Object> no_failure; | 12281 i::Handle<i::Object> no_failure; |
| 12272 no_failure = i::SetElement(jsobj, 1, value, i::kNonStrictMode); | 12282 no_failure = i::JSObject::SetElement(jsobj, 1, value, i::kNonStrictMode); |
| 12273 ASSERT(!no_failure.is_null()); | 12283 ASSERT(!no_failure.is_null()); |
| 12274 i::USE(no_failure); | 12284 i::USE(no_failure); |
| 12275 CHECK_EQ(2, i::Smi::cast(jsobj->GetElement(1)->ToObjectChecked())->value()); | 12285 CHECK_EQ(2, i::Smi::cast(jsobj->GetElement(1)->ToObjectChecked())->value()); |
| 12276 *value.location() = i::Smi::FromInt(256); | 12286 *value.location() = i::Smi::FromInt(256); |
| 12277 no_failure = i::SetElement(jsobj, 1, value, i::kNonStrictMode); | 12287 no_failure = i::JSObject::SetElement(jsobj, 1, value, i::kNonStrictMode); |
| 12278 ASSERT(!no_failure.is_null()); | 12288 ASSERT(!no_failure.is_null()); |
| 12279 i::USE(no_failure); | 12289 i::USE(no_failure); |
| 12280 CHECK_EQ(255, | 12290 CHECK_EQ(255, |
| 12281 i::Smi::cast(jsobj->GetElement(1)->ToObjectChecked())->value()); | 12291 i::Smi::cast(jsobj->GetElement(1)->ToObjectChecked())->value()); |
| 12282 *value.location() = i::Smi::FromInt(-1); | 12292 *value.location() = i::Smi::FromInt(-1); |
| 12283 no_failure = i::SetElement(jsobj, 1, value, i::kNonStrictMode); | 12293 no_failure = i::JSObject::SetElement(jsobj, 1, value, i::kNonStrictMode); |
| 12284 ASSERT(!no_failure.is_null()); | 12294 ASSERT(!no_failure.is_null()); |
| 12285 i::USE(no_failure); | 12295 i::USE(no_failure); |
| 12286 CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(1)->ToObjectChecked())->value()); | 12296 CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(1)->ToObjectChecked())->value()); |
| 12287 | 12297 |
| 12288 result = CompileRun("for (var i = 0; i < 8; i++) {" | 12298 result = CompileRun("for (var i = 0; i < 8; i++) {" |
| 12289 " pixels[i] = (i * 65) - 109;" | 12299 " pixels[i] = (i * 65) - 109;" |
| 12290 "}" | 12300 "}" |
| 12291 "pixels[1] + pixels[6];"); | 12301 "pixels[1] + pixels[6];"); |
| 12292 CHECK_EQ(255, result->Int32Value()); | 12302 CHECK_EQ(255, result->Int32Value()); |
| 12293 CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(0)->ToObjectChecked())->value()); | 12303 CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(0)->ToObjectChecked())->value()); |
| (...skipping 1248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13542 rv = v8::V8::IdleNotification(); | 13552 rv = v8::V8::IdleNotification(); |
| 13543 if (rv) | 13553 if (rv) |
| 13544 break; | 13554 break; |
| 13545 } | 13555 } |
| 13546 CHECK(rv == true); | 13556 CHECK(rv == true); |
| 13547 } | 13557 } |
| 13548 | 13558 |
| 13549 // Test that idle notification can be handled and eventually returns true. | 13559 // Test that idle notification can be handled and eventually returns true. |
| 13550 // This just checks the contract of the IdleNotification() function, | 13560 // This just checks the contract of the IdleNotification() function, |
| 13551 // and does not verify that it does reasonable work. | 13561 // and does not verify that it does reasonable work. |
| 13552 THREADED_TEST(IdleNotificationWithHint) { | 13562 TEST(IdleNotificationWithHint) { |
| 13553 v8::HandleScope scope; | 13563 v8::HandleScope scope; |
| 13554 LocalContext env; | 13564 LocalContext env; |
| 13555 CompileRun("function binom(n, m) {" | 13565 { |
| 13556 " var C = [[1]];" | 13566 i::AlwaysAllocateScope always_allocate; |
| 13557 " for (var i = 1; i <= n; ++i) {" | 13567 CompileRun("function binom(n, m) {" |
| 13558 " C[i] = [1];" | 13568 " var C = [[1]];" |
| 13559 " for (var j = 1; j < i; ++j) {" | 13569 " for (var i = 1; i <= n; ++i) {" |
| 13560 " C[i][j] = C[i-1][j-1] + C[i-1][j];" | 13570 " C[i] = [1];" |
| 13561 " }" | 13571 " for (var j = 1; j < i; ++j) {" |
| 13562 " C[i][i] = 1;" | 13572 " C[i][j] = C[i-1][j-1] + C[i-1][j];" |
| 13563 " }" | 13573 " }" |
| 13564 " return C[n][m];" | 13574 " C[i][i] = 1;" |
| 13565 "};" | 13575 " }" |
| 13566 "binom(1000, 500)"); | 13576 " return C[n][m];" |
| 13577 "};" |
| 13578 "binom(1000, 500)"); |
| 13579 } |
| 13567 bool rv = false; | 13580 bool rv = false; |
| 13568 intptr_t old_size = HEAP->SizeOfObjects(); | 13581 intptr_t old_size = HEAP->SizeOfObjects(); |
| 13569 bool no_idle_work = v8::V8::IdleNotification(10); | 13582 bool no_idle_work = v8::V8::IdleNotification(10); |
| 13570 for (int i = 0; i < 200; i++) { | 13583 for (int i = 0; i < 200; i++) { |
| 13571 rv = v8::V8::IdleNotification(10); | 13584 rv = v8::V8::IdleNotification(10); |
| 13572 if (rv) | 13585 if (rv) |
| 13573 break; | 13586 break; |
| 13574 } | 13587 } |
| 13575 CHECK(rv == true); | 13588 CHECK(rv == true); |
| 13576 intptr_t new_size = HEAP->SizeOfObjects(); | 13589 intptr_t new_size = HEAP->SizeOfObjects(); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13658 LocalContext c1; | 13671 LocalContext c1; |
| 13659 v8::HeapStatistics heap_statistics; | 13672 v8::HeapStatistics heap_statistics; |
| 13660 CHECK_EQ(static_cast<int>(heap_statistics.total_heap_size()), 0); | 13673 CHECK_EQ(static_cast<int>(heap_statistics.total_heap_size()), 0); |
| 13661 CHECK_EQ(static_cast<int>(heap_statistics.used_heap_size()), 0); | 13674 CHECK_EQ(static_cast<int>(heap_statistics.used_heap_size()), 0); |
| 13662 v8::V8::GetHeapStatistics(&heap_statistics); | 13675 v8::V8::GetHeapStatistics(&heap_statistics); |
| 13663 CHECK_NE(static_cast<int>(heap_statistics.total_heap_size()), 0); | 13676 CHECK_NE(static_cast<int>(heap_statistics.total_heap_size()), 0); |
| 13664 CHECK_NE(static_cast<int>(heap_statistics.used_heap_size()), 0); | 13677 CHECK_NE(static_cast<int>(heap_statistics.used_heap_size()), 0); |
| 13665 } | 13678 } |
| 13666 | 13679 |
| 13667 | 13680 |
| 13681 class VisitorImpl : public v8::ExternalResourceVisitor { |
| 13682 public: |
| 13683 VisitorImpl(TestResource* r1, TestResource* r2) |
| 13684 : resource1_(r1), |
| 13685 resource2_(r2), |
| 13686 found_resource1_(false), |
| 13687 found_resource2_(false) {} |
| 13688 virtual ~VisitorImpl() {} |
| 13689 virtual void VisitExternalString(v8::Handle<v8::String> string) { |
| 13690 if (!string->IsExternal()) { |
| 13691 CHECK(string->IsExternalAscii()); |
| 13692 return; |
| 13693 } |
| 13694 v8::String::ExternalStringResource* resource = |
| 13695 string->GetExternalStringResource(); |
| 13696 CHECK(resource); |
| 13697 if (resource1_ == resource) { |
| 13698 CHECK(!found_resource1_); |
| 13699 found_resource1_ = true; |
| 13700 } |
| 13701 if (resource2_ == resource) { |
| 13702 CHECK(!found_resource2_); |
| 13703 found_resource2_ = true; |
| 13704 } |
| 13705 } |
| 13706 void CheckVisitedResources() { |
| 13707 CHECK(found_resource1_); |
| 13708 CHECK(found_resource2_); |
| 13709 } |
| 13710 |
| 13711 private: |
| 13712 v8::String::ExternalStringResource* resource1_; |
| 13713 v8::String::ExternalStringResource* resource2_; |
| 13714 bool found_resource1_; |
| 13715 bool found_resource2_; |
| 13716 }; |
| 13717 |
| 13718 TEST(VisitExternalStrings) { |
| 13719 v8::HandleScope scope; |
| 13720 LocalContext env; |
| 13721 const char* string = "Some string"; |
| 13722 uint16_t* two_byte_string = AsciiToTwoByteString(string); |
| 13723 TestResource* resource1 = new TestResource(two_byte_string); |
| 13724 v8::Local<v8::String> string1 = v8::String::NewExternal(resource1); |
| 13725 TestResource* resource2 = new TestResource(two_byte_string); |
| 13726 v8::Local<v8::String> string2 = v8::String::NewExternal(resource2); |
| 13727 |
| 13728 VisitorImpl visitor(resource1, resource2); |
| 13729 v8::V8::VisitExternalResources(&visitor); |
| 13730 visitor.CheckVisitedResources(); |
| 13731 } |
| 13732 |
| 13733 |
| 13668 static double DoubleFromBits(uint64_t value) { | 13734 static double DoubleFromBits(uint64_t value) { |
| 13669 double target; | 13735 double target; |
| 13670 memcpy(&target, &value, sizeof(target)); | 13736 memcpy(&target, &value, sizeof(target)); |
| 13671 return target; | 13737 return target; |
| 13672 } | 13738 } |
| 13673 | 13739 |
| 13674 | 13740 |
| 13675 static uint64_t DoubleToBits(double value) { | 13741 static uint64_t DoubleToBits(double value) { |
| 13676 uint64_t target; | 13742 uint64_t target; |
| 13677 memcpy(&target, &value, sizeof(target)); | 13743 memcpy(&target, &value, sizeof(target)); |
| (...skipping 2136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15814 CompileRun("throw 'exception';"); | 15880 CompileRun("throw 'exception';"); |
| 15815 } | 15881 } |
| 15816 | 15882 |
| 15817 | 15883 |
| 15818 TEST(CallCompletedCallbackTwoExceptions) { | 15884 TEST(CallCompletedCallbackTwoExceptions) { |
| 15819 v8::HandleScope scope; | 15885 v8::HandleScope scope; |
| 15820 LocalContext env; | 15886 LocalContext env; |
| 15821 v8::V8::AddCallCompletedCallback(CallCompletedCallbackException); | 15887 v8::V8::AddCallCompletedCallback(CallCompletedCallbackException); |
| 15822 CompileRun("throw 'first exception';"); | 15888 CompileRun("throw 'first exception';"); |
| 15823 } | 15889 } |
| OLD | NEW |