Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(355)

Side by Side Diff: test/cctest/test-api.cc

Issue 14793004: deprecate Context::New which returns Persistent (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: use Reset instead of operator= Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/cctest.h ('k') | test/cctest/test-debug.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 4670 matching lines...) Expand 10 before | Expand all | Expand 10 after
4681 "for (var i = 0; i < 10; i++) get_x(obj);" 4681 "for (var i = 0; i < 10; i++) get_x(obj);"
4682 "interceptor_obj.x = 42;" 4682 "interceptor_obj.x = 42;"
4683 "interceptor_obj.y = 10;" 4683 "interceptor_obj.y = 10;"
4684 "delete interceptor_obj.y;" 4684 "delete interceptor_obj.y;"
4685 "get_x(interceptor_obj)"); 4685 "get_x(interceptor_obj)");
4686 CHECK_EQ(result, v8_str("x")); 4686 CHECK_EQ(result, v8_str("x"));
4687 } 4687 }
4688 4688
4689 4689
4690 THREADED_TEST(NamedInterceptorDictionaryICMultipleContext) { 4690 THREADED_TEST(NamedInterceptorDictionaryICMultipleContext) {
4691 v8::HandleScope scope(v8::Isolate::GetCurrent()); 4691 v8::Isolate* isolate = v8::Isolate::GetCurrent();
4692 4692 v8::HandleScope scope(isolate);
4693 v8::Persistent<Context> context1 = Context::New(); 4693 v8::Local<Context> context1 = Context::New(isolate);
4694 4694
4695 context1->Enter(); 4695 context1->Enter();
4696 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4696 Local<ObjectTemplate> templ = ObjectTemplate::New();
4697 templ->SetNamedPropertyHandler(XPropertyGetter); 4697 templ->SetNamedPropertyHandler(XPropertyGetter);
4698 // Create an object with a named interceptor. 4698 // Create an object with a named interceptor.
4699 v8::Local<v8::Object> object = templ->NewInstance(); 4699 v8::Local<v8::Object> object = templ->NewInstance();
4700 context1->Global()->Set(v8_str("interceptor_obj"), object); 4700 context1->Global()->Set(v8_str("interceptor_obj"), object);
4701 4701
4702 // Force the object into the slow case. 4702 // Force the object into the slow case.
4703 CompileRun("interceptor_obj.y = 0;" 4703 CompileRun("interceptor_obj.y = 0;"
(...skipping 14 matching lines...) Expand all
4718 "get_x(interceptor_obj)"); 4718 "get_x(interceptor_obj)");
4719 // Check that the interceptor was actually invoked. 4719 // Check that the interceptor was actually invoked.
4720 CHECK_EQ(result, v8_str("x")); 4720 CHECK_EQ(result, v8_str("x"));
4721 } 4721 }
4722 4722
4723 // Return to the original context and force some object to the slow case 4723 // Return to the original context and force some object to the slow case
4724 // to cause the NormalizedMapCache to verify. 4724 // to cause the NormalizedMapCache to verify.
4725 context1->Enter(); 4725 context1->Enter();
4726 CompileRun("var obj = { x : 0 }; delete obj.x;"); 4726 CompileRun("var obj = { x : 0 }; delete obj.x;");
4727 context1->Exit(); 4727 context1->Exit();
4728
4729 context1.Dispose(context1->GetIsolate());
4730 } 4728 }
4731 4729
4732 4730
4733 static v8::Handle<Value> SetXOnPrototypeGetter(Local<String> property, 4731 static v8::Handle<Value> SetXOnPrototypeGetter(Local<String> property,
4734 const AccessorInfo& info) { 4732 const AccessorInfo& info) {
4735 // Set x on the prototype object and do not handle the get request. 4733 // Set x on the prototype object and do not handle the get request.
4736 v8::Handle<v8::Value> proto = info.Holder()->GetPrototype(); 4734 v8::Handle<v8::Value> proto = info.Holder()->GetPrototype();
4737 proto.As<v8::Object>()->Set(v8_str("x"), v8::Integer::New(23)); 4735 proto.As<v8::Object>()->Set(v8_str("x"), v8::Integer::New(23));
4738 return v8::Handle<Value>(); 4736 return v8::Handle<Value>();
4739 } 4737 }
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after
5494 } 5492 }
5495 5493
5496 5494
5497 static v8::Handle<Value> HandleLogDelegator(const v8::Arguments& args) { 5495 static v8::Handle<Value> HandleLogDelegator(const v8::Arguments& args) {
5498 ApiTestFuzzer::Fuzz(); 5496 ApiTestFuzzer::Fuzz();
5499 return v8::Undefined(); 5497 return v8::Undefined();
5500 } 5498 }
5501 5499
5502 5500
5503 THREADED_TEST(GlobalObjectTemplate) { 5501 THREADED_TEST(GlobalObjectTemplate) {
5504 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 5502 v8::Isolate* isolate = v8::Isolate::GetCurrent();
5503 v8::HandleScope handle_scope(isolate);
5505 Local<ObjectTemplate> global_template = ObjectTemplate::New(); 5504 Local<ObjectTemplate> global_template = ObjectTemplate::New();
5506 global_template->Set(v8_str("JSNI_Log"), 5505 global_template->Set(v8_str("JSNI_Log"),
5507 v8::FunctionTemplate::New(HandleLogDelegator)); 5506 v8::FunctionTemplate::New(HandleLogDelegator));
5508 v8::Persistent<Context> context = Context::New(0, global_template); 5507 v8::Local<Context> context = Context::New(isolate, 0, global_template);
5509 Context::Scope context_scope(v8::Isolate::GetCurrent(), context); 5508 Context::Scope context_scope(context);
5510 Script::Compile(v8_str("JSNI_Log('LOG')"))->Run(); 5509 Script::Compile(v8_str("JSNI_Log('LOG')"))->Run();
5511 context.Dispose(context->GetIsolate());
5512 } 5510 }
5513 5511
5514 5512
5515 static const char* kSimpleExtensionSource = 5513 static const char* kSimpleExtensionSource =
5516 "function Foo() {" 5514 "function Foo() {"
5517 " return 4;" 5515 " return 4;"
5518 "}"; 5516 "}";
5519 5517
5520 5518
5521 THREADED_TEST(SimpleExtensions) { 5519 THREADED_TEST(SimpleExtensions) {
(...skipping 2147 matching lines...) Expand 10 before | Expand all | Expand 10 after
7669 } 7667 }
7670 7668
7671 7669
7672 static void UnreachableSetter(Local<String>, Local<Value>, 7670 static void UnreachableSetter(Local<String>, Local<Value>,
7673 const AccessorInfo&) { 7671 const AccessorInfo&) {
7674 CHECK(false); // This function should nto be called. 7672 CHECK(false); // This function should nto be called.
7675 } 7673 }
7676 7674
7677 7675
7678 TEST(AccessControl) { 7676 TEST(AccessControl) {
7679 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 7677 v8::Isolate* isolate = v8::Isolate::GetCurrent();
7678 v8::HandleScope handle_scope(isolate);
7680 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 7679 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
7681 7680
7682 global_template->SetAccessCheckCallbacks(NamedAccessBlocker, 7681 global_template->SetAccessCheckCallbacks(NamedAccessBlocker,
7683 IndexedAccessBlocker); 7682 IndexedAccessBlocker);
7684 7683
7685 // Add an accessor accessible by cross-domain JS code. 7684 // Add an accessor accessible by cross-domain JS code.
7686 global_template->SetAccessor( 7685 global_template->SetAccessor(
7687 v8_str("accessible_prop"), 7686 v8_str("accessible_prop"),
7688 EchoGetter, EchoSetter, 7687 EchoGetter, EchoSetter,
7689 v8::Handle<Value>(), 7688 v8::Handle<Value>(),
7690 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); 7689 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE));
7691 7690
7692 // Add an accessor that is not accessible by cross-domain JS code. 7691 // Add an accessor that is not accessible by cross-domain JS code.
7693 global_template->SetAccessor(v8_str("blocked_prop"), 7692 global_template->SetAccessor(v8_str("blocked_prop"),
7694 UnreachableGetter, UnreachableSetter, 7693 UnreachableGetter, UnreachableSetter,
7695 v8::Handle<Value>(), 7694 v8::Handle<Value>(),
7696 v8::DEFAULT); 7695 v8::DEFAULT);
7697 7696
7698 // Create an environment 7697 // Create an environment
7699 v8::Persistent<Context> context0 = Context::New(NULL, global_template); 7698 v8::Local<Context> context0 = Context::New(isolate, NULL, global_template);
7700 context0->Enter(); 7699 context0->Enter();
7701 7700
7702 v8::Handle<v8::Object> global0 = context0->Global(); 7701 v8::Handle<v8::Object> global0 = context0->Global();
7703 7702
7704 // Define a property with JS getter and setter. 7703 // Define a property with JS getter and setter.
7705 CompileRun( 7704 CompileRun(
7706 "function getter() { return 'getter'; };\n" 7705 "function getter() { return 'getter'; };\n"
7707 "function setter() { return 'setter'; }\n" 7706 "function setter() { return 'setter'; }\n"
7708 "Object.defineProperty(this, 'js_accessor_p', {get:getter, set:setter})"); 7707 "Object.defineProperty(this, 'js_accessor_p', {get:getter, set:setter})");
7709 7708
7710 Local<Value> getter = global0->Get(v8_str("getter")); 7709 Local<Value> getter = global0->Get(v8_str("getter"));
7711 Local<Value> setter = global0->Get(v8_str("setter")); 7710 Local<Value> setter = global0->Get(v8_str("setter"));
7712 7711
7713 // And define normal element. 7712 // And define normal element.
7714 global0->Set(239, v8_str("239")); 7713 global0->Set(239, v8_str("239"));
7715 7714
7716 // Define an element with JS getter and setter. 7715 // Define an element with JS getter and setter.
7717 CompileRun( 7716 CompileRun(
7718 "function el_getter() { return 'el_getter'; };\n" 7717 "function el_getter() { return 'el_getter'; };\n"
7719 "function el_setter() { return 'el_setter'; };\n" 7718 "function el_setter() { return 'el_setter'; };\n"
7720 "Object.defineProperty(this, '42', {get: el_getter, set: el_setter});"); 7719 "Object.defineProperty(this, '42', {get: el_getter, set: el_setter});");
7721 7720
7722 Local<Value> el_getter = global0->Get(v8_str("el_getter")); 7721 Local<Value> el_getter = global0->Get(v8_str("el_getter"));
7723 Local<Value> el_setter = global0->Get(v8_str("el_setter")); 7722 Local<Value> el_setter = global0->Get(v8_str("el_setter"));
7724 7723
7725 v8::HandleScope scope1(v8::Isolate::GetCurrent()); 7724 v8::HandleScope scope1(isolate);
7726 7725
7727 v8::Persistent<Context> context1 = Context::New(); 7726 v8::Local<Context> context1 = Context::New(isolate);
7728 context1->Enter(); 7727 context1->Enter();
7729 7728
7730 v8::Handle<v8::Object> global1 = context1->Global(); 7729 v8::Handle<v8::Object> global1 = context1->Global();
7731 global1->Set(v8_str("other"), global0); 7730 global1->Set(v8_str("other"), global0);
7732 7731
7733 // Access blocked property. 7732 // Access blocked property.
7734 CompileRun("other.blocked_prop = 1"); 7733 CompileRun("other.blocked_prop = 1");
7735 7734
7736 ExpectUndefined("other.blocked_prop"); 7735 ExpectUndefined("other.blocked_prop");
7737 ExpectUndefined( 7736 ExpectUndefined(
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
7907 CompileRun("(function(){var obj = {'__proto__':other};" 7906 CompileRun("(function(){var obj = {'__proto__':other};"
7908 "for (var p in obj)" 7907 "for (var p in obj)"
7909 " if (p == 'accessible_prop' || p == 'blocked_prop') {" 7908 " if (p == 'accessible_prop' || p == 'blocked_prop') {"
7910 " return false;" 7909 " return false;"
7911 " }" 7910 " }"
7912 "return true;})()"); 7911 "return true;})()");
7913 CHECK(value->IsTrue()); 7912 CHECK(value->IsTrue());
7914 7913
7915 context1->Exit(); 7914 context1->Exit();
7916 context0->Exit(); 7915 context0->Exit();
7917 context1.Dispose(context1->GetIsolate());
7918 context0.Dispose(context0->GetIsolate());
7919 } 7916 }
7920 7917
7921 7918
7922 TEST(AccessControlES5) { 7919 TEST(AccessControlES5) {
7923 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 7920 v8::Isolate* isolate = v8::Isolate::GetCurrent();
7921 v8::HandleScope handle_scope(isolate);
7924 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 7922 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
7925 7923
7926 global_template->SetAccessCheckCallbacks(NamedAccessBlocker, 7924 global_template->SetAccessCheckCallbacks(NamedAccessBlocker,
7927 IndexedAccessBlocker); 7925 IndexedAccessBlocker);
7928 7926
7929 // Add accessible accessor. 7927 // Add accessible accessor.
7930 global_template->SetAccessor( 7928 global_template->SetAccessor(
7931 v8_str("accessible_prop"), 7929 v8_str("accessible_prop"),
7932 EchoGetter, EchoSetter, 7930 EchoGetter, EchoSetter,
7933 v8::Handle<Value>(), 7931 v8::Handle<Value>(),
7934 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); 7932 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE));
7935 7933
7936 7934
7937 // Add an accessor that is not accessible by cross-domain JS code. 7935 // Add an accessor that is not accessible by cross-domain JS code.
7938 global_template->SetAccessor(v8_str("blocked_prop"), 7936 global_template->SetAccessor(v8_str("blocked_prop"),
7939 UnreachableGetter, UnreachableSetter, 7937 UnreachableGetter, UnreachableSetter,
7940 v8::Handle<Value>(), 7938 v8::Handle<Value>(),
7941 v8::DEFAULT); 7939 v8::DEFAULT);
7942 7940
7943 // Create an environment 7941 // Create an environment
7944 v8::Persistent<Context> context0 = Context::New(NULL, global_template); 7942 v8::Local<Context> context0 = Context::New(isolate, NULL, global_template);
7945 context0->Enter(); 7943 context0->Enter();
7946 7944
7947 v8::Handle<v8::Object> global0 = context0->Global(); 7945 v8::Handle<v8::Object> global0 = context0->Global();
7948 7946
7949 v8::Persistent<Context> context1 = Context::New(); 7947 v8::Local<Context> context1 = Context::New(isolate);
7950 context1->Enter(); 7948 context1->Enter();
7951 v8::Handle<v8::Object> global1 = context1->Global(); 7949 v8::Handle<v8::Object> global1 = context1->Global();
7952 global1->Set(v8_str("other"), global0); 7950 global1->Set(v8_str("other"), global0);
7953 7951
7954 // Regression test for issue 1154. 7952 // Regression test for issue 1154.
7955 ExpectTrue("Object.keys(other).indexOf('blocked_prop') == -1"); 7953 ExpectTrue("Object.keys(other).indexOf('blocked_prop') == -1");
7956 7954
7957 ExpectUndefined("other.blocked_prop"); 7955 ExpectUndefined("other.blocked_prop");
7958 7956
7959 // Regression test for issue 1027. 7957 // Regression test for issue 1027.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
7999 7997
8000 static bool GetOwnPropertyNamesIndexedBlocker(Local<v8::Object> global, 7998 static bool GetOwnPropertyNamesIndexedBlocker(Local<v8::Object> global,
8001 uint32_t key, 7999 uint32_t key,
8002 v8::AccessType type, 8000 v8::AccessType type,
8003 Local<Value> data) { 8001 Local<Value> data) {
8004 return false; 8002 return false;
8005 } 8003 }
8006 8004
8007 8005
8008 THREADED_TEST(AccessControlGetOwnPropertyNames) { 8006 THREADED_TEST(AccessControlGetOwnPropertyNames) {
8009 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 8007 v8::Isolate* isolate = v8::Isolate::GetCurrent();
8008 v8::HandleScope handle_scope(isolate);
8010 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(); 8009 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New();
8011 8010
8012 obj_template->Set(v8_str("x"), v8::Integer::New(42)); 8011 obj_template->Set(v8_str("x"), v8::Integer::New(42));
8013 obj_template->SetAccessCheckCallbacks(GetOwnPropertyNamesNamedBlocker, 8012 obj_template->SetAccessCheckCallbacks(GetOwnPropertyNamesNamedBlocker,
8014 GetOwnPropertyNamesIndexedBlocker); 8013 GetOwnPropertyNamesIndexedBlocker);
8015 8014
8016 // Create an environment 8015 // Create an environment
8017 v8::Persistent<Context> context0 = Context::New(NULL, obj_template); 8016 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template);
8018 context0->Enter(); 8017 context0->Enter();
8019 8018
8020 v8::Handle<v8::Object> global0 = context0->Global(); 8019 v8::Handle<v8::Object> global0 = context0->Global();
8021 8020
8022 v8::HandleScope scope1(v8::Isolate::GetCurrent()); 8021 v8::HandleScope scope1(v8::Isolate::GetCurrent());
8023 8022
8024 v8::Persistent<Context> context1 = Context::New(); 8023 v8::Local<Context> context1 = Context::New(isolate);
8025 context1->Enter(); 8024 context1->Enter();
8026 8025
8027 v8::Handle<v8::Object> global1 = context1->Global(); 8026 v8::Handle<v8::Object> global1 = context1->Global();
8028 global1->Set(v8_str("other"), global0); 8027 global1->Set(v8_str("other"), global0);
8029 global1->Set(v8_str("object"), obj_template->NewInstance()); 8028 global1->Set(v8_str("object"), obj_template->NewInstance());
8030 8029
8031 v8::Handle<Value> value; 8030 v8::Handle<Value> value;
8032 8031
8033 // Attempt to get the property names of the other global object and 8032 // Attempt to get the property names of the other global object and
8034 // of an object that requires access checks. Accessing the other 8033 // of an object that requires access checks. Accessing the other
8035 // global object should be blocked by access checks on the global 8034 // global object should be blocked by access checks on the global
8036 // proxy object. Accessing the object that requires access checks 8035 // proxy object. Accessing the object that requires access checks
8037 // is blocked by the access checks on the object itself. 8036 // is blocked by the access checks on the object itself.
8038 value = CompileRun("Object.getOwnPropertyNames(other).length == 0"); 8037 value = CompileRun("Object.getOwnPropertyNames(other).length == 0");
8039 CHECK(value->IsTrue()); 8038 CHECK(value->IsTrue());
8040 8039
8041 value = CompileRun("Object.getOwnPropertyNames(object).length == 0"); 8040 value = CompileRun("Object.getOwnPropertyNames(object).length == 0");
8042 CHECK(value->IsTrue()); 8041 CHECK(value->IsTrue());
8043 8042
8044 context1->Exit(); 8043 context1->Exit();
8045 context0->Exit(); 8044 context0->Exit();
8046 context1.Dispose(context1->GetIsolate());
8047 context0.Dispose(context0->GetIsolate());
8048 } 8045 }
8049 8046
8050 8047
8051 static v8::Handle<v8::Array> IndexedPropertyEnumerator(const AccessorInfo&) { 8048 static v8::Handle<v8::Array> IndexedPropertyEnumerator(const AccessorInfo&) {
8052 v8::Handle<v8::Array> result = v8::Array::New(2); 8049 v8::Handle<v8::Array> result = v8::Array::New(2);
8053 result->Set(0, v8::Integer::New(7)); 8050 result->Set(0, v8::Integer::New(7));
8054 result->Set(1, v8::Object::New()); 8051 result->Set(1, v8::Object::New());
8055 return result; 8052 return result;
8056 } 8053 }
8057 8054
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
8093 } 8090 }
8094 8091
8095 8092
8096 static v8::Handle<Value> ConstTenGetter(Local<String> name, 8093 static v8::Handle<Value> ConstTenGetter(Local<String> name,
8097 const AccessorInfo& info) { 8094 const AccessorInfo& info) {
8098 return v8_num(10); 8095 return v8_num(10);
8099 } 8096 }
8100 8097
8101 8098
8102 THREADED_TEST(CrossDomainAccessors) { 8099 THREADED_TEST(CrossDomainAccessors) {
8103 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 8100 v8::Isolate* isolate = v8::Isolate::GetCurrent();
8101 v8::HandleScope handle_scope(isolate);
8104 8102
8105 v8::Handle<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(); 8103 v8::Handle<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New();
8106 8104
8107 v8::Handle<v8::ObjectTemplate> global_template = 8105 v8::Handle<v8::ObjectTemplate> global_template =
8108 func_template->InstanceTemplate(); 8106 func_template->InstanceTemplate();
8109 8107
8110 v8::Handle<v8::ObjectTemplate> proto_template = 8108 v8::Handle<v8::ObjectTemplate> proto_template =
8111 func_template->PrototypeTemplate(); 8109 func_template->PrototypeTemplate();
8112 8110
8113 // Add an accessor to proto that's accessible by cross-domain JS code. 8111 // Add an accessor to proto that's accessible by cross-domain JS code.
8114 proto_template->SetAccessor(v8_str("accessible"), 8112 proto_template->SetAccessor(v8_str("accessible"),
8115 ConstTenGetter, 0, 8113 ConstTenGetter, 0,
8116 v8::Handle<Value>(), 8114 v8::Handle<Value>(),
8117 v8::ALL_CAN_READ); 8115 v8::ALL_CAN_READ);
8118 8116
8119 // Add an accessor that is not accessible by cross-domain JS code. 8117 // Add an accessor that is not accessible by cross-domain JS code.
8120 global_template->SetAccessor(v8_str("unreachable"), 8118 global_template->SetAccessor(v8_str("unreachable"),
8121 UnreachableGetter, 0, 8119 UnreachableGetter, 0,
8122 v8::Handle<Value>(), 8120 v8::Handle<Value>(),
8123 v8::DEFAULT); 8121 v8::DEFAULT);
8124 8122
8125 v8::Persistent<Context> context0 = Context::New(NULL, global_template); 8123 v8::Local<Context> context0 = Context::New(isolate, NULL, global_template);
8126 context0->Enter(); 8124 context0->Enter();
8127 8125
8128 Local<v8::Object> global = context0->Global(); 8126 Local<v8::Object> global = context0->Global();
8129 // Add a normal property that shadows 'accessible' 8127 // Add a normal property that shadows 'accessible'
8130 global->Set(v8_str("accessible"), v8_num(11)); 8128 global->Set(v8_str("accessible"), v8_num(11));
8131 8129
8132 // Enter a new context. 8130 // Enter a new context.
8133 v8::HandleScope scope1(v8::Isolate::GetCurrent()); 8131 v8::HandleScope scope1(v8::Isolate::GetCurrent());
8134 v8::Persistent<Context> context1 = Context::New(); 8132 v8::Local<Context> context1 = Context::New(isolate);
8135 context1->Enter(); 8133 context1->Enter();
8136 8134
8137 v8::Handle<v8::Object> global1 = context1->Global(); 8135 v8::Handle<v8::Object> global1 = context1->Global();
8138 global1->Set(v8_str("other"), global); 8136 global1->Set(v8_str("other"), global);
8139 8137
8140 // Should return 10, instead of 11 8138 // Should return 10, instead of 11
8141 v8::Handle<Value> value = v8_compile("other.accessible")->Run(); 8139 v8::Handle<Value> value = v8_compile("other.accessible")->Run();
8142 CHECK(value->IsNumber()); 8140 CHECK(value->IsNumber());
8143 CHECK_EQ(10, value->Int32Value()); 8141 CHECK_EQ(10, value->Int32Value());
8144 8142
8145 value = v8_compile("other.unreachable")->Run(); 8143 value = v8_compile("other.unreachable")->Run();
8146 CHECK(value->IsUndefined()); 8144 CHECK(value->IsUndefined());
8147 8145
8148 context1->Exit(); 8146 context1->Exit();
8149 context0->Exit(); 8147 context0->Exit();
8150 context1.Dispose(context1->GetIsolate());
8151 context0.Dispose(context0->GetIsolate());
8152 } 8148 }
8153 8149
8154 8150
8155 static int named_access_count = 0; 8151 static int named_access_count = 0;
8156 static int indexed_access_count = 0; 8152 static int indexed_access_count = 0;
8157 8153
8158 static bool NamedAccessCounter(Local<v8::Object> global, 8154 static bool NamedAccessCounter(Local<v8::Object> global,
8159 Local<Value> name, 8155 Local<Value> name,
8160 v8::AccessType type, 8156 v8::AccessType type,
8161 Local<Value> data) { 8157 Local<Value> data) {
8162 named_access_count++; 8158 named_access_count++;
8163 return true; 8159 return true;
8164 } 8160 }
8165 8161
8166 8162
8167 static bool IndexedAccessCounter(Local<v8::Object> global, 8163 static bool IndexedAccessCounter(Local<v8::Object> global,
8168 uint32_t key, 8164 uint32_t key,
8169 v8::AccessType type, 8165 v8::AccessType type,
8170 Local<Value> data) { 8166 Local<Value> data) {
8171 indexed_access_count++; 8167 indexed_access_count++;
8172 return true; 8168 return true;
8173 } 8169 }
8174 8170
8175 8171
8176 // This one is too easily disturbed by other tests. 8172 // This one is too easily disturbed by other tests.
8177 TEST(AccessControlIC) { 8173 TEST(AccessControlIC) {
8178 named_access_count = 0; 8174 named_access_count = 0;
8179 indexed_access_count = 0; 8175 indexed_access_count = 0;
8180 8176
8181 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 8177 v8::Isolate* isolate = v8::Isolate::GetCurrent();
8178 v8::HandleScope handle_scope(isolate);
8182 8179
8183 // Create an environment. 8180 // Create an environment.
8184 v8::Persistent<Context> context0 = Context::New(); 8181 v8::Local<Context> context0 = Context::New(isolate);
8185 context0->Enter(); 8182 context0->Enter();
8186 8183
8187 // Create an object that requires access-check functions to be 8184 // Create an object that requires access-check functions to be
8188 // called for cross-domain access. 8185 // called for cross-domain access.
8189 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); 8186 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New();
8190 object_template->SetAccessCheckCallbacks(NamedAccessCounter, 8187 object_template->SetAccessCheckCallbacks(NamedAccessCounter,
8191 IndexedAccessCounter); 8188 IndexedAccessCounter);
8192 Local<v8::Object> object = object_template->NewInstance(); 8189 Local<v8::Object> object = object_template->NewInstance();
8193 8190
8194 v8::HandleScope scope1(v8::Isolate::GetCurrent()); 8191 v8::HandleScope scope1(isolate);
8195 8192
8196 // Create another environment. 8193 // Create another environment.
8197 v8::Persistent<Context> context1 = Context::New(); 8194 v8::Local<Context> context1 = Context::New(isolate);
8198 context1->Enter(); 8195 context1->Enter();
8199 8196
8200 // Make easy access to the object from the other environment. 8197 // Make easy access to the object from the other environment.
8201 v8::Handle<v8::Object> global1 = context1->Global(); 8198 v8::Handle<v8::Object> global1 = context1->Global();
8202 global1->Set(v8_str("obj"), object); 8199 global1->Set(v8_str("obj"), object);
8203 8200
8204 v8::Handle<Value> value; 8201 v8::Handle<Value> value;
8205 8202
8206 // Check that the named access-control function is called every time. 8203 // Check that the named access-control function is called every time.
8207 CompileRun("function testProp(obj) {" 8204 CompileRun("function testProp(obj) {"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
8275 8272
8276 // Force the call inline cache into dictionary probing mode. 8273 // Force the call inline cache into dictionary probing mode.
8277 CompileRun("o.f = function() {}; testCallNormal(o)"); 8274 CompileRun("o.f = function() {}; testCallNormal(o)");
8278 // Test that the named access check is still called for each 8275 // Test that the named access check is still called for each
8279 // invocation of the function. 8276 // invocation of the function.
8280 value = CompileRun("testCallNormal(obj)"); 8277 value = CompileRun("testCallNormal(obj)");
8281 CHECK_EQ(106, named_access_count); 8278 CHECK_EQ(106, named_access_count);
8282 8279
8283 context1->Exit(); 8280 context1->Exit();
8284 context0->Exit(); 8281 context0->Exit();
8285 context1.Dispose(context1->GetIsolate());
8286 context0.Dispose(context0->GetIsolate());
8287 } 8282 }
8288 8283
8289 8284
8290 static bool NamedAccessFlatten(Local<v8::Object> global, 8285 static bool NamedAccessFlatten(Local<v8::Object> global,
8291 Local<Value> name, 8286 Local<Value> name,
8292 v8::AccessType type, 8287 v8::AccessType type,
8293 Local<Value> data) { 8288 Local<Value> data) {
8294 char buf[100]; 8289 char buf[100];
8295 int len; 8290 int len;
8296 8291
(...skipping 23 matching lines...) Expand all
8320 8315
8321 // Regression test. In access checks, operations that may cause 8316 // Regression test. In access checks, operations that may cause
8322 // garbage collection are not allowed. It used to be the case that 8317 // garbage collection are not allowed. It used to be the case that
8323 // using the Write operation on a string could cause a garbage 8318 // using the Write operation on a string could cause a garbage
8324 // collection due to flattening of the string. This is no longer the 8319 // collection due to flattening of the string. This is no longer the
8325 // case. 8320 // case.
8326 THREADED_TEST(AccessControlFlatten) { 8321 THREADED_TEST(AccessControlFlatten) {
8327 named_access_count = 0; 8322 named_access_count = 0;
8328 indexed_access_count = 0; 8323 indexed_access_count = 0;
8329 8324
8330 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 8325 v8::Isolate* isolate = v8::Isolate::GetCurrent();
8326 v8::HandleScope handle_scope(isolate);
8331 8327
8332 // Create an environment. 8328 // Create an environment.
8333 v8::Persistent<Context> context0 = Context::New(); 8329 v8::Local<Context> context0 = Context::New(isolate);
8334 context0->Enter(); 8330 context0->Enter();
8335 8331
8336 // Create an object that requires access-check functions to be 8332 // Create an object that requires access-check functions to be
8337 // called for cross-domain access. 8333 // called for cross-domain access.
8338 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); 8334 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New();
8339 object_template->SetAccessCheckCallbacks(NamedAccessFlatten, 8335 object_template->SetAccessCheckCallbacks(NamedAccessFlatten,
8340 IndexedAccessFlatten); 8336 IndexedAccessFlatten);
8341 Local<v8::Object> object = object_template->NewInstance(); 8337 Local<v8::Object> object = object_template->NewInstance();
8342 8338
8343 v8::HandleScope scope1(v8::Isolate::GetCurrent()); 8339 v8::HandleScope scope1(isolate);
8344 8340
8345 // Create another environment. 8341 // Create another environment.
8346 v8::Persistent<Context> context1 = Context::New(); 8342 v8::Local<Context> context1 = Context::New(isolate);
8347 context1->Enter(); 8343 context1->Enter();
8348 8344
8349 // Make easy access to the object from the other environment. 8345 // Make easy access to the object from the other environment.
8350 v8::Handle<v8::Object> global1 = context1->Global(); 8346 v8::Handle<v8::Object> global1 = context1->Global();
8351 global1->Set(v8_str("obj"), object); 8347 global1->Set(v8_str("obj"), object);
8352 8348
8353 v8::Handle<Value> value; 8349 v8::Handle<Value> value;
8354 8350
8355 value = v8_compile("var p = 'as' + 'df';")->Run(); 8351 value = v8_compile("var p = 'as' + 'df';")->Run();
8356 value = v8_compile("obj[p];")->Run(); 8352 value = v8_compile("obj[p];")->Run();
8357 8353
8358 context1->Exit(); 8354 context1->Exit();
8359 context0->Exit(); 8355 context0->Exit();
8360 context1.Dispose(context1->GetIsolate());
8361 context0.Dispose(context0->GetIsolate());
8362 } 8356 }
8363 8357
8364 8358
8365 static v8::Handle<Value> AccessControlNamedGetter( 8359 static v8::Handle<Value> AccessControlNamedGetter(
8366 Local<String>, const AccessorInfo&) { 8360 Local<String>, const AccessorInfo&) {
8367 return v8::Integer::New(42); 8361 return v8::Integer::New(42);
8368 } 8362 }
8369 8363
8370 8364
8371 static v8::Handle<Value> AccessControlNamedSetter( 8365 static v8::Handle<Value> AccessControlNamedSetter(
(...skipping 12 matching lines...) Expand all
8384 static v8::Handle<Value> AccessControlIndexedSetter( 8378 static v8::Handle<Value> AccessControlIndexedSetter(
8385 uint32_t, Local<Value> value, const AccessorInfo&) { 8379 uint32_t, Local<Value> value, const AccessorInfo&) {
8386 return value; 8380 return value;
8387 } 8381 }
8388 8382
8389 8383
8390 THREADED_TEST(AccessControlInterceptorIC) { 8384 THREADED_TEST(AccessControlInterceptorIC) {
8391 named_access_count = 0; 8385 named_access_count = 0;
8392 indexed_access_count = 0; 8386 indexed_access_count = 0;
8393 8387
8394 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 8388 v8::Isolate* isolate = v8::Isolate::GetCurrent();
8389 v8::HandleScope handle_scope(isolate);
8395 8390
8396 // Create an environment. 8391 // Create an environment.
8397 v8::Persistent<Context> context0 = Context::New(); 8392 v8::Local<Context> context0 = Context::New(isolate);
8398 context0->Enter(); 8393 context0->Enter();
8399 8394
8400 // Create an object that requires access-check functions to be 8395 // Create an object that requires access-check functions to be
8401 // called for cross-domain access. The object also has interceptors 8396 // called for cross-domain access. The object also has interceptors
8402 // interceptor. 8397 // interceptor.
8403 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); 8398 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New();
8404 object_template->SetAccessCheckCallbacks(NamedAccessCounter, 8399 object_template->SetAccessCheckCallbacks(NamedAccessCounter,
8405 IndexedAccessCounter); 8400 IndexedAccessCounter);
8406 object_template->SetNamedPropertyHandler(AccessControlNamedGetter, 8401 object_template->SetNamedPropertyHandler(AccessControlNamedGetter,
8407 AccessControlNamedSetter); 8402 AccessControlNamedSetter);
8408 object_template->SetIndexedPropertyHandler(AccessControlIndexedGetter, 8403 object_template->SetIndexedPropertyHandler(AccessControlIndexedGetter,
8409 AccessControlIndexedSetter); 8404 AccessControlIndexedSetter);
8410 Local<v8::Object> object = object_template->NewInstance(); 8405 Local<v8::Object> object = object_template->NewInstance();
8411 8406
8412 v8::HandleScope scope1(v8::Isolate::GetCurrent()); 8407 v8::HandleScope scope1(isolate);
8413 8408
8414 // Create another environment. 8409 // Create another environment.
8415 v8::Persistent<Context> context1 = Context::New(); 8410 v8::Local<Context> context1 = Context::New(isolate);
8416 context1->Enter(); 8411 context1->Enter();
8417 8412
8418 // Make easy access to the object from the other environment. 8413 // Make easy access to the object from the other environment.
8419 v8::Handle<v8::Object> global1 = context1->Global(); 8414 v8::Handle<v8::Object> global1 = context1->Global();
8420 global1->Set(v8_str("obj"), object); 8415 global1->Set(v8_str("obj"), object);
8421 8416
8422 v8::Handle<Value> value; 8417 v8::Handle<Value> value;
8423 8418
8424 // Check that the named access-control function is called every time 8419 // Check that the named access-control function is called every time
8425 // eventhough there is an interceptor on the object. 8420 // eventhough there is an interceptor on the object.
(...skipping 16 matching lines...) Expand all
8442 // time eventhough there is an interceptor on the object. 8437 // time eventhough there is an interceptor on the object.
8443 value = v8_compile("for (var i = 0; i < 10; i++) obj[0] = 1;")->Run(); 8438 value = v8_compile("for (var i = 0; i < 10; i++) obj[0] = 1;")->Run();
8444 value = v8_compile("for (var i = 0; i < 10; i++) obj[0];" 8439 value = v8_compile("for (var i = 0; i < 10; i++) obj[0];"
8445 "obj[0]")->Run(); 8440 "obj[0]")->Run();
8446 CHECK(value->IsNumber()); 8441 CHECK(value->IsNumber());
8447 CHECK_EQ(42, value->Int32Value()); 8442 CHECK_EQ(42, value->Int32Value());
8448 CHECK_EQ(21, indexed_access_count); 8443 CHECK_EQ(21, indexed_access_count);
8449 8444
8450 context1->Exit(); 8445 context1->Exit();
8451 context0->Exit(); 8446 context0->Exit();
8452 context1.Dispose(context1->GetIsolate());
8453 context0.Dispose(context0->GetIsolate());
8454 } 8447 }
8455 8448
8456 8449
8457 THREADED_TEST(Version) { 8450 THREADED_TEST(Version) {
8458 v8::V8::GetVersion(); 8451 v8::V8::GetVersion();
8459 } 8452 }
8460 8453
8461 8454
8462 static v8::Handle<Value> InstanceFunctionCallback(const v8::Arguments& args) { 8455 static v8::Handle<Value> InstanceFunctionCallback(const v8::Arguments& args) {
8463 ApiTestFuzzer::Fuzz(); 8456 ApiTestFuzzer::Fuzz();
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after
9304 Script::Compile(v8_str("other.y = 1; eval.call(other, 'y')")); 9297 Script::Compile(v8_str("other.y = 1; eval.call(other, 'y')"));
9305 result = script->Run(); 9298 result = script->Run();
9306 CHECK(try_catch.HasCaught()); 9299 CHECK(try_catch.HasCaught());
9307 } 9300 }
9308 9301
9309 9302
9310 // Test that calling eval in a context which has been detached from 9303 // Test that calling eval in a context which has been detached from
9311 // its global throws an exception. This behavior is consistent with 9304 // its global throws an exception. This behavior is consistent with
9312 // other JavaScript implementations. 9305 // other JavaScript implementations.
9313 THREADED_TEST(EvalInDetachedGlobal) { 9306 THREADED_TEST(EvalInDetachedGlobal) {
9314 v8::HandleScope scope(v8::Isolate::GetCurrent()); 9307 v8::Isolate* isolate = v8::Isolate::GetCurrent();
9308 v8::HandleScope scope(isolate);
9315 9309
9316 v8::Persistent<Context> context0 = Context::New(); 9310 v8::Local<Context> context0 = Context::New(isolate);
9317 v8::Persistent<Context> context1 = Context::New(); 9311 v8::Local<Context> context1 = Context::New(isolate);
9318 9312
9319 // Set up function in context0 that uses eval from context0. 9313 // Set up function in context0 that uses eval from context0.
9320 context0->Enter(); 9314 context0->Enter();
9321 v8::Handle<v8::Value> fun = 9315 v8::Handle<v8::Value> fun =
9322 CompileRun("var x = 42;" 9316 CompileRun("var x = 42;"
9323 "(function() {" 9317 "(function() {"
9324 " var e = eval;" 9318 " var e = eval;"
9325 " return function(s) { return e(s); }" 9319 " return function(s) { return e(s); }"
9326 "})()"); 9320 "})()");
9327 context0->Exit(); 9321 context0->Exit();
9328 9322
9329 // Put the function into context1 and call it before and after 9323 // Put the function into context1 and call it before and after
9330 // detaching the global. Before detaching, the call succeeds and 9324 // detaching the global. Before detaching, the call succeeds and
9331 // after detaching and exception is thrown. 9325 // after detaching and exception is thrown.
9332 context1->Enter(); 9326 context1->Enter();
9333 context1->Global()->Set(v8_str("fun"), fun); 9327 context1->Global()->Set(v8_str("fun"), fun);
9334 v8::Handle<v8::Value> x_value = CompileRun("fun('x')"); 9328 v8::Handle<v8::Value> x_value = CompileRun("fun('x')");
9335 CHECK_EQ(42, x_value->Int32Value()); 9329 CHECK_EQ(42, x_value->Int32Value());
9336 context0->DetachGlobal(); 9330 context0->DetachGlobal();
9337 v8::TryCatch catcher; 9331 v8::TryCatch catcher;
9338 x_value = CompileRun("fun('x')"); 9332 x_value = CompileRun("fun('x')");
9339 CHECK(x_value.IsEmpty()); 9333 CHECK(x_value.IsEmpty());
9340 CHECK(catcher.HasCaught()); 9334 CHECK(catcher.HasCaught());
9341 context1->Exit(); 9335 context1->Exit();
9342
9343 context1.Dispose(context1->GetIsolate());
9344 context0.Dispose(context0->GetIsolate());
9345 } 9336 }
9346 9337
9347 9338
9348 THREADED_TEST(CrossLazyLoad) { 9339 THREADED_TEST(CrossLazyLoad) {
9349 v8::HandleScope scope(v8::Isolate::GetCurrent()); 9340 v8::HandleScope scope(v8::Isolate::GetCurrent());
9350 LocalContext other; 9341 LocalContext other;
9351 LocalContext current; 9342 LocalContext current;
9352 9343
9353 Local<String> token = v8_str("<security token>"); 9344 Local<String> token = v8_str("<security token>");
9354 other->SetSecurityToken(token); 9345 other->SetSecurityToken(token);
(...skipping 2612 matching lines...) Expand 10 before | Expand all | Expand 10 after
11967 CompileRun(source); 11958 CompileRun(source);
11968 } 11959 }
11969 { v8::HandleScope scope(v8::Isolate::GetCurrent()); 11960 { v8::HandleScope scope(v8::Isolate::GetCurrent());
11970 LocalContext context; 11961 LocalContext context;
11971 CompileRun(source); 11962 CompileRun(source);
11972 } 11963 }
11973 } 11964 }
11974 } 11965 }
11975 11966
11976 11967
11977 static v8::Handle<Value> NestedScope(v8::Persistent<Context> env) { 11968 static v8::Handle<Value> NestedScope(v8::Local<Context> env) {
11978 v8::HandleScope inner(env->GetIsolate()); 11969 v8::HandleScope inner(env->GetIsolate());
11979 env->Enter(); 11970 env->Enter();
11980 v8::Handle<Value> three = v8_num(3); 11971 v8::Handle<Value> three = v8_num(3);
11981 v8::Handle<Value> value = inner.Close(three); 11972 v8::Handle<Value> value = inner.Close(three);
11982 env->Exit(); 11973 env->Exit();
11983 return value; 11974 return value;
11984 } 11975 }
11985 11976
11986 11977
11987 THREADED_TEST(NestedHandleScopeAndContexts) { 11978 THREADED_TEST(NestedHandleScopeAndContexts) {
11988 v8::HandleScope outer(v8::Isolate::GetCurrent()); 11979 v8::Isolate* isolate = v8::Isolate::GetCurrent();
11989 v8::Persistent<Context> env = Context::New(); 11980 v8::HandleScope outer(isolate);
11981 v8::Local<Context> env = Context::New(isolate);
11990 env->Enter(); 11982 env->Enter();
11991 v8::Handle<Value> value = NestedScope(env); 11983 v8::Handle<Value> value = NestedScope(env);
11992 v8::Handle<String> str(value->ToString()); 11984 v8::Handle<String> str(value->ToString());
11993 CHECK(!str.IsEmpty()); 11985 CHECK(!str.IsEmpty());
11994 env->Exit(); 11986 env->Exit();
11995 env.Dispose(env->GetIsolate());
11996 } 11987 }
11997 11988
11998 11989
11999 static i::Handle<i::JSFunction>* foo_ptr = NULL; 11990 static i::Handle<i::JSFunction>* foo_ptr = NULL;
12000 static int foo_count = 0; 11991 static int foo_count = 0;
12001 static i::Handle<i::JSFunction>* bar_ptr = NULL; 11992 static i::Handle<i::JSFunction>* bar_ptr = NULL;
12002 static int bar_count = 0; 11993 static int bar_count = 0;
12003 11994
12004 11995
12005 static void entry_hook(uintptr_t function, 11996 static void entry_hook(uintptr_t function,
(...skipping 11 matching lines...) Expand all
12017 // TODO(siggi): Verify return_addr_location. 12008 // TODO(siggi): Verify return_addr_location.
12018 // This can be done by capturing JitCodeEvents, but requires an ordered 12009 // This can be done by capturing JitCodeEvents, but requires an ordered
12019 // collection. 12010 // collection.
12020 } 12011 }
12021 12012
12022 12013
12023 static void RunLoopInNewEnv() { 12014 static void RunLoopInNewEnv() {
12024 bar_ptr = NULL; 12015 bar_ptr = NULL;
12025 foo_ptr = NULL; 12016 foo_ptr = NULL;
12026 12017
12027 v8::HandleScope outer(v8::Isolate::GetCurrent()); 12018 v8::Isolate* isolate = v8::Isolate::GetCurrent();
12028 v8::Persistent<Context> env = Context::New(); 12019 v8::HandleScope outer(isolate);
12020 v8::Local<Context> env = Context::New(isolate);
12029 env->Enter(); 12021 env->Enter();
12030 12022
12031 const char* script = 12023 const char* script =
12032 "function bar() {" 12024 "function bar() {"
12033 " var sum = 0;" 12025 " var sum = 0;"
12034 " for (i = 0; i < 100; ++i)" 12026 " for (i = 0; i < 100; ++i)"
12035 " sum = foo(i);" 12027 " sum = foo(i);"
12036 " return sum;" 12028 " return sum;"
12037 "}" 12029 "}"
12038 "function foo(i) { return i * i; }"; 12030 "function foo(i) { return i * i; }";
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
12344 12336
12345 isolate->Exit(); 12337 isolate->Exit();
12346 isolate->Dispose(); 12338 isolate->Dispose();
12347 } 12339 }
12348 12340
12349 12341
12350 static int64_t cast(intptr_t x) { return static_cast<int64_t>(x); } 12342 static int64_t cast(intptr_t x) { return static_cast<int64_t>(x); }
12351 12343
12352 12344
12353 THREADED_TEST(ExternalAllocatedMemory) { 12345 THREADED_TEST(ExternalAllocatedMemory) {
12354 v8::HandleScope outer(v8::Isolate::GetCurrent()); 12346 v8::Isolate* isolate = v8::Isolate::GetCurrent();
12355 v8::Persistent<Context> env(Context::New()); 12347 v8::HandleScope outer(isolate);
12348 v8::Local<Context> env(Context::New(isolate));
12356 CHECK(!env.IsEmpty()); 12349 CHECK(!env.IsEmpty());
12357 const intptr_t kSize = 1024*1024; 12350 const intptr_t kSize = 1024*1024;
12358 v8::Isolate* isolate = env->GetIsolate();
12359 int64_t baseline = cast(isolate->AdjustAmountOfExternalAllocatedMemory(0)); 12351 int64_t baseline = cast(isolate->AdjustAmountOfExternalAllocatedMemory(0));
12360 CHECK_EQ(baseline + cast(kSize), 12352 CHECK_EQ(baseline + cast(kSize),
12361 cast(isolate->AdjustAmountOfExternalAllocatedMemory(kSize))); 12353 cast(isolate->AdjustAmountOfExternalAllocatedMemory(kSize)));
12362 CHECK_EQ(baseline, 12354 CHECK_EQ(baseline,
12363 cast(isolate->AdjustAmountOfExternalAllocatedMemory(-kSize))); 12355 cast(isolate->AdjustAmountOfExternalAllocatedMemory(-kSize)));
12364 } 12356 }
12365 12357
12366 12358
12367 THREADED_TEST(DisposeEnteredContext) { 12359 THREADED_TEST(DisposeEnteredContext) {
12368 LocalContext outer; 12360 LocalContext outer;
12369 v8::HandleScope scope(outer->GetIsolate()); 12361 v8::Isolate* isolate = outer->GetIsolate();
12370 { v8::Persistent<v8::Context> inner = v8::Context::New(); 12362 v8::Persistent<v8::Context> inner;
12363 {
12364 v8::HandleScope scope(isolate);
12365 inner.Reset(isolate, v8::Context::New(isolate));
12366 }
12367 v8::HandleScope scope(isolate);
12368 {
12371 inner->Enter(); 12369 inner->Enter();
12372 inner.Dispose(inner->GetIsolate()); 12370 inner.Dispose(inner->GetIsolate());
12373 inner.Clear(); 12371 inner.Clear();
12374 inner->Exit(); 12372 inner->Exit();
12375 } 12373 }
12376 } 12374 }
12377 12375
12378 12376
12379 // Regression test for issue 54, object templates with internal fields 12377 // Regression test for issue 54, object templates with internal fields
12380 // but no accessors or interceptors did not get their internal field 12378 // but no accessors or interceptors did not get their internal field
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
12680 context->Global()->Set(v8_str("obj_2"), instance_2); 12678 context->Global()->Set(v8_str("obj_2"), instance_2);
12681 12679
12682 Local<Value> value_2 = CompileRun("obj_2.a"); 12680 Local<Value> value_2 = CompileRun("obj_2.a");
12683 CHECK(value_2->IsUndefined()); 12681 CHECK(value_2->IsUndefined());
12684 } 12682 }
12685 12683
12686 12684
12687 // This tests that access check information remains on the global 12685 // This tests that access check information remains on the global
12688 // object template when creating contexts. 12686 // object template when creating contexts.
12689 THREADED_TEST(AccessControlRepeatedContextCreation) { 12687 THREADED_TEST(AccessControlRepeatedContextCreation) {
12690 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 12688 v8::Isolate* isolate = v8::Isolate::GetCurrent();
12689 v8::HandleScope handle_scope(isolate);
12691 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 12690 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
12692 global_template->SetAccessCheckCallbacks(NamedSetAccessBlocker, 12691 global_template->SetAccessCheckCallbacks(NamedSetAccessBlocker,
12693 IndexedSetAccessBlocker); 12692 IndexedSetAccessBlocker);
12694 i::Handle<i::ObjectTemplateInfo> internal_template = 12693 i::Handle<i::ObjectTemplateInfo> internal_template =
12695 v8::Utils::OpenHandle(*global_template); 12694 v8::Utils::OpenHandle(*global_template);
12696 CHECK(!internal_template->constructor()->IsUndefined()); 12695 CHECK(!internal_template->constructor()->IsUndefined());
12697 i::Handle<i::FunctionTemplateInfo> constructor( 12696 i::Handle<i::FunctionTemplateInfo> constructor(
12698 i::FunctionTemplateInfo::cast(internal_template->constructor())); 12697 i::FunctionTemplateInfo::cast(internal_template->constructor()));
12699 CHECK(!constructor->access_check_info()->IsUndefined()); 12698 CHECK(!constructor->access_check_info()->IsUndefined());
12700 v8::Persistent<Context> context0(Context::New(NULL, global_template)); 12699 v8::Local<Context> context0(Context::New(isolate, NULL, global_template));
12701 CHECK(!context0.IsEmpty()); 12700 CHECK(!context0.IsEmpty());
12702 CHECK(!constructor->access_check_info()->IsUndefined()); 12701 CHECK(!constructor->access_check_info()->IsUndefined());
12703 } 12702 }
12704 12703
12705 12704
12706 THREADED_TEST(TurnOnAccessCheck) { 12705 THREADED_TEST(TurnOnAccessCheck) {
12707 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 12706 v8::Isolate* isolate = v8::Isolate::GetCurrent();
12707 v8::HandleScope handle_scope(isolate);
12708 12708
12709 // Create an environment with access check to the global object disabled by 12709 // Create an environment with access check to the global object disabled by
12710 // default. 12710 // default.
12711 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 12711 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
12712 global_template->SetAccessCheckCallbacks(NamedGetAccessBlocker, 12712 global_template->SetAccessCheckCallbacks(NamedGetAccessBlocker,
12713 IndexedGetAccessBlocker, 12713 IndexedGetAccessBlocker,
12714 v8::Handle<v8::Value>(), 12714 v8::Handle<v8::Value>(),
12715 false); 12715 false);
12716 v8::Persistent<Context> context = Context::New(NULL, global_template); 12716 v8::Local<Context> context = Context::New(isolate, NULL, global_template);
12717 Context::Scope context_scope(v8::Isolate::GetCurrent(), context); 12717 Context::Scope context_scope(context);
12718 12718
12719 // Set up a property and a number of functions. 12719 // Set up a property and a number of functions.
12720 context->Global()->Set(v8_str("a"), v8_num(1)); 12720 context->Global()->Set(v8_str("a"), v8_num(1));
12721 CompileRun("function f1() {return a;}" 12721 CompileRun("function f1() {return a;}"
12722 "function f2() {return a;}" 12722 "function f2() {return a;}"
12723 "function g1() {return h();}" 12723 "function g1() {return h();}"
12724 "function g2() {return h();}" 12724 "function g2() {return h();}"
12725 "function h() {return 1;}"); 12725 "function h() {return 1;}");
12726 Local<Function> f1 = 12726 Local<Function> f1 =
12727 Local<Function>::Cast(context->Global()->Get(v8_str("f1"))); 12727 Local<Function>::Cast(context->Global()->Get(v8_str("f1")));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
12777 Local<Value> data) { 12777 Local<Value> data) {
12778 if (!name->IsString()) return false; 12778 if (!name->IsString()) return false;
12779 i::Handle<i::String> name_handle = 12779 i::Handle<i::String> name_handle =
12780 v8::Utils::OpenHandle(String::Cast(*name)); 12780 v8::Utils::OpenHandle(String::Cast(*name));
12781 return !name_handle->IsUtf8EqualTo(i::CStrVector(kPropertyA)) 12781 return !name_handle->IsUtf8EqualTo(i::CStrVector(kPropertyA))
12782 && !name_handle->IsUtf8EqualTo(i::CStrVector(kPropertyH)); 12782 && !name_handle->IsUtf8EqualTo(i::CStrVector(kPropertyH));
12783 } 12783 }
12784 12784
12785 12785
12786 THREADED_TEST(TurnOnAccessCheckAndRecompile) { 12786 THREADED_TEST(TurnOnAccessCheckAndRecompile) {
12787 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 12787 v8::Isolate* isolate = v8::Isolate::GetCurrent();
12788 v8::HandleScope handle_scope(isolate);
12788 12789
12789 // Create an environment with access check to the global object disabled by 12790 // Create an environment with access check to the global object disabled by
12790 // default. When the registered access checker will block access to properties 12791 // default. When the registered access checker will block access to properties
12791 // a and h. 12792 // a and h.
12792 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 12793 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
12793 global_template->SetAccessCheckCallbacks(NamedGetAccessBlockAandH, 12794 global_template->SetAccessCheckCallbacks(NamedGetAccessBlockAandH,
12794 IndexedGetAccessBlocker, 12795 IndexedGetAccessBlocker,
12795 v8::Handle<v8::Value>(), 12796 v8::Handle<v8::Value>(),
12796 false); 12797 false);
12797 v8::Persistent<Context> context = Context::New(NULL, global_template); 12798 v8::Local<Context> context = Context::New(isolate, NULL, global_template);
12798 Context::Scope context_scope(v8::Isolate::GetCurrent(), context); 12799 Context::Scope context_scope(context);
12799 12800
12800 // Set up a property and a number of functions. 12801 // Set up a property and a number of functions.
12801 context->Global()->Set(v8_str("a"), v8_num(1)); 12802 context->Global()->Set(v8_str("a"), v8_num(1));
12802 static const char* source = "function f1() {return a;}" 12803 static const char* source = "function f1() {return a;}"
12803 "function f2() {return a;}" 12804 "function f2() {return a;}"
12804 "function g1() {return h();}" 12805 "function g1() {return h();}"
12805 "function g2() {return h();}" 12806 "function g2() {return h();}"
12806 "function h() {return 1;}"; 12807 "function h() {return 1;}";
12807 12808
12808 CompileRun(source); 12809 CompileRun(source);
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
13046 context->Global()->Set(v8_str("tmp"), v8::True()); 13047 context->Global()->Set(v8_str("tmp"), v8::True());
13047 context->Global()->Delete(v8_str("tmp")); 13048 context->Global()->Delete(v8_str("tmp"));
13048 CompileRun("for (var j = 0; j < 10; j++) RegExp('')"); 13049 CompileRun("for (var j = 0; j < 10; j++) RegExp('')");
13049 } 13050 }
13050 } 13051 }
13051 13052
13052 13053
13053 // Test that cross-context new calls use the context of the callee to 13054 // Test that cross-context new calls use the context of the callee to
13054 // create the new JavaScript object. 13055 // create the new JavaScript object.
13055 THREADED_TEST(CrossContextNew) { 13056 THREADED_TEST(CrossContextNew) {
13056 v8::HandleScope scope(v8::Isolate::GetCurrent()); 13057 v8::Isolate* isolate = v8::Isolate::GetCurrent();
13057 v8::Persistent<Context> context0 = Context::New(); 13058 v8::HandleScope scope(isolate);
13058 v8::Persistent<Context> context1 = Context::New(); 13059 v8::Local<Context> context0 = Context::New(isolate);
13060 v8::Local<Context> context1 = Context::New(isolate);
13059 13061
13060 // Allow cross-domain access. 13062 // Allow cross-domain access.
13061 Local<String> token = v8_str("<security token>"); 13063 Local<String> token = v8_str("<security token>");
13062 context0->SetSecurityToken(token); 13064 context0->SetSecurityToken(token);
13063 context1->SetSecurityToken(token); 13065 context1->SetSecurityToken(token);
13064 13066
13065 // Set an 'x' property on the Object prototype and define a 13067 // Set an 'x' property on the Object prototype and define a
13066 // constructor function in context0. 13068 // constructor function in context0.
13067 context0->Enter(); 13069 context0->Enter();
13068 CompileRun("Object.prototype.x = 42; function C() {};"); 13070 CompileRun("Object.prototype.x = 42; function C() {};");
13069 context0->Exit(); 13071 context0->Exit();
13070 13072
13071 // Call the constructor function from context0 and check that the 13073 // Call the constructor function from context0 and check that the
13072 // result has the 'x' property. 13074 // result has the 'x' property.
13073 context1->Enter(); 13075 context1->Enter();
13074 context1->Global()->Set(v8_str("other"), context0->Global()); 13076 context1->Global()->Set(v8_str("other"), context0->Global());
13075 Local<Value> value = CompileRun("var instance = new other.C(); instance.x"); 13077 Local<Value> value = CompileRun("var instance = new other.C(); instance.x");
13076 CHECK(value->IsInt32()); 13078 CHECK(value->IsInt32());
13077 CHECK_EQ(42, value->Int32Value()); 13079 CHECK_EQ(42, value->Int32Value());
13078 context1->Exit(); 13080 context1->Exit();
13079
13080 // Dispose the contexts to allow them to be garbage collected.
13081 context0.Dispose(context0->GetIsolate());
13082 context1.Dispose(context1->GetIsolate());
13083 } 13081 }
13084 13082
13085 13083
13086 class RegExpInterruptTest { 13084 class RegExpInterruptTest {
13087 public: 13085 public:
13088 RegExpInterruptTest() : block_(NULL) {} 13086 RegExpInterruptTest() : block_(NULL) {}
13089 ~RegExpInterruptTest() { delete block_; } 13087 ~RegExpInterruptTest() { delete block_; }
13090 void RunTest() { 13088 void RunTest() {
13091 block_ = i::OS::CreateSemaphore(0); 13089 block_ = i::OS::CreateSemaphore(0);
13092 gc_count_ = 0; 13090 gc_count_ = 0;
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
13853 CHECK(context->Global()->ForceDelete(v8_str("foo"))); 13851 CHECK(context->Global()->ForceDelete(v8_str("foo")));
13854 // Make sure the value for foo is read from the prototype, and that 13852 // Make sure the value for foo is read from the prototype, and that
13855 // we don't get in trouble with reading the deleted cell value 13853 // we don't get in trouble with reading the deleted cell value
13856 // sentinel. 13854 // sentinel.
13857 CHECK_EQ(5, CompileRun("f()")->Int32Value()); 13855 CHECK_EQ(5, CompileRun("f()")->Int32Value());
13858 } 13856 }
13859 13857
13860 13858
13861 TEST(InlinedFunctionAcrossContexts) { 13859 TEST(InlinedFunctionAcrossContexts) {
13862 i::FLAG_allow_natives_syntax = true; 13860 i::FLAG_allow_natives_syntax = true;
13863 v8::HandleScope outer_scope(v8::Isolate::GetCurrent()); 13861 v8::Isolate* isolate = v8::Isolate::GetCurrent();
13864 v8::Persistent<v8::Context> ctx1 = v8::Context::New(); 13862 v8::HandleScope outer_scope(isolate);
13865 v8::Persistent<v8::Context> ctx2 = v8::Context::New(); 13863 v8::Local<v8::Context> ctx1 = v8::Context::New(isolate);
13864 v8::Local<v8::Context> ctx2 = v8::Context::New(isolate);
13866 ctx1->Enter(); 13865 ctx1->Enter();
13867 13866
13868 { 13867 {
13869 v8::HandleScope inner_scope(v8::Isolate::GetCurrent()); 13868 v8::HandleScope inner_scope(v8::Isolate::GetCurrent());
13870 CompileRun("var G = 42; function foo() { return G; }"); 13869 CompileRun("var G = 42; function foo() { return G; }");
13871 v8::Local<v8::Value> foo = ctx1->Global()->Get(v8_str("foo")); 13870 v8::Local<v8::Value> foo = ctx1->Global()->Get(v8_str("foo"));
13872 ctx2->Enter(); 13871 ctx2->Enter();
13873 ctx2->Global()->Set(v8_str("o"), foo); 13872 ctx2->Global()->Set(v8_str("o"), foo);
13874 v8::Local<v8::Value> res = CompileRun( 13873 v8::Local<v8::Value> res = CompileRun(
13875 "function f() { return o(); }" 13874 "function f() { return o(); }"
13876 "for (var i = 0; i < 10; ++i) f();" 13875 "for (var i = 0; i < 10; ++i) f();"
13877 "%OptimizeFunctionOnNextCall(f);" 13876 "%OptimizeFunctionOnNextCall(f);"
13878 "f();"); 13877 "f();");
13879 CHECK_EQ(42, res->Int32Value()); 13878 CHECK_EQ(42, res->Int32Value());
13880 ctx2->Exit(); 13879 ctx2->Exit();
13881 v8::Handle<v8::String> G_property = v8::String::New("G"); 13880 v8::Handle<v8::String> G_property = v8::String::New("G");
13882 CHECK(ctx1->Global()->ForceDelete(G_property)); 13881 CHECK(ctx1->Global()->ForceDelete(G_property));
13883 ctx2->Enter(); 13882 ctx2->Enter();
13884 ExpectString( 13883 ExpectString(
13885 "(function() {" 13884 "(function() {"
13886 " try {" 13885 " try {"
13887 " return f();" 13886 " return f();"
13888 " } catch(e) {" 13887 " } catch(e) {"
13889 " return e.toString();" 13888 " return e.toString();"
13890 " }" 13889 " }"
13891 " })()", 13890 " })()",
13892 "ReferenceError: G is not defined"); 13891 "ReferenceError: G is not defined");
13893 ctx2->Exit(); 13892 ctx2->Exit();
13894 ctx1->Exit(); 13893 ctx1->Exit();
13895 ctx1.Dispose(ctx1->GetIsolate());
13896 } 13894 }
13897 ctx2.Dispose(ctx2->GetIsolate());
13898 } 13895 }
13899 13896
13900 13897
13901 v8::Persistent<Context> calling_context0; 13898 static v8::Local<Context> calling_context0;
13902 v8::Persistent<Context> calling_context1; 13899 static v8::Local<Context> calling_context1;
13903 v8::Persistent<Context> calling_context2; 13900 static v8::Local<Context> calling_context2;
13904 13901
13905 13902
13906 // Check that the call to the callback is initiated in 13903 // Check that the call to the callback is initiated in
13907 // calling_context2, the directly calling context is calling_context1 13904 // calling_context2, the directly calling context is calling_context1
13908 // and the callback itself is in calling_context0. 13905 // and the callback itself is in calling_context0.
13909 static v8::Handle<Value> GetCallingContextCallback(const v8::Arguments& args) { 13906 static v8::Handle<Value> GetCallingContextCallback(const v8::Arguments& args) {
13910 ApiTestFuzzer::Fuzz(); 13907 ApiTestFuzzer::Fuzz();
13911 CHECK(Context::GetCurrent() == calling_context0); 13908 CHECK(Context::GetCurrent() == calling_context0);
13912 CHECK(args.GetIsolate()->GetCurrentContext() == calling_context0); 13909 CHECK(args.GetIsolate()->GetCurrentContext() == calling_context0);
13913 CHECK(Context::GetCalling() == calling_context1); 13910 CHECK(Context::GetCalling() == calling_context1);
13914 CHECK(Context::GetEntered() == calling_context2); 13911 CHECK(Context::GetEntered() == calling_context2);
13915 return v8::Integer::New(42); 13912 return v8::Integer::New(42);
13916 } 13913 }
13917 13914
13918 13915
13919 THREADED_TEST(GetCallingContext) { 13916 THREADED_TEST(GetCallingContext) {
13920 v8::HandleScope scope(v8::Isolate::GetCurrent()); 13917 v8::Isolate* isolate = v8::Isolate::GetCurrent();
13918 v8::HandleScope scope(isolate);
13921 13919
13922 calling_context0 = Context::New(); 13920 Local<Context> calling_context0(Context::New(isolate));
13923 calling_context1 = Context::New(); 13921 Local<Context> calling_context1(Context::New(isolate));
13924 calling_context2 = Context::New(); 13922 Local<Context> calling_context2(Context::New(isolate));
13923 ::calling_context0 = calling_context0;
13924 ::calling_context1 = calling_context1;
13925 ::calling_context2 = calling_context2;
13925 13926
13926 // Allow cross-domain access. 13927 // Allow cross-domain access.
13927 Local<String> token = v8_str("<security token>"); 13928 Local<String> token = v8_str("<security token>");
13928 calling_context0->SetSecurityToken(token); 13929 calling_context0->SetSecurityToken(token);
13929 calling_context1->SetSecurityToken(token); 13930 calling_context1->SetSecurityToken(token);
13930 calling_context2->SetSecurityToken(token); 13931 calling_context2->SetSecurityToken(token);
13931 13932
13932 // Create an object with a C++ callback in context0. 13933 // Create an object with a C++ callback in context0.
13933 calling_context0->Enter(); 13934 calling_context0->Enter();
13934 Local<v8::FunctionTemplate> callback_templ = 13935 Local<v8::FunctionTemplate> callback_templ =
(...skipping 10 matching lines...) Expand all
13945 CompileRun("function f() { context0.callback() }"); 13946 CompileRun("function f() { context0.callback() }");
13946 calling_context1->Exit(); 13947 calling_context1->Exit();
13947 13948
13948 // Expose context1 in context2 and call the callback function in 13949 // Expose context1 in context2 and call the callback function in
13949 // context0 indirectly through f in context1. 13950 // context0 indirectly through f in context1.
13950 calling_context2->Enter(); 13951 calling_context2->Enter();
13951 calling_context2->Global()->Set(v8_str("context1"), 13952 calling_context2->Global()->Set(v8_str("context1"),
13952 calling_context1->Global()); 13953 calling_context1->Global());
13953 CompileRun("context1.f()"); 13954 CompileRun("context1.f()");
13954 calling_context2->Exit(); 13955 calling_context2->Exit();
13955 13956 ::calling_context0.Clear();
13956 // Dispose the contexts to allow them to be garbage collected. 13957 ::calling_context1.Clear();
13957 calling_context0.Dispose(calling_context0->GetIsolate()); 13958 ::calling_context2.Clear();
13958 calling_context1.Dispose(calling_context1->GetIsolate());
13959 calling_context2.Dispose(calling_context2->GetIsolate());
13960 calling_context0.Clear();
13961 calling_context1.Clear();
13962 calling_context2.Clear();
13963 } 13959 }
13964 13960
13965 13961
13966 // Check that a variable declaration with no explicit initialization 13962 // Check that a variable declaration with no explicit initialization
13967 // value does shadow an existing property in the prototype chain. 13963 // value does shadow an existing property in the prototype chain.
13968 THREADED_TEST(InitGlobalVarInProtoChain) { 13964 THREADED_TEST(InitGlobalVarInProtoChain) {
13969 i::FLAG_es52_globals = true; 13965 i::FLAG_es52_globals = true;
13970 LocalContext context; 13966 LocalContext context;
13971 v8::HandleScope scope(context->GetIsolate()); 13967 v8::HandleScope scope(context->GetIsolate());
13972 // Introduce a variable in the prototype chain. 13968 // Introduce a variable in the prototype chain.
(...skipping 1824 matching lines...) Expand 10 before | Expand all | Expand 10 after
15797 CHECK(finished); 15793 CHECK(finished);
15798 CHECK_LT(final_size, initial_size + 1); 15794 CHECK_LT(final_size, initial_size + 1);
15799 } 15795 }
15800 15796
15801 15797
15802 TEST(Regress2107) { 15798 TEST(Regress2107) {
15803 const intptr_t MB = 1024 * 1024; 15799 const intptr_t MB = 1024 * 1024;
15804 const int kShortIdlePauseInMs = 100; 15800 const int kShortIdlePauseInMs = 100;
15805 const int kLongIdlePauseInMs = 1000; 15801 const int kLongIdlePauseInMs = 1000;
15806 LocalContext env; 15802 LocalContext env;
15803 v8::Isolate* isolate = env->GetIsolate();
15807 v8::HandleScope scope(env->GetIsolate()); 15804 v8::HandleScope scope(env->GetIsolate());
15808 intptr_t initial_size = HEAP->SizeOfObjects(); 15805 intptr_t initial_size = HEAP->SizeOfObjects();
15809 // Send idle notification to start a round of incremental GCs. 15806 // Send idle notification to start a round of incremental GCs.
15810 v8::V8::IdleNotification(kShortIdlePauseInMs); 15807 v8::V8::IdleNotification(kShortIdlePauseInMs);
15811 // Emulate 7 page reloads. 15808 // Emulate 7 page reloads.
15812 for (int i = 0; i < 7; i++) { 15809 for (int i = 0; i < 7; i++) {
15813 v8::Persistent<v8::Context> ctx = v8::Context::New(); 15810 {
15814 ctx->Enter(); 15811 v8::HandleScope inner_scope(env->GetIsolate());
15815 CreateGarbageInOldSpace(); 15812 v8::Local<v8::Context> ctx = v8::Context::New(isolate);
15816 ctx->Exit(); 15813 ctx->Enter();
15817 ctx.Dispose(ctx->GetIsolate()); 15814 CreateGarbageInOldSpace();
15815 ctx->Exit();
15816 }
15818 v8::V8::ContextDisposedNotification(); 15817 v8::V8::ContextDisposedNotification();
15819 v8::V8::IdleNotification(kLongIdlePauseInMs); 15818 v8::V8::IdleNotification(kLongIdlePauseInMs);
15820 } 15819 }
15821 // Create garbage and check that idle notification still collects it. 15820 // Create garbage and check that idle notification still collects it.
15822 CreateGarbageInOldSpace(); 15821 CreateGarbageInOldSpace();
15823 intptr_t size_with_garbage = HEAP->SizeOfObjects(); 15822 intptr_t size_with_garbage = HEAP->SizeOfObjects();
15824 CHECK_GT(size_with_garbage, initial_size + MB); 15823 CHECK_GT(size_with_garbage, initial_size + MB);
15825 bool finished = false; 15824 bool finished = false;
15826 for (int i = 0; i < 200 && !finished; i++) { 15825 for (int i = 0; i < 200 && !finished; i++) {
15827 finished = v8::V8::IdleNotification(kShortIdlePauseInMs); 15826 finished = v8::V8::IdleNotification(kShortIdlePauseInMs);
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
16136 "};" 16135 "};"
16137 "s(o);"); 16136 "s(o);");
16138 CHECK(try_catch.HasCaught()); 16137 CHECK(try_catch.HasCaught());
16139 v8::String::Utf8Value value(try_catch.Exception()); 16138 v8::String::Utf8Value value(try_catch.Exception());
16140 CHECK_EQ(0, strcmp(*value, "Hey!")); 16139 CHECK_EQ(0, strcmp(*value, "Hey!"));
16141 } 16140 }
16142 16141
16143 16142
16144 TEST(Regress528) { 16143 TEST(Regress528) {
16145 v8::V8::Initialize(); 16144 v8::V8::Initialize();
16146 16145 v8::Isolate* isolate = v8::Isolate::GetCurrent();
16147 v8::HandleScope scope(v8::Isolate::GetCurrent()); 16146 v8::HandleScope scope(isolate);
16148 v8::Persistent<Context> context; 16147 v8::Local<Context> other_context;
16149 v8::Persistent<Context> other_context;
16150 int gc_count; 16148 int gc_count;
16151 16149
16152 // Create a context used to keep the code from aging in the compilation 16150 // Create a context used to keep the code from aging in the compilation
16153 // cache. 16151 // cache.
16154 other_context = Context::New(); 16152 other_context = Context::New(isolate);
16155 16153
16156 // Context-dependent context data creates reference from the compilation 16154 // Context-dependent context data creates reference from the compilation
16157 // cache to the global object. 16155 // cache to the global object.
16158 const char* source_simple = "1"; 16156 const char* source_simple = "1";
16159 context = Context::New();
16160 { 16157 {
16161 v8::HandleScope scope(v8::Isolate::GetCurrent()); 16158 v8::HandleScope scope(isolate);
16159 v8::Local<Context> context = Context::New(isolate);
16162 16160
16163 context->Enter(); 16161 context->Enter();
16164 Local<v8::String> obj = v8::String::New(""); 16162 Local<v8::String> obj = v8::String::New("");
16165 context->SetEmbedderData(0, obj); 16163 context->SetEmbedderData(0, obj);
16166 CompileRun(source_simple); 16164 CompileRun(source_simple);
16167 context->Exit(); 16165 context->Exit();
16168 } 16166 }
16169 context.Dispose(context->GetIsolate());
16170 v8::V8::ContextDisposedNotification(); 16167 v8::V8::ContextDisposedNotification();
16171 for (gc_count = 1; gc_count < 10; gc_count++) { 16168 for (gc_count = 1; gc_count < 10; gc_count++) {
16172 other_context->Enter(); 16169 other_context->Enter();
16173 CompileRun(source_simple); 16170 CompileRun(source_simple);
16174 other_context->Exit(); 16171 other_context->Exit();
16175 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 16172 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
16176 if (GetGlobalObjectsCount() == 1) break; 16173 if (GetGlobalObjectsCount() == 1) break;
16177 } 16174 }
16178 CHECK_GE(2, gc_count); 16175 CHECK_GE(2, gc_count);
16179 CHECK_EQ(1, GetGlobalObjectsCount()); 16176 CHECK_EQ(1, GetGlobalObjectsCount());
16180 16177
16181 // Eval in a function creates reference from the compilation cache to the 16178 // Eval in a function creates reference from the compilation cache to the
16182 // global object. 16179 // global object.
16183 const char* source_eval = "function f(){eval('1')}; f()"; 16180 const char* source_eval = "function f(){eval('1')}; f()";
16184 context = Context::New();
16185 { 16181 {
16186 v8::HandleScope scope(v8::Isolate::GetCurrent()); 16182 v8::HandleScope scope(isolate);
16183 v8::Local<Context> context = Context::New(isolate);
16187 16184
16188 context->Enter(); 16185 context->Enter();
16189 CompileRun(source_eval); 16186 CompileRun(source_eval);
16190 context->Exit(); 16187 context->Exit();
16191 } 16188 }
16192 context.Dispose(context->GetIsolate());
16193 v8::V8::ContextDisposedNotification(); 16189 v8::V8::ContextDisposedNotification();
16194 for (gc_count = 1; gc_count < 10; gc_count++) { 16190 for (gc_count = 1; gc_count < 10; gc_count++) {
16195 other_context->Enter(); 16191 other_context->Enter();
16196 CompileRun(source_eval); 16192 CompileRun(source_eval);
16197 other_context->Exit(); 16193 other_context->Exit();
16198 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 16194 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
16199 if (GetGlobalObjectsCount() == 1) break; 16195 if (GetGlobalObjectsCount() == 1) break;
16200 } 16196 }
16201 CHECK_GE(2, gc_count); 16197 CHECK_GE(2, gc_count);
16202 CHECK_EQ(1, GetGlobalObjectsCount()); 16198 CHECK_EQ(1, GetGlobalObjectsCount());
16203 16199
16204 // Looking up the line number for an exception creates reference from the 16200 // Looking up the line number for an exception creates reference from the
16205 // compilation cache to the global object. 16201 // compilation cache to the global object.
16206 const char* source_exception = "function f(){throw 1;} f()"; 16202 const char* source_exception = "function f(){throw 1;} f()";
16207 context = Context::New();
16208 { 16203 {
16209 v8::HandleScope scope(v8::Isolate::GetCurrent()); 16204 v8::HandleScope scope(isolate);
16205 v8::Local<Context> context = Context::New(isolate);
16210 16206
16211 context->Enter(); 16207 context->Enter();
16212 v8::TryCatch try_catch; 16208 v8::TryCatch try_catch;
16213 CompileRun(source_exception); 16209 CompileRun(source_exception);
16214 CHECK(try_catch.HasCaught()); 16210 CHECK(try_catch.HasCaught());
16215 v8::Handle<v8::Message> message = try_catch.Message(); 16211 v8::Handle<v8::Message> message = try_catch.Message();
16216 CHECK(!message.IsEmpty()); 16212 CHECK(!message.IsEmpty());
16217 CHECK_EQ(1, message->GetLineNumber()); 16213 CHECK_EQ(1, message->GetLineNumber());
16218 context->Exit(); 16214 context->Exit();
16219 } 16215 }
16220 context.Dispose(context->GetIsolate());
16221 v8::V8::ContextDisposedNotification(); 16216 v8::V8::ContextDisposedNotification();
16222 for (gc_count = 1; gc_count < 10; gc_count++) { 16217 for (gc_count = 1; gc_count < 10; gc_count++) {
16223 other_context->Enter(); 16218 other_context->Enter();
16224 CompileRun(source_exception); 16219 CompileRun(source_exception);
16225 other_context->Exit(); 16220 other_context->Exit();
16226 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 16221 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
16227 if (GetGlobalObjectsCount() == 1) break; 16222 if (GetGlobalObjectsCount() == 1) break;
16228 } 16223 }
16229 CHECK_GE(2, gc_count); 16224 CHECK_GE(2, gc_count);
16230 CHECK_EQ(1, GetGlobalObjectsCount()); 16225 CHECK_EQ(1, GetGlobalObjectsCount());
16231 16226
16232 other_context.Dispose(other_context->GetIsolate());
16233 v8::V8::ContextDisposedNotification(); 16227 v8::V8::ContextDisposedNotification();
16234 } 16228 }
16235 16229
16236 16230
16237 THREADED_TEST(ScriptOrigin) { 16231 THREADED_TEST(ScriptOrigin) {
16238 LocalContext env; 16232 LocalContext env;
16239 v8::HandleScope scope(env->GetIsolate()); 16233 v8::HandleScope scope(env->GetIsolate());
16240 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); 16234 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test"));
16241 v8::Handle<v8::String> script = v8::String::New( 16235 v8::Handle<v8::String> script = v8::String::New(
16242 "function f() {}\n\nfunction g() {}"); 16236 "function f() {}\n\nfunction g() {}");
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
16939 // Still entered, should fail. 16933 // Still entered, should fail.
16940 isolate->Dispose(); 16934 isolate->Dispose();
16941 CHECK_NE(last_location, NULL); 16935 CHECK_NE(last_location, NULL);
16942 CHECK_NE(last_message, NULL); 16936 CHECK_NE(last_message, NULL);
16943 } 16937 }
16944 16938
16945 TEST(RunTwoIsolatesOnSingleThread) { 16939 TEST(RunTwoIsolatesOnSingleThread) {
16946 // Run isolate 1. 16940 // Run isolate 1.
16947 v8::Isolate* isolate1 = v8::Isolate::New(); 16941 v8::Isolate* isolate1 = v8::Isolate::New();
16948 isolate1->Enter(); 16942 isolate1->Enter();
16949 v8::Persistent<v8::Context> context1 = v8::Context::New(); 16943 v8::Persistent<v8::Context> context1;
16944 {
16945 v8::HandleScope scope(isolate1);
16946 context1.Reset(isolate1, Context::New(isolate1));
16947 }
16950 16948
16951 { 16949 {
16952 v8::HandleScope scope(isolate1); 16950 v8::HandleScope scope(isolate1);
16953 v8::Context::Scope cscope(isolate1, context1); 16951 v8::Context::Scope cscope(isolate1, context1);
16954 // Run something in new isolate. 16952 // Run something in new isolate.
16955 CompileRun("var foo = 'isolate 1';"); 16953 CompileRun("var foo = 'isolate 1';");
16956 ExpectString("function f() { return foo; }; f()", "isolate 1"); 16954 ExpectString("function f() { return foo; }; f()", "isolate 1");
16957 } 16955 }
16958 16956
16959 // Run isolate 2. 16957 // Run isolate 2.
16960 v8::Isolate* isolate2 = v8::Isolate::New(); 16958 v8::Isolate* isolate2 = v8::Isolate::New();
16961 v8::Persistent<v8::Context> context2; 16959 v8::Persistent<v8::Context> context2;
16962 16960
16963 { 16961 {
16964 v8::Isolate::Scope iscope(isolate2); 16962 v8::Isolate::Scope iscope(isolate2);
16965 context2 = v8::Context::New();
16966 v8::HandleScope scope(isolate2); 16963 v8::HandleScope scope(isolate2);
16964 context2.Reset(isolate2, Context::New(isolate2));
16967 v8::Context::Scope cscope(isolate2, context2); 16965 v8::Context::Scope cscope(isolate2, context2);
16968 16966
16969 // Run something in new isolate. 16967 // Run something in new isolate.
16970 CompileRun("var foo = 'isolate 2';"); 16968 CompileRun("var foo = 'isolate 2';");
16971 ExpectString("function f() { return foo; }; f()", "isolate 2"); 16969 ExpectString("function f() { return foo; }; f()", "isolate 2");
16972 } 16970 }
16973 16971
16974 { 16972 {
16975 v8::HandleScope scope(isolate1); 16973 v8::HandleScope scope(isolate1);
16976 v8::Context::Scope cscope(isolate1, context1); 16974 v8::Context::Scope cscope(isolate1, context1);
16977 // Now again in isolate 1 16975 // Now again in isolate 1
16978 ExpectString("function f() { return foo; }; f()", "isolate 1"); 16976 ExpectString("function f() { return foo; }; f()", "isolate 1");
16979 } 16977 }
16980 16978
16981 isolate1->Exit(); 16979 isolate1->Exit();
16982 16980
16983 // Run some stuff in default isolate. 16981 // Run some stuff in default isolate.
16984 v8::Persistent<v8::Context> context_default = v8::Context::New(); 16982 v8::Persistent<v8::Context> context_default;
16983 {
16984 v8::Isolate* isolate = v8::Isolate::GetCurrent();
16985 v8::Isolate::Scope iscope(isolate);
16986 v8::HandleScope scope(isolate);
16987 context_default.Reset(isolate, Context::New(isolate));
16988 }
16985 16989
16986 { 16990 {
16987 v8::HandleScope scope(v8::Isolate::GetCurrent()); 16991 v8::HandleScope scope(v8::Isolate::GetCurrent());
16988 v8::Context::Scope cscope(v8::Isolate::GetCurrent(), context_default); 16992 v8::Context::Scope cscope(v8::Isolate::GetCurrent(), context_default);
16989 // Variables in other isolates should be not available, verify there 16993 // Variables in other isolates should be not available, verify there
16990 // is an exception. 16994 // is an exception.
16991 ExpectTrue("function f() {" 16995 ExpectTrue("function f() {"
16992 " try {" 16996 " try {"
16993 " foo;" 16997 " foo;"
16994 " return false;" 16998 " return false;"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
17100 CHECK_EQ(result2, 144); 17104 CHECK_EQ(result2, 144);
17101 CHECK_EQ(result1, thread1.result()); 17105 CHECK_EQ(result1, thread1.result());
17102 CHECK_EQ(result2, thread2.result()); 17106 CHECK_EQ(result2, thread2.result());
17103 17107
17104 isolate1->Dispose(); 17108 isolate1->Dispose();
17105 isolate2->Dispose(); 17109 isolate2->Dispose();
17106 } 17110 }
17107 17111
17108 TEST(IsolateDifferentContexts) { 17112 TEST(IsolateDifferentContexts) {
17109 v8::Isolate* isolate = v8::Isolate::New(); 17113 v8::Isolate* isolate = v8::Isolate::New();
17110 Persistent<v8::Context> context; 17114 Local<v8::Context> context;
17111 { 17115 {
17112 v8::Isolate::Scope isolate_scope(isolate); 17116 v8::Isolate::Scope isolate_scope(isolate);
17113 v8::HandleScope handle_scope(isolate); 17117 v8::HandleScope handle_scope(isolate);
17114 context = v8::Context::New(); 17118 context = v8::Context::New(isolate);
17115 v8::Context::Scope context_scope(isolate, context); 17119 v8::Context::Scope context_scope(context);
17116 Local<Value> v = CompileRun("2"); 17120 Local<Value> v = CompileRun("2");
17117 CHECK(v->IsNumber()); 17121 CHECK(v->IsNumber());
17118 CHECK_EQ(2, static_cast<int>(v->NumberValue())); 17122 CHECK_EQ(2, static_cast<int>(v->NumberValue()));
17119 } 17123 }
17120 { 17124 {
17121 v8::Isolate::Scope isolate_scope(isolate); 17125 v8::Isolate::Scope isolate_scope(isolate);
17122 v8::HandleScope handle_scope(isolate); 17126 v8::HandleScope handle_scope(isolate);
17123 context = v8::Context::New(); 17127 context = v8::Context::New(isolate);
17124 v8::Context::Scope context_scope(isolate, context); 17128 v8::Context::Scope context_scope(context);
17125 Local<Value> v = CompileRun("22"); 17129 Local<Value> v = CompileRun("22");
17126 CHECK(v->IsNumber()); 17130 CHECK(v->IsNumber());
17127 CHECK_EQ(22, static_cast<int>(v->NumberValue())); 17131 CHECK_EQ(22, static_cast<int>(v->NumberValue()));
17128 } 17132 }
17129 isolate->Dispose();
17130 } 17133 }
17131 17134
17132 class InitDefaultIsolateThread : public v8::internal::Thread { 17135 class InitDefaultIsolateThread : public v8::internal::Thread {
17133 public: 17136 public:
17134 enum TestCase { 17137 enum TestCase {
17135 IgnoreOOM, 17138 IgnoreOOM,
17136 SetResourceConstraints, 17139 SetResourceConstraints,
17137 SetFatalHandler, 17140 SetFatalHandler,
17138 SetCounterFunction, 17141 SetCounterFunction,
17139 SetCreateHistogramFunction, 17142 SetCreateHistogramFunction,
(...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after
18008 char buffer[10]; 18011 char buffer[10];
18009 CHECK_EQ(10, name->ToString()->WriteUtf8(buffer)); 18012 CHECK_EQ(10, name->ToString()->WriteUtf8(buffer));
18010 return strncmp(buffer, "__proto__", 9) != 0; 18013 return strncmp(buffer, "__proto__", 9) != 0;
18011 } 18014 }
18012 18015
18013 return true; 18016 return true;
18014 } 18017 }
18015 18018
18016 18019
18017 THREADED_TEST(Regress93759) { 18020 THREADED_TEST(Regress93759) {
18018 HandleScope scope(v8::Isolate::GetCurrent()); 18021 v8::Isolate* isolate = v8::Isolate::GetCurrent();
18022 HandleScope scope(isolate);
18019 18023
18020 // Template for object with security check. 18024 // Template for object with security check.
18021 Local<ObjectTemplate> no_proto_template = v8::ObjectTemplate::New(); 18025 Local<ObjectTemplate> no_proto_template = v8::ObjectTemplate::New();
18022 // We don't do indexing, so any callback can be used for that. 18026 // We don't do indexing, so any callback can be used for that.
18023 no_proto_template->SetAccessCheckCallbacks( 18027 no_proto_template->SetAccessCheckCallbacks(
18024 BlockProtoNamedSecurityTestCallback, 18028 BlockProtoNamedSecurityTestCallback,
18025 IndexedSecurityTestCallback); 18029 IndexedSecurityTestCallback);
18026 18030
18027 // Templates for objects with hidden prototypes and possibly security check. 18031 // Templates for objects with hidden prototypes and possibly security check.
18028 Local<FunctionTemplate> hidden_proto_template = v8::FunctionTemplate::New(); 18032 Local<FunctionTemplate> hidden_proto_template = v8::FunctionTemplate::New();
18029 hidden_proto_template->SetHiddenPrototype(true); 18033 hidden_proto_template->SetHiddenPrototype(true);
18030 18034
18031 Local<FunctionTemplate> protected_hidden_proto_template = 18035 Local<FunctionTemplate> protected_hidden_proto_template =
18032 v8::FunctionTemplate::New(); 18036 v8::FunctionTemplate::New();
18033 protected_hidden_proto_template->InstanceTemplate()->SetAccessCheckCallbacks( 18037 protected_hidden_proto_template->InstanceTemplate()->SetAccessCheckCallbacks(
18034 BlockProtoNamedSecurityTestCallback, 18038 BlockProtoNamedSecurityTestCallback,
18035 IndexedSecurityTestCallback); 18039 IndexedSecurityTestCallback);
18036 protected_hidden_proto_template->SetHiddenPrototype(true); 18040 protected_hidden_proto_template->SetHiddenPrototype(true);
18037 18041
18038 // Context for "foreign" objects used in test. 18042 // Context for "foreign" objects used in test.
18039 Persistent<Context> context = v8::Context::New(); 18043 Local<Context> context = v8::Context::New(isolate);
18040 context->Enter(); 18044 context->Enter();
18041 18045
18042 // Plain object, no security check. 18046 // Plain object, no security check.
18043 Local<Object> simple_object = Object::New(); 18047 Local<Object> simple_object = Object::New();
18044 18048
18045 // Object with explicit security check. 18049 // Object with explicit security check.
18046 Local<Object> protected_object = 18050 Local<Object> protected_object =
18047 no_proto_template->NewInstance(); 18051 no_proto_template->NewInstance();
18048 18052
18049 // JSGlobalProxy object, always have security check. 18053 // JSGlobalProxy object, always have security check.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
18093 18097
18094 Local<Value> result4 = CompileRun("Object.getPrototypeOf(proxy)"); 18098 Local<Value> result4 = CompileRun("Object.getPrototypeOf(proxy)");
18095 CHECK(result4->Equals(Undefined())); 18099 CHECK(result4->Equals(Undefined()));
18096 18100
18097 Local<Value> result5 = CompileRun("Object.getPrototypeOf(hidden)"); 18101 Local<Value> result5 = CompileRun("Object.getPrototypeOf(hidden)");
18098 CHECK(result5->Equals( 18102 CHECK(result5->Equals(
18099 object_with_hidden->GetPrototype()->ToObject()->GetPrototype())); 18103 object_with_hidden->GetPrototype()->ToObject()->GetPrototype()));
18100 18104
18101 Local<Value> result6 = CompileRun("Object.getPrototypeOf(phidden)"); 18105 Local<Value> result6 = CompileRun("Object.getPrototypeOf(phidden)");
18102 CHECK(result6->Equals(Undefined())); 18106 CHECK(result6->Equals(Undefined()));
18103
18104 context.Dispose(context->GetIsolate());
18105 } 18107 }
18106 18108
18107 18109
18108 THREADED_TEST(Regress125988) { 18110 THREADED_TEST(Regress125988) {
18109 v8::HandleScope scope(v8::Isolate::GetCurrent()); 18111 v8::HandleScope scope(v8::Isolate::GetCurrent());
18110 Handle<FunctionTemplate> intercept = FunctionTemplate::New(); 18112 Handle<FunctionTemplate> intercept = FunctionTemplate::New();
18111 AddInterceptor(intercept, EmptyInterceptorGetter, EmptyInterceptorSetter); 18113 AddInterceptor(intercept, EmptyInterceptorGetter, EmptyInterceptorSetter);
18112 LocalContext env; 18114 LocalContext env;
18113 env->Global()->Set(v8_str("Intercept"), intercept->GetFunction()); 18115 env->Global()->Set(v8_str("Intercept"), intercept->GetFunction());
18114 CompileRun("var a = new Object();" 18116 CompileRun("var a = new Object();"
(...skipping 18 matching lines...) Expand all
18133 Local<Value> expected_receiver, 18135 Local<Value> expected_receiver,
18134 const char* code) { 18136 const char* code) {
18135 Local<Value> result = CompileRun(code); 18137 Local<Value> result = CompileRun(code);
18136 CHECK(result->IsObject()); 18138 CHECK(result->IsObject());
18137 CHECK(expected_receiver->Equals(result->ToObject()->Get(1))); 18139 CHECK(expected_receiver->Equals(result->ToObject()->Get(1)));
18138 CHECK(expected_result->Equals(result->ToObject()->Get(0))); 18140 CHECK(expected_result->Equals(result->ToObject()->Get(0)));
18139 } 18141 }
18140 18142
18141 18143
18142 THREADED_TEST(ForeignFunctionReceiver) { 18144 THREADED_TEST(ForeignFunctionReceiver) {
18143 HandleScope scope(v8::Isolate::GetCurrent()); 18145 v8::Isolate* isolate = v8::Isolate::GetCurrent();
18146 HandleScope scope(isolate);
18144 18147
18145 // Create two contexts with different "id" properties ('i' and 'o'). 18148 // Create two contexts with different "id" properties ('i' and 'o').
18146 // Call a function both from its own context and from a the foreign 18149 // Call a function both from its own context and from a the foreign
18147 // context, and see what "this" is bound to (returning both "this" 18150 // context, and see what "this" is bound to (returning both "this"
18148 // and "this.id" for comparison). 18151 // and "this.id" for comparison).
18149 18152
18150 Persistent<Context> foreign_context = v8::Context::New(); 18153 Local<Context> foreign_context = v8::Context::New(isolate);
18151 foreign_context->Enter(); 18154 foreign_context->Enter();
18152 Local<Value> foreign_function = 18155 Local<Value> foreign_function =
18153 CompileRun("function func() { return { 0: this.id, " 18156 CompileRun("function func() { return { 0: this.id, "
18154 " 1: this, " 18157 " 1: this, "
18155 " toString: function() { " 18158 " toString: function() { "
18156 " return this[0];" 18159 " return this[0];"
18157 " }" 18160 " }"
18158 " };" 18161 " };"
18159 "}" 18162 "}"
18160 "var id = 'i';" 18163 "var id = 'i';"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
18221 // ToString(func()) is func()[0], i.e., the returned this.id. 18224 // ToString(func()) is func()[0], i.e., the returned this.id.
18222 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/,func)[1]"))); 18225 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/,func)[1]")));
18223 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[1]"))); 18226 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[1]")));
18224 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]"))); 18227 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]")));
18225 18228
18226 // TODO(1547): Make the following also return "i". 18229 // TODO(1547): Make the following also return "i".
18227 // Calling with environment record as base. 18230 // Calling with environment record as base.
18228 TestReceiver(o, context->Global(), "func()"); 18231 TestReceiver(o, context->Global(), "func()");
18229 // Calling with no base. 18232 // Calling with no base.
18230 TestReceiver(o, context->Global(), "(1,func)()"); 18233 TestReceiver(o, context->Global(), "(1,func)()");
18231
18232 foreign_context.Dispose(foreign_context->GetIsolate());
18233 } 18234 }
18234 18235
18235 18236
18236 uint8_t callback_fired = 0; 18237 uint8_t callback_fired = 0;
18237 18238
18238 18239
18239 void CallCompletedCallback1() { 18240 void CallCompletedCallback1() {
18240 i::OS::Print("Firing callback 1.\n"); 18241 i::OS::Print("Firing callback 1.\n");
18241 callback_fired ^= 1; // Toggle first bit. 18242 callback_fired ^= 1; // Toggle first bit.
18242 } 18243 }
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
18948 i::Semaphore* sem_; 18949 i::Semaphore* sem_;
18949 volatile int sem_value_; 18950 volatile int sem_value_;
18950 }; 18951 };
18951 18952
18952 18953
18953 THREADED_TEST(SemaphoreInterruption) { 18954 THREADED_TEST(SemaphoreInterruption) {
18954 ThreadInterruptTest().RunTest(); 18955 ThreadInterruptTest().RunTest();
18955 } 18956 }
18956 18957
18957 #endif // WIN32 18958 #endif // WIN32
OLDNEW
« no previous file with comments | « test/cctest/cctest.h ('k') | test/cctest/test-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698