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

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

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