OLD | NEW |
1 // Copyright 2012 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 |
(...skipping 4643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4654 | 4654 |
4655 void CThrowCountDown(const v8::FunctionCallbackInfo<v8::Value>& args) { | 4655 void CThrowCountDown(const v8::FunctionCallbackInfo<v8::Value>& args) { |
4656 ApiTestFuzzer::Fuzz(); | 4656 ApiTestFuzzer::Fuzz(); |
4657 CHECK_EQ(4, args.Length()); | 4657 CHECK_EQ(4, args.Length()); |
4658 int count = args[0]->Int32Value(); | 4658 int count = args[0]->Int32Value(); |
4659 int cInterval = args[2]->Int32Value(); | 4659 int cInterval = args[2]->Int32Value(); |
4660 if (count == 0) { | 4660 if (count == 0) { |
4661 v8::ThrowException(v8_str("FromC")); | 4661 v8::ThrowException(v8_str("FromC")); |
4662 return; | 4662 return; |
4663 } else { | 4663 } else { |
4664 Local<v8::Object> global = Context::GetCurrent()->Global(); | 4664 Local<v8::Object> global = |
| 4665 args.GetIsolate()->GetCurrentContext()->Global(); |
4665 Local<Value> fun = global->Get(v8_str("JSThrowCountDown")); | 4666 Local<Value> fun = global->Get(v8_str("JSThrowCountDown")); |
4666 v8::Handle<Value> argv[] = { v8_num(count - 1), | 4667 v8::Handle<Value> argv[] = { v8_num(count - 1), |
4667 args[1], | 4668 args[1], |
4668 args[2], | 4669 args[2], |
4669 args[3] }; | 4670 args[3] }; |
4670 if (count % cInterval == 0) { | 4671 if (count % cInterval == 0) { |
4671 v8::TryCatch try_catch; | 4672 v8::TryCatch try_catch; |
4672 Local<Value> result = fun.As<Function>()->Call(global, 4, argv); | 4673 Local<Value> result = fun.As<Function>()->Call(global, 4, argv); |
4673 int expected = args[3]->Int32Value(); | 4674 int expected = args[3]->Int32Value(); |
4674 if (try_catch.HasCaught()) { | 4675 if (try_catch.HasCaught()) { |
(...skipping 2396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7071 | 7072 |
7072 | 7073 |
7073 int p_getter_count; | 7074 int p_getter_count; |
7074 int p_getter_count2; | 7075 int p_getter_count2; |
7075 | 7076 |
7076 | 7077 |
7077 static void PGetter(Local<String> name, | 7078 static void PGetter(Local<String> name, |
7078 const v8::PropertyCallbackInfo<v8::Value>& info) { | 7079 const v8::PropertyCallbackInfo<v8::Value>& info) { |
7079 ApiTestFuzzer::Fuzz(); | 7080 ApiTestFuzzer::Fuzz(); |
7080 p_getter_count++; | 7081 p_getter_count++; |
7081 v8::Handle<v8::Object> global = Context::GetCurrent()->Global(); | 7082 v8::Handle<v8::Object> global = |
| 7083 info.GetIsolate()->GetCurrentContext()->Global(); |
7082 CHECK_EQ(info.Holder(), global->Get(v8_str("o1"))); | 7084 CHECK_EQ(info.Holder(), global->Get(v8_str("o1"))); |
7083 if (name->Equals(v8_str("p1"))) { | 7085 if (name->Equals(v8_str("p1"))) { |
7084 CHECK_EQ(info.This(), global->Get(v8_str("o1"))); | 7086 CHECK_EQ(info.This(), global->Get(v8_str("o1"))); |
7085 } else if (name->Equals(v8_str("p2"))) { | 7087 } else if (name->Equals(v8_str("p2"))) { |
7086 CHECK_EQ(info.This(), global->Get(v8_str("o2"))); | 7088 CHECK_EQ(info.This(), global->Get(v8_str("o2"))); |
7087 } else if (name->Equals(v8_str("p3"))) { | 7089 } else if (name->Equals(v8_str("p3"))) { |
7088 CHECK_EQ(info.This(), global->Get(v8_str("o3"))); | 7090 CHECK_EQ(info.This(), global->Get(v8_str("o3"))); |
7089 } else if (name->Equals(v8_str("p4"))) { | 7091 } else if (name->Equals(v8_str("p4"))) { |
7090 CHECK_EQ(info.This(), global->Get(v8_str("o4"))); | 7092 CHECK_EQ(info.This(), global->Get(v8_str("o4"))); |
7091 } | 7093 } |
(...skipping 13 matching lines...) Expand all Loading... |
7105 "for (var i = 0; i < 10; i++) o3.p3;" | 7107 "for (var i = 0; i < 10; i++) o3.p3;" |
7106 "for (var i = 0; i < 10; i++) o2.p2;" | 7108 "for (var i = 0; i < 10; i++) o2.p2;" |
7107 "for (var i = 0; i < 10; i++) o1.p1;"); | 7109 "for (var i = 0; i < 10; i++) o1.p1;"); |
7108 } | 7110 } |
7109 | 7111 |
7110 | 7112 |
7111 static void PGetter2(Local<String> name, | 7113 static void PGetter2(Local<String> name, |
7112 const v8::PropertyCallbackInfo<v8::Value>& info) { | 7114 const v8::PropertyCallbackInfo<v8::Value>& info) { |
7113 ApiTestFuzzer::Fuzz(); | 7115 ApiTestFuzzer::Fuzz(); |
7114 p_getter_count2++; | 7116 p_getter_count2++; |
7115 v8::Handle<v8::Object> global = Context::GetCurrent()->Global(); | 7117 v8::Handle<v8::Object> global = |
| 7118 info.GetIsolate()->GetCurrentContext()->Global(); |
7116 CHECK_EQ(info.Holder(), global->Get(v8_str("o1"))); | 7119 CHECK_EQ(info.Holder(), global->Get(v8_str("o1"))); |
7117 if (name->Equals(v8_str("p1"))) { | 7120 if (name->Equals(v8_str("p1"))) { |
7118 CHECK_EQ(info.This(), global->Get(v8_str("o1"))); | 7121 CHECK_EQ(info.This(), global->Get(v8_str("o1"))); |
7119 } else if (name->Equals(v8_str("p2"))) { | 7122 } else if (name->Equals(v8_str("p2"))) { |
7120 CHECK_EQ(info.This(), global->Get(v8_str("o2"))); | 7123 CHECK_EQ(info.This(), global->Get(v8_str("o2"))); |
7121 } else if (name->Equals(v8_str("p3"))) { | 7124 } else if (name->Equals(v8_str("p3"))) { |
7122 CHECK_EQ(info.This(), global->Get(v8_str("o3"))); | 7125 CHECK_EQ(info.This(), global->Get(v8_str("o3"))); |
7123 } else if (name->Equals(v8_str("p4"))) { | 7126 } else if (name->Equals(v8_str("p4"))) { |
7124 CHECK_EQ(info.This(), global->Get(v8_str("o4"))); | 7127 CHECK_EQ(info.This(), global->Get(v8_str("o4"))); |
7125 } | 7128 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7211 CompileRun( | 7214 CompileRun( |
7212 "var left = '';" | 7215 "var left = '';" |
7213 "for (var i = 0; i < 0xd800; i += 4) {" | 7216 "for (var i = 0; i < 0xd800; i += 4) {" |
7214 " left = left + String.fromCharCode(i);" | 7217 " left = left + String.fromCharCode(i);" |
7215 "}"); | 7218 "}"); |
7216 CompileRun( | 7219 CompileRun( |
7217 "var right = '';" | 7220 "var right = '';" |
7218 "for (var i = 0; i < 0xd800; i += 4) {" | 7221 "for (var i = 0; i < 0xd800; i += 4) {" |
7219 " right = String.fromCharCode(i) + right;" | 7222 " right = String.fromCharCode(i) + right;" |
7220 "}"); | 7223 "}"); |
7221 v8::Handle<v8::Object> global = Context::GetCurrent()->Global(); | 7224 v8::Handle<v8::Object> global = context->Global(); |
7222 Handle<String> left_tree = global->Get(v8_str("left")).As<String>(); | 7225 Handle<String> left_tree = global->Get(v8_str("left")).As<String>(); |
7223 Handle<String> right_tree = global->Get(v8_str("right")).As<String>(); | 7226 Handle<String> right_tree = global->Get(v8_str("right")).As<String>(); |
7224 | 7227 |
7225 CHECK_EQ(5, str2->Length()); | 7228 CHECK_EQ(5, str2->Length()); |
7226 CHECK_EQ(0xd800 / kStride, left_tree->Length()); | 7229 CHECK_EQ(0xd800 / kStride, left_tree->Length()); |
7227 CHECK_EQ(0xd800 / kStride, right_tree->Length()); | 7230 CHECK_EQ(0xd800 / kStride, right_tree->Length()); |
7228 | 7231 |
7229 char buf[100]; | 7232 char buf[100]; |
7230 char utf8buf[0xd800 * 3]; | 7233 char utf8buf[0xd800 * 3]; |
7231 uint16_t wbuf[100]; | 7234 uint16_t wbuf[100]; |
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7798 return g_security_callback_result; | 7801 return g_security_callback_result; |
7799 } | 7802 } |
7800 | 7803 |
7801 | 7804 |
7802 static int trouble_nesting = 0; | 7805 static int trouble_nesting = 0; |
7803 static void TroubleCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { | 7806 static void TroubleCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { |
7804 ApiTestFuzzer::Fuzz(); | 7807 ApiTestFuzzer::Fuzz(); |
7805 trouble_nesting++; | 7808 trouble_nesting++; |
7806 | 7809 |
7807 // Call a JS function that throws an uncaught exception. | 7810 // Call a JS function that throws an uncaught exception. |
7808 Local<v8::Object> arg_this = Context::GetCurrent()->Global(); | 7811 Local<v8::Object> arg_this = |
| 7812 args.GetIsolate()->GetCurrentContext()->Global(); |
7809 Local<Value> trouble_callee = (trouble_nesting == 3) ? | 7813 Local<Value> trouble_callee = (trouble_nesting == 3) ? |
7810 arg_this->Get(v8_str("trouble_callee")) : | 7814 arg_this->Get(v8_str("trouble_callee")) : |
7811 arg_this->Get(v8_str("trouble_caller")); | 7815 arg_this->Get(v8_str("trouble_caller")); |
7812 CHECK(trouble_callee->IsFunction()); | 7816 CHECK(trouble_callee->IsFunction()); |
7813 args.GetReturnValue().Set( | 7817 args.GetReturnValue().Set( |
7814 Function::Cast(*trouble_callee)->Call(arg_this, 0, NULL)); | 7818 Function::Cast(*trouble_callee)->Call(arg_this, 0, NULL)); |
7815 } | 7819 } |
7816 | 7820 |
7817 | 7821 |
7818 static int report_count = 0; | 7822 static int report_count = 0; |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8320 CHECK(result->IsInt32()); | 8324 CHECK(result->IsInt32()); |
8321 CHECK_EQ(42, result->Int32Value()); | 8325 CHECK_EQ(42, result->Int32Value()); |
8322 } | 8326 } |
8323 | 8327 |
8324 | 8328 |
8325 static bool allowed_access_type[v8::ACCESS_KEYS + 1] = { false }; | 8329 static bool allowed_access_type[v8::ACCESS_KEYS + 1] = { false }; |
8326 static bool NamedAccessBlocker(Local<v8::Object> global, | 8330 static bool NamedAccessBlocker(Local<v8::Object> global, |
8327 Local<Value> name, | 8331 Local<Value> name, |
8328 v8::AccessType type, | 8332 v8::AccessType type, |
8329 Local<Value> data) { | 8333 Local<Value> data) { |
8330 return Context::GetCurrent()->Global()->Equals(global) || | 8334 return CcTest::isolate()->GetCurrentContext()->Global()->Equals(global) || |
8331 allowed_access_type[type]; | 8335 allowed_access_type[type]; |
8332 } | 8336 } |
8333 | 8337 |
8334 | 8338 |
8335 static bool IndexedAccessBlocker(Local<v8::Object> global, | 8339 static bool IndexedAccessBlocker(Local<v8::Object> global, |
8336 uint32_t key, | 8340 uint32_t key, |
8337 v8::AccessType type, | 8341 v8::AccessType type, |
8338 Local<Value> data) { | 8342 Local<Value> data) { |
8339 return Context::GetCurrent()->Global()->Equals(global) || | 8343 return CcTest::isolate()->GetCurrentContext()->Global()->Equals(global) || |
8340 allowed_access_type[type]; | 8344 allowed_access_type[type]; |
8341 } | 8345 } |
8342 | 8346 |
8343 | 8347 |
8344 static int g_echo_value_1 = -1; | 8348 static int g_echo_value_1 = -1; |
8345 static int g_echo_value_2 = -1; | 8349 static int g_echo_value_2 = -1; |
8346 | 8350 |
8347 | 8351 |
8348 static void EchoGetter( | 8352 static void EchoGetter( |
8349 Local<String> name, | 8353 Local<String> name, |
(...skipping 5127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13477 CHECK(!env.IsEmpty()); | 13481 CHECK(!env.IsEmpty()); |
13478 const intptr_t kSize = 1024*1024; | 13482 const intptr_t kSize = 1024*1024; |
13479 int64_t baseline = cast(isolate->AdjustAmountOfExternalAllocatedMemory(0)); | 13483 int64_t baseline = cast(isolate->AdjustAmountOfExternalAllocatedMemory(0)); |
13480 CHECK_EQ(baseline + cast(kSize), | 13484 CHECK_EQ(baseline + cast(kSize), |
13481 cast(isolate->AdjustAmountOfExternalAllocatedMemory(kSize))); | 13485 cast(isolate->AdjustAmountOfExternalAllocatedMemory(kSize))); |
13482 CHECK_EQ(baseline, | 13486 CHECK_EQ(baseline, |
13483 cast(isolate->AdjustAmountOfExternalAllocatedMemory(-kSize))); | 13487 cast(isolate->AdjustAmountOfExternalAllocatedMemory(-kSize))); |
13484 } | 13488 } |
13485 | 13489 |
13486 | 13490 |
13487 THREADED_TEST(DisposeEnteredContext) { | |
13488 LocalContext outer; | |
13489 v8::Isolate* isolate = outer->GetIsolate(); | |
13490 v8::Persistent<v8::Context> inner; | |
13491 { | |
13492 v8::HandleScope scope(isolate); | |
13493 inner.Reset(isolate, v8::Context::New(isolate)); | |
13494 } | |
13495 v8::HandleScope scope(isolate); | |
13496 { | |
13497 // Don't want a handle here, so do this unsafely | |
13498 v8::Handle<v8::Context> inner_local = | |
13499 v8::Utils::Convert<i::Object, v8::Context>( | |
13500 v8::Utils::OpenPersistent(inner)); | |
13501 inner_local->Enter(); | |
13502 inner.Dispose(); | |
13503 inner.Clear(); | |
13504 inner_local->Exit(); | |
13505 } | |
13506 } | |
13507 | |
13508 | |
13509 // Regression test for issue 54, object templates with internal fields | 13491 // Regression test for issue 54, object templates with internal fields |
13510 // but no accessors or interceptors did not get their internal field | 13492 // but no accessors or interceptors did not get their internal field |
13511 // count set on instances. | 13493 // count set on instances. |
13512 THREADED_TEST(Regress54) { | 13494 THREADED_TEST(Regress54) { |
13513 LocalContext context; | 13495 LocalContext context; |
13514 v8::Isolate* isolate = context->GetIsolate(); | 13496 v8::Isolate* isolate = context->GetIsolate(); |
13515 v8::HandleScope outer(isolate); | 13497 v8::HandleScope outer(isolate); |
13516 static v8::Persistent<v8::ObjectTemplate> templ; | 13498 static v8::Persistent<v8::ObjectTemplate> templ; |
13517 if (templ.IsEmpty()) { | 13499 if (templ.IsEmpty()) { |
13518 v8::HandleScope inner(isolate); | 13500 v8::HandleScope inner(isolate); |
(...skipping 1515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15034 static v8::Local<Context> calling_context1; | 15016 static v8::Local<Context> calling_context1; |
15035 static v8::Local<Context> calling_context2; | 15017 static v8::Local<Context> calling_context2; |
15036 | 15018 |
15037 | 15019 |
15038 // Check that the call to the callback is initiated in | 15020 // Check that the call to the callback is initiated in |
15039 // calling_context2, the directly calling context is calling_context1 | 15021 // calling_context2, the directly calling context is calling_context1 |
15040 // and the callback itself is in calling_context0. | 15022 // and the callback itself is in calling_context0. |
15041 static void GetCallingContextCallback( | 15023 static void GetCallingContextCallback( |
15042 const v8::FunctionCallbackInfo<v8::Value>& args) { | 15024 const v8::FunctionCallbackInfo<v8::Value>& args) { |
15043 ApiTestFuzzer::Fuzz(); | 15025 ApiTestFuzzer::Fuzz(); |
15044 CHECK(Context::GetCurrent() == calling_context0); | |
15045 CHECK(args.GetIsolate()->GetCurrentContext() == calling_context0); | 15026 CHECK(args.GetIsolate()->GetCurrentContext() == calling_context0); |
15046 CHECK(Context::GetCalling() == calling_context1); | 15027 CHECK(args.GetIsolate()->GetCallingContext() == calling_context1); |
15047 CHECK(Context::GetEntered() == calling_context2); | 15028 CHECK(args.GetIsolate()->GetEnteredContext() == calling_context2); |
15048 args.GetReturnValue().Set(42); | 15029 args.GetReturnValue().Set(42); |
15049 } | 15030 } |
15050 | 15031 |
15051 | 15032 |
15052 THREADED_TEST(GetCurrentContextWhenNotInContext) { | 15033 THREADED_TEST(GetCurrentContextWhenNotInContext) { |
15053 i::Isolate* isolate = CcTest::i_isolate(); | 15034 i::Isolate* isolate = CcTest::i_isolate(); |
15054 CHECK(isolate != NULL); | 15035 CHECK(isolate != NULL); |
15055 CHECK(isolate->context() == NULL); | 15036 CHECK(isolate->context() == NULL); |
15056 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); | 15037 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
15057 v8::HandleScope scope(v8_isolate); | 15038 v8::HandleScope scope(v8_isolate); |
(...skipping 5538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20596 Local<Object> data2 = v8::Object::New(); | 20577 Local<Object> data2 = v8::Object::New(); |
20597 function_new_expected_env = data2; | 20578 function_new_expected_env = data2; |
20598 Local<Function> func2 = Function::New(isolate, FunctionNewCallback, data2); | 20579 Local<Function> func2 = Function::New(isolate, FunctionNewCallback, data2); |
20599 CHECK(!func2->IsNull()); | 20580 CHECK(!func2->IsNull()); |
20600 CHECK_NE(func, func2); | 20581 CHECK_NE(func, func2); |
20601 env->Global()->Set(v8_str("func2"), func2); | 20582 env->Global()->Set(v8_str("func2"), func2); |
20602 Local<Value> result2 = CompileRun("func2();"); | 20583 Local<Value> result2 = CompileRun("func2();"); |
20603 CHECK_EQ(v8::Integer::New(17, isolate), result2); | 20584 CHECK_EQ(v8::Integer::New(17, isolate), result2); |
20604 } | 20585 } |
20605 | 20586 |
OLD | NEW |