OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1182 THREADED_TEST(GlobalPrototype) { | 1182 THREADED_TEST(GlobalPrototype) { |
1183 v8::HandleScope scope; | 1183 v8::HandleScope scope; |
1184 v8::Handle<v8::FunctionTemplate> func_templ = v8::FunctionTemplate::New(); | 1184 v8::Handle<v8::FunctionTemplate> func_templ = v8::FunctionTemplate::New(); |
1185 func_templ->PrototypeTemplate()->Set( | 1185 func_templ->PrototypeTemplate()->Set( |
1186 "dummy", | 1186 "dummy", |
1187 v8::FunctionTemplate::New(DummyCallHandler)); | 1187 v8::FunctionTemplate::New(DummyCallHandler)); |
1188 v8::Handle<ObjectTemplate> templ = func_templ->InstanceTemplate(); | 1188 v8::Handle<ObjectTemplate> templ = func_templ->InstanceTemplate(); |
1189 templ->Set("x", v8_num(200)); | 1189 templ->Set("x", v8_num(200)); |
1190 templ->SetAccessor(v8_str("m"), GetM); | 1190 templ->SetAccessor(v8_str("m"), GetM); |
1191 LocalContext env(0, templ); | 1191 LocalContext env(0, templ); |
1192 v8::Handle<v8::Object> obj(env->Global()); | |
1193 v8::Handle<Script> script(v8_compile("dummy()")); | 1192 v8::Handle<Script> script(v8_compile("dummy()")); |
1194 v8::Handle<Value> result(script->Run()); | 1193 v8::Handle<Value> result(script->Run()); |
1195 CHECK_EQ(13.4, result->NumberValue()); | 1194 CHECK_EQ(13.4, result->NumberValue()); |
1196 CHECK_EQ(200, v8_compile("x")->Run()->Int32Value()); | 1195 CHECK_EQ(200, v8_compile("x")->Run()->Int32Value()); |
1197 CHECK_EQ(876, v8_compile("m")->Run()->Int32Value()); | 1196 CHECK_EQ(876, v8_compile("m")->Run()->Int32Value()); |
1198 } | 1197 } |
1199 | 1198 |
1200 | 1199 |
1201 THREADED_TEST(ObjectTemplate) { | 1200 THREADED_TEST(ObjectTemplate) { |
1202 v8::HandleScope scope; | 1201 v8::HandleScope scope; |
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1840 v8::HandleScope scope; | 1839 v8::HandleScope scope; |
1841 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(); | 1840 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(); |
1842 global->Set(v8_str("callScriptRecursively"), | 1841 global->Set(v8_str("callScriptRecursively"), |
1843 v8::FunctionTemplate::New(CallScriptRecursivelyCall)); | 1842 v8::FunctionTemplate::New(CallScriptRecursivelyCall)); |
1844 global->Set(v8_str("callFunctionRecursively"), | 1843 global->Set(v8_str("callFunctionRecursively"), |
1845 v8::FunctionTemplate::New(CallFunctionRecursivelyCall)); | 1844 v8::FunctionTemplate::New(CallFunctionRecursivelyCall)); |
1846 LocalContext env(NULL, global); | 1845 LocalContext env(NULL, global); |
1847 | 1846 |
1848 env->Global()->Set(v8_str("depth"), v8::Integer::New(0)); | 1847 env->Global()->Set(v8_str("depth"), v8::Integer::New(0)); |
1849 call_recursively_script = v8_compile("callScriptRecursively()"); | 1848 call_recursively_script = v8_compile("callScriptRecursively()"); |
1850 v8::Handle<Value> result(call_recursively_script->Run()); | 1849 call_recursively_script->Run(); |
1851 call_recursively_script = v8::Handle<Script>(); | 1850 call_recursively_script = v8::Handle<Script>(); |
1852 | 1851 |
1853 env->Global()->Set(v8_str("depth"), v8::Integer::New(0)); | 1852 env->Global()->Set(v8_str("depth"), v8::Integer::New(0)); |
1854 Script::Compile(v8_str("callFunctionRecursively()"))->Run(); | 1853 Script::Compile(v8_str("callFunctionRecursively()"))->Run(); |
1855 } | 1854 } |
1856 | 1855 |
1857 | 1856 |
1858 static v8::Handle<Value> | 1857 static v8::Handle<Value> |
1859 ThrowingPropertyHandlerGet(Local<String> key, const AccessorInfo&) { | 1858 ThrowingPropertyHandlerGet(Local<String> key, const AccessorInfo&) { |
1860 ApiTestFuzzer::Fuzz(); | 1859 ApiTestFuzzer::Fuzz(); |
(...skipping 2608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4469 | 4468 |
4470 ExpectBoolean("Object.isExtensible(undetectable)", true); | 4469 ExpectBoolean("Object.isExtensible(undetectable)", true); |
4471 | 4470 |
4472 source = v8_str("Object.preventExtensions(undetectable);"); | 4471 source = v8_str("Object.preventExtensions(undetectable);"); |
4473 script = Script::Compile(source); | 4472 script = Script::Compile(source); |
4474 script->Run(); | 4473 script->Run(); |
4475 ExpectBoolean("Object.isExtensible(undetectable)", false); | 4474 ExpectBoolean("Object.isExtensible(undetectable)", false); |
4476 | 4475 |
4477 source = v8_str("undetectable.y = 2000;"); | 4476 source = v8_str("undetectable.y = 2000;"); |
4478 script = Script::Compile(source); | 4477 script = Script::Compile(source); |
4479 Local<Value> result(script->Run()); | 4478 script->Run(); |
4480 ExpectBoolean("undetectable.y == undefined", true); | 4479 ExpectBoolean("undetectable.y == undefined", true); |
4481 } | 4480 } |
4482 | 4481 |
4483 | 4482 |
4484 | 4483 |
4485 THREADED_TEST(UndetectableString) { | 4484 THREADED_TEST(UndetectableString) { |
4486 v8::HandleScope scope; | 4485 v8::HandleScope scope; |
4487 LocalContext env; | 4486 LocalContext env; |
4488 | 4487 |
4489 Local<String> obj = String::NewUndetectable("foo"); | 4488 Local<String> obj = String::NewUndetectable("foo"); |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4822 | 4821 |
4823 THREADED_TEST(NativeFunctionDeclarationError) { | 4822 THREADED_TEST(NativeFunctionDeclarationError) { |
4824 v8::HandleScope handle_scope; | 4823 v8::HandleScope handle_scope; |
4825 const char* name = "nativedeclerr"; | 4824 const char* name = "nativedeclerr"; |
4826 // Syntax error in extension code. | 4825 // Syntax error in extension code. |
4827 v8::RegisterExtension(new NativeFunctionExtension(name, | 4826 v8::RegisterExtension(new NativeFunctionExtension(name, |
4828 "native\nfunction foo();")); | 4827 "native\nfunction foo();")); |
4829 const char* extension_names[] = { name }; | 4828 const char* extension_names[] = { name }; |
4830 v8::ExtensionConfiguration extensions(1, extension_names); | 4829 v8::ExtensionConfiguration extensions(1, extension_names); |
4831 v8::Handle<Context> context(Context::New(&extensions)); | 4830 v8::Handle<Context> context(Context::New(&extensions)); |
4832 ASSERT(context.IsEmpty()); | 4831 CHECK(context.IsEmpty()); |
4833 } | 4832 } |
4834 | 4833 |
| 4834 |
4835 THREADED_TEST(NativeFunctionDeclarationErrorEscape) { | 4835 THREADED_TEST(NativeFunctionDeclarationErrorEscape) { |
4836 v8::HandleScope handle_scope; | 4836 v8::HandleScope handle_scope; |
4837 const char* name = "nativedeclerresc"; | 4837 const char* name = "nativedeclerresc"; |
4838 // Syntax error in extension code - escape code in "native" means that | 4838 // Syntax error in extension code - escape code in "native" means that |
4839 // it's not treated as a keyword. | 4839 // it's not treated as a keyword. |
4840 v8::RegisterExtension(new NativeFunctionExtension( | 4840 v8::RegisterExtension(new NativeFunctionExtension( |
4841 name, | 4841 name, |
4842 "nativ\\u0065 function foo();")); | 4842 "nativ\\u0065 function foo();")); |
4843 const char* extension_names[] = { name }; | 4843 const char* extension_names[] = { name }; |
4844 v8::ExtensionConfiguration extensions(1, extension_names); | 4844 v8::ExtensionConfiguration extensions(1, extension_names); |
4845 v8::Handle<Context> context(Context::New(&extensions)); | 4845 v8::Handle<Context> context(Context::New(&extensions)); |
4846 ASSERT(context.IsEmpty()); | 4846 CHECK(context.IsEmpty()); |
4847 } | 4847 } |
4848 | 4848 |
4849 | 4849 |
4850 static void CheckDependencies(const char* name, const char* expected) { | 4850 static void CheckDependencies(const char* name, const char* expected) { |
4851 v8::HandleScope handle_scope; | 4851 v8::HandleScope handle_scope; |
4852 v8::ExtensionConfiguration config(1, &name); | 4852 v8::ExtensionConfiguration config(1, &name); |
4853 LocalContext context(&config); | 4853 LocalContext context(&config); |
4854 CHECK_EQ(String::New(expected), context->Global()->Get(v8_str("loaded"))); | 4854 CHECK_EQ(String::New(expected), context->Global()->Get(v8_str("loaded"))); |
4855 } | 4855 } |
4856 | 4856 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5002 | 5002 |
5003 | 5003 |
5004 TEST(RegexpOutOfMemory) { | 5004 TEST(RegexpOutOfMemory) { |
5005 // Execute a script that causes out of memory when flattening a string. | 5005 // Execute a script that causes out of memory when flattening a string. |
5006 v8::HandleScope scope; | 5006 v8::HandleScope scope; |
5007 v8::V8::SetFatalErrorHandler(OOMCallback); | 5007 v8::V8::SetFatalErrorHandler(OOMCallback); |
5008 LocalContext context; | 5008 LocalContext context; |
5009 Local<Script> script = | 5009 Local<Script> script = |
5010 Script::Compile(String::New(js_code_causing_huge_string_flattening)); | 5010 Script::Compile(String::New(js_code_causing_huge_string_flattening)); |
5011 last_location = NULL; | 5011 last_location = NULL; |
5012 Local<Value> result(script->Run()); | 5012 script->Run(); |
5013 | 5013 |
5014 CHECK(false); // Should not return. | 5014 CHECK(false); // Should not return. |
5015 } | 5015 } |
5016 | 5016 |
5017 | 5017 |
5018 static void MissingScriptInfoMessageListener(v8::Handle<v8::Message> message, | 5018 static void MissingScriptInfoMessageListener(v8::Handle<v8::Message> message, |
5019 v8::Handle<Value> data) { | 5019 v8::Handle<Value> data) { |
5020 CHECK_EQ(v8::Undefined(), data); | 5020 CHECK_EQ(v8::Undefined(), data); |
5021 CHECK(message->GetScriptResourceName()->IsUndefined()); | 5021 CHECK(message->GetScriptResourceName()->IsUndefined()); |
5022 CHECK_EQ(v8::Undefined(), message->GetScriptResourceName()); | 5022 CHECK_EQ(v8::Undefined(), message->GetScriptResourceName()); |
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5780 | 5780 |
5781 | 5781 |
5782 THREADED_TEST(ErrorConstruction) { | 5782 THREADED_TEST(ErrorConstruction) { |
5783 v8::HandleScope scope; | 5783 v8::HandleScope scope; |
5784 LocalContext context; | 5784 LocalContext context; |
5785 | 5785 |
5786 v8::Handle<String> foo = v8_str("foo"); | 5786 v8::Handle<String> foo = v8_str("foo"); |
5787 v8::Handle<String> message = v8_str("message"); | 5787 v8::Handle<String> message = v8_str("message"); |
5788 v8::Handle<Value> range_error = v8::Exception::RangeError(foo); | 5788 v8::Handle<Value> range_error = v8::Exception::RangeError(foo); |
5789 CHECK(range_error->IsObject()); | 5789 CHECK(range_error->IsObject()); |
5790 v8::Handle<v8::Object> range_obj(range_error.As<v8::Object>()); | |
5791 CHECK(range_error.As<v8::Object>()->Get(message)->Equals(foo)); | 5790 CHECK(range_error.As<v8::Object>()->Get(message)->Equals(foo)); |
5792 v8::Handle<Value> reference_error = v8::Exception::ReferenceError(foo); | 5791 v8::Handle<Value> reference_error = v8::Exception::ReferenceError(foo); |
5793 CHECK(reference_error->IsObject()); | 5792 CHECK(reference_error->IsObject()); |
5794 CHECK(reference_error.As<v8::Object>()->Get(message)->Equals(foo)); | 5793 CHECK(reference_error.As<v8::Object>()->Get(message)->Equals(foo)); |
5795 v8::Handle<Value> syntax_error = v8::Exception::SyntaxError(foo); | 5794 v8::Handle<Value> syntax_error = v8::Exception::SyntaxError(foo); |
5796 CHECK(syntax_error->IsObject()); | 5795 CHECK(syntax_error->IsObject()); |
5797 CHECK(syntax_error.As<v8::Object>()->Get(message)->Equals(foo)); | 5796 CHECK(syntax_error.As<v8::Object>()->Get(message)->Equals(foo)); |
5798 v8::Handle<Value> type_error = v8::Exception::TypeError(foo); | 5797 v8::Handle<Value> type_error = v8::Exception::TypeError(foo); |
5799 CHECK(type_error->IsObject()); | 5798 CHECK(type_error->IsObject()); |
5800 CHECK(type_error.As<v8::Object>()->Get(message)->Equals(foo)); | 5799 CHECK(type_error.As<v8::Object>()->Get(message)->Equals(foo)); |
(...skipping 1549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7350 // Hold on to the global object so it can be used again in another | 7349 // Hold on to the global object so it can be used again in another |
7351 // environment initialization. | 7350 // environment initialization. |
7352 global_object = env->Global(); | 7351 global_object = env->Global(); |
7353 foo = Script::Compile(v8_str(script))->Run(); | 7352 foo = Script::Compile(v8_str(script))->Run(); |
7354 } | 7353 } |
7355 | 7354 |
7356 { | 7355 { |
7357 // Create new environment reusing the global object. | 7356 // Create new environment reusing the global object. |
7358 LocalContext env(NULL, instance_template, global_object); | 7357 LocalContext env(NULL, instance_template, global_object); |
7359 env->Global()->Set(v8_str("foo"), foo); | 7358 env->Global()->Set(v8_str("foo"), foo); |
7360 Local<Value> value(Script::Compile(v8_str("foo()"))->Run()); | 7359 Script::Compile(v8_str("foo()"))->Run(); |
7361 } | 7360 } |
7362 } | 7361 } |
7363 | 7362 |
7364 | 7363 |
7365 static v8::Handle<Value> ShadowFunctionCallback(const v8::Arguments& args) { | 7364 static v8::Handle<Value> ShadowFunctionCallback(const v8::Arguments& args) { |
7366 ApiTestFuzzer::Fuzz(); | 7365 ApiTestFuzzer::Fuzz(); |
7367 return v8_num(42); | 7366 return v8_num(42); |
7368 } | 7367 } |
7369 | 7368 |
7370 | 7369 |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7676 | 7675 |
7677 THREADED_TEST(Constructor) { | 7676 THREADED_TEST(Constructor) { |
7678 v8::HandleScope handle_scope; | 7677 v8::HandleScope handle_scope; |
7679 LocalContext context; | 7678 LocalContext context; |
7680 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); | 7679 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); |
7681 templ->SetClassName(v8_str("Fun")); | 7680 templ->SetClassName(v8_str("Fun")); |
7682 Local<Function> cons = templ->GetFunction(); | 7681 Local<Function> cons = templ->GetFunction(); |
7683 context->Global()->Set(v8_str("Fun"), cons); | 7682 context->Global()->Set(v8_str("Fun"), cons); |
7684 Local<v8::Object> inst = cons->NewInstance(); | 7683 Local<v8::Object> inst = cons->NewInstance(); |
7685 i::Handle<i::JSObject> obj(v8::Utils::OpenHandle(*inst)); | 7684 i::Handle<i::JSObject> obj(v8::Utils::OpenHandle(*inst)); |
| 7685 CHECK(obj->IsJSObject()); |
7686 Local<Value> value = CompileRun("(new Fun()).constructor === Fun"); | 7686 Local<Value> value = CompileRun("(new Fun()).constructor === Fun"); |
7687 CHECK(value->BooleanValue()); | 7687 CHECK(value->BooleanValue()); |
7688 } | 7688 } |
7689 | 7689 |
7690 | 7690 |
7691 static Handle<Value> ConstructorCallback(const Arguments& args) { | 7691 static Handle<Value> ConstructorCallback(const Arguments& args) { |
7692 ApiTestFuzzer::Fuzz(); | 7692 ApiTestFuzzer::Fuzz(); |
7693 Local<Object> This; | 7693 Local<Object> This; |
7694 | 7694 |
7695 if (args.IsConstructCall()) { | 7695 if (args.IsConstructCall()) { |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8147 // Check that the call-as-function handler can be called through | 8147 // Check that the call-as-function handler can be called through |
8148 // the API. | 8148 // the API. |
8149 v8::Handle<Value> args[] = { v8_num(28) }; | 8149 v8::Handle<Value> args[] = { v8_num(28) }; |
8150 value = instance->CallAsFunction(instance, 1, args); | 8150 value = instance->CallAsFunction(instance, 1, args); |
8151 CHECK(!try_catch.HasCaught()); | 8151 CHECK(!try_catch.HasCaught()); |
8152 CHECK_EQ(28, value->Int32Value()); | 8152 CHECK_EQ(28, value->Int32Value()); |
8153 } | 8153 } |
8154 | 8154 |
8155 { Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); | 8155 { Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); |
8156 Local<ObjectTemplate> instance_template(t->InstanceTemplate()); | 8156 Local<ObjectTemplate> instance_template(t->InstanceTemplate()); |
| 8157 USE(instance_template); |
8157 Local<v8::Object> instance = t->GetFunction()->NewInstance(); | 8158 Local<v8::Object> instance = t->GetFunction()->NewInstance(); |
8158 context->Global()->Set(v8_str("obj2"), instance); | 8159 context->Global()->Set(v8_str("obj2"), instance); |
8159 v8::TryCatch try_catch; | 8160 v8::TryCatch try_catch; |
8160 Local<Value> value; | 8161 Local<Value> value; |
8161 CHECK(!try_catch.HasCaught()); | 8162 CHECK(!try_catch.HasCaught()); |
8162 | 8163 |
8163 // Call an object without call-as-function handler through the JS | 8164 // Call an object without call-as-function handler through the JS |
8164 value = CompileRun("obj2(28)"); | 8165 value = CompileRun("obj2(28)"); |
8165 CHECK(value.IsEmpty()); | 8166 CHECK(value.IsEmpty()); |
8166 CHECK(try_catch.HasCaught()); | 8167 CHECK(try_catch.HasCaught()); |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8776 | 8777 |
8777 // This test should hit the store IC for the interceptor case. | 8778 // This test should hit the store IC for the interceptor case. |
8778 THREADED_TEST(InterceptorStoreIC) { | 8779 THREADED_TEST(InterceptorStoreIC) { |
8779 v8::HandleScope scope; | 8780 v8::HandleScope scope; |
8780 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | 8781 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); |
8781 templ->SetNamedPropertyHandler(InterceptorLoadICGetter, | 8782 templ->SetNamedPropertyHandler(InterceptorLoadICGetter, |
8782 InterceptorStoreICSetter, | 8783 InterceptorStoreICSetter, |
8783 0, 0, 0, v8_str("data")); | 8784 0, 0, 0, v8_str("data")); |
8784 LocalContext context; | 8785 LocalContext context; |
8785 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 8786 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
8786 v8::Handle<Value> value(CompileRun( | 8787 CompileRun( |
8787 "for (var i = 0; i < 1000; i++) {" | 8788 "for (var i = 0; i < 1000; i++) {" |
8788 " o.x = 42;" | 8789 " o.x = 42;" |
8789 "}")); | 8790 "}"); |
8790 } | 8791 } |
8791 | 8792 |
8792 | 8793 |
8793 THREADED_TEST(InterceptorStoreICWithNoSetter) { | 8794 THREADED_TEST(InterceptorStoreICWithNoSetter) { |
8794 v8::HandleScope scope; | 8795 v8::HandleScope scope; |
8795 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | 8796 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); |
8796 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); | 8797 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); |
8797 LocalContext context; | 8798 LocalContext context; |
8798 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 8799 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
8799 v8::Handle<Value> value = CompileRun( | 8800 v8::Handle<Value> value = CompileRun( |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9247 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 9248 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
9248 proto_templ->Set(v8_str("method"), method_templ); | 9249 proto_templ->Set(v8_str("method"), method_templ); |
9249 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 9250 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
9250 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, | 9251 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, |
9251 NULL, NULL, NULL, NULL, | 9252 NULL, NULL, NULL, NULL, |
9252 v8::External::Wrap(&interceptor_call_count)); | 9253 v8::External::Wrap(&interceptor_call_count)); |
9253 LocalContext context; | 9254 LocalContext context; |
9254 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 9255 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
9255 GenerateSomeGarbage(); | 9256 GenerateSomeGarbage(); |
9256 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 9257 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
9257 v8::Handle<Value> value(CompileRun( | 9258 CompileRun( |
9258 "var result = 0;" | 9259 "var result = 0;" |
9259 "for (var i = 0; i < 100; i++) {" | 9260 "for (var i = 0; i < 100; i++) {" |
9260 " result = o.method(41);" | 9261 " result = o.method(41);" |
9261 "}")); | 9262 "}"); |
9262 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); | 9263 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); |
9263 CHECK_EQ(100, interceptor_call_count); | 9264 CHECK_EQ(100, interceptor_call_count); |
9264 } | 9265 } |
9265 | 9266 |
9266 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature) { | 9267 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature) { |
9267 int interceptor_call_count = 0; | 9268 int interceptor_call_count = 0; |
9268 v8::HandleScope scope; | 9269 v8::HandleScope scope; |
9269 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 9270 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
9270 v8::Handle<v8::FunctionTemplate> method_templ = | 9271 v8::Handle<v8::FunctionTemplate> method_templ = |
9271 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, | 9272 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, |
9272 v8_str("method_data"), | 9273 v8_str("method_data"), |
9273 v8::Signature::New(fun_templ)); | 9274 v8::Signature::New(fun_templ)); |
9274 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 9275 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
9275 proto_templ->Set(v8_str("method"), method_templ); | 9276 proto_templ->Set(v8_str("method"), method_templ); |
9276 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 9277 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
9277 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, | 9278 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, |
9278 NULL, NULL, NULL, NULL, | 9279 NULL, NULL, NULL, NULL, |
9279 v8::External::Wrap(&interceptor_call_count)); | 9280 v8::External::Wrap(&interceptor_call_count)); |
9280 LocalContext context; | 9281 LocalContext context; |
9281 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 9282 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
9282 GenerateSomeGarbage(); | 9283 GenerateSomeGarbage(); |
9283 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 9284 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
9284 v8::Handle<Value> value(CompileRun( | 9285 CompileRun( |
9285 "o.foo = 17;" | 9286 "o.foo = 17;" |
9286 "var receiver = {};" | 9287 "var receiver = {};" |
9287 "receiver.__proto__ = o;" | 9288 "receiver.__proto__ = o;" |
9288 "var result = 0;" | 9289 "var result = 0;" |
9289 "for (var i = 0; i < 100; i++) {" | 9290 "for (var i = 0; i < 100; i++) {" |
9290 " result = receiver.method(41);" | 9291 " result = receiver.method(41);" |
9291 "}")); | 9292 "}"); |
9292 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); | 9293 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); |
9293 CHECK_EQ(100, interceptor_call_count); | 9294 CHECK_EQ(100, interceptor_call_count); |
9294 } | 9295 } |
9295 | 9296 |
9296 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss1) { | 9297 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss1) { |
9297 int interceptor_call_count = 0; | 9298 int interceptor_call_count = 0; |
9298 v8::HandleScope scope; | 9299 v8::HandleScope scope; |
9299 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 9300 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
9300 v8::Handle<v8::FunctionTemplate> method_templ = | 9301 v8::Handle<v8::FunctionTemplate> method_templ = |
9301 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, | 9302 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, |
9302 v8_str("method_data"), | 9303 v8_str("method_data"), |
9303 v8::Signature::New(fun_templ)); | 9304 v8::Signature::New(fun_templ)); |
9304 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 9305 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
9305 proto_templ->Set(v8_str("method"), method_templ); | 9306 proto_templ->Set(v8_str("method"), method_templ); |
9306 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 9307 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
9307 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, | 9308 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, |
9308 NULL, NULL, NULL, NULL, | 9309 NULL, NULL, NULL, NULL, |
9309 v8::External::Wrap(&interceptor_call_count)); | 9310 v8::External::Wrap(&interceptor_call_count)); |
9310 LocalContext context; | 9311 LocalContext context; |
9311 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 9312 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
9312 GenerateSomeGarbage(); | 9313 GenerateSomeGarbage(); |
9313 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 9314 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
9314 v8::Handle<Value> value(CompileRun( | 9315 CompileRun( |
9315 "o.foo = 17;" | 9316 "o.foo = 17;" |
9316 "var receiver = {};" | 9317 "var receiver = {};" |
9317 "receiver.__proto__ = o;" | 9318 "receiver.__proto__ = o;" |
9318 "var result = 0;" | 9319 "var result = 0;" |
9319 "var saved_result = 0;" | 9320 "var saved_result = 0;" |
9320 "for (var i = 0; i < 100; i++) {" | 9321 "for (var i = 0; i < 100; i++) {" |
9321 " result = receiver.method(41);" | 9322 " result = receiver.method(41);" |
9322 " if (i == 50) {" | 9323 " if (i == 50) {" |
9323 " saved_result = result;" | 9324 " saved_result = result;" |
9324 " receiver = {method: function(x) { return x - 1 }};" | 9325 " receiver = {method: function(x) { return x - 1 }};" |
9325 " }" | 9326 " }" |
9326 "}")); | 9327 "}"); |
9327 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); | 9328 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); |
9328 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 9329 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); |
9329 CHECK_GE(interceptor_call_count, 50); | 9330 CHECK_GE(interceptor_call_count, 50); |
9330 } | 9331 } |
9331 | 9332 |
9332 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss2) { | 9333 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss2) { |
9333 int interceptor_call_count = 0; | 9334 int interceptor_call_count = 0; |
9334 v8::HandleScope scope; | 9335 v8::HandleScope scope; |
9335 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 9336 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
9336 v8::Handle<v8::FunctionTemplate> method_templ = | 9337 v8::Handle<v8::FunctionTemplate> method_templ = |
9337 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, | 9338 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, |
9338 v8_str("method_data"), | 9339 v8_str("method_data"), |
9339 v8::Signature::New(fun_templ)); | 9340 v8::Signature::New(fun_templ)); |
9340 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 9341 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
9341 proto_templ->Set(v8_str("method"), method_templ); | 9342 proto_templ->Set(v8_str("method"), method_templ); |
9342 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 9343 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
9343 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, | 9344 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, |
9344 NULL, NULL, NULL, NULL, | 9345 NULL, NULL, NULL, NULL, |
9345 v8::External::Wrap(&interceptor_call_count)); | 9346 v8::External::Wrap(&interceptor_call_count)); |
9346 LocalContext context; | 9347 LocalContext context; |
9347 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 9348 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
9348 GenerateSomeGarbage(); | 9349 GenerateSomeGarbage(); |
9349 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 9350 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
9350 v8::Handle<Value> value(CompileRun( | 9351 CompileRun( |
9351 "o.foo = 17;" | 9352 "o.foo = 17;" |
9352 "var receiver = {};" | 9353 "var receiver = {};" |
9353 "receiver.__proto__ = o;" | 9354 "receiver.__proto__ = o;" |
9354 "var result = 0;" | 9355 "var result = 0;" |
9355 "var saved_result = 0;" | 9356 "var saved_result = 0;" |
9356 "for (var i = 0; i < 100; i++) {" | 9357 "for (var i = 0; i < 100; i++) {" |
9357 " result = receiver.method(41);" | 9358 " result = receiver.method(41);" |
9358 " if (i == 50) {" | 9359 " if (i == 50) {" |
9359 " saved_result = result;" | 9360 " saved_result = result;" |
9360 " o.method = function(x) { return x - 1 };" | 9361 " o.method = function(x) { return x - 1 };" |
9361 " }" | 9362 " }" |
9362 "}")); | 9363 "}"); |
9363 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); | 9364 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); |
9364 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 9365 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); |
9365 CHECK_GE(interceptor_call_count, 50); | 9366 CHECK_GE(interceptor_call_count, 50); |
9366 } | 9367 } |
9367 | 9368 |
9368 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss3) { | 9369 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss3) { |
9369 int interceptor_call_count = 0; | 9370 int interceptor_call_count = 0; |
9370 v8::HandleScope scope; | 9371 v8::HandleScope scope; |
9371 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 9372 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
9372 v8::Handle<v8::FunctionTemplate> method_templ = | 9373 v8::Handle<v8::FunctionTemplate> method_templ = |
9373 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, | 9374 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, |
9374 v8_str("method_data"), | 9375 v8_str("method_data"), |
9375 v8::Signature::New(fun_templ)); | 9376 v8::Signature::New(fun_templ)); |
9376 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 9377 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
9377 proto_templ->Set(v8_str("method"), method_templ); | 9378 proto_templ->Set(v8_str("method"), method_templ); |
9378 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 9379 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
9379 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, | 9380 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, |
9380 NULL, NULL, NULL, NULL, | 9381 NULL, NULL, NULL, NULL, |
9381 v8::External::Wrap(&interceptor_call_count)); | 9382 v8::External::Wrap(&interceptor_call_count)); |
9382 LocalContext context; | 9383 LocalContext context; |
9383 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 9384 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
9384 GenerateSomeGarbage(); | 9385 GenerateSomeGarbage(); |
9385 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 9386 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
9386 v8::TryCatch try_catch; | 9387 v8::TryCatch try_catch; |
9387 v8::Handle<Value> value(CompileRun( | 9388 CompileRun( |
9388 "o.foo = 17;" | 9389 "o.foo = 17;" |
9389 "var receiver = {};" | 9390 "var receiver = {};" |
9390 "receiver.__proto__ = o;" | 9391 "receiver.__proto__ = o;" |
9391 "var result = 0;" | 9392 "var result = 0;" |
9392 "var saved_result = 0;" | 9393 "var saved_result = 0;" |
9393 "for (var i = 0; i < 100; i++) {" | 9394 "for (var i = 0; i < 100; i++) {" |
9394 " result = receiver.method(41);" | 9395 " result = receiver.method(41);" |
9395 " if (i == 50) {" | 9396 " if (i == 50) {" |
9396 " saved_result = result;" | 9397 " saved_result = result;" |
9397 " receiver = 333;" | 9398 " receiver = 333;" |
9398 " }" | 9399 " }" |
9399 "}")); | 9400 "}"); |
9400 CHECK(try_catch.HasCaught()); | 9401 CHECK(try_catch.HasCaught()); |
9401 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"), | 9402 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"), |
9402 try_catch.Exception()->ToString()); | 9403 try_catch.Exception()->ToString()); |
9403 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 9404 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); |
9404 CHECK_GE(interceptor_call_count, 50); | 9405 CHECK_GE(interceptor_call_count, 50); |
9405 } | 9406 } |
9406 | 9407 |
9407 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_TypeError) { | 9408 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_TypeError) { |
9408 int interceptor_call_count = 0; | 9409 int interceptor_call_count = 0; |
9409 v8::HandleScope scope; | 9410 v8::HandleScope scope; |
9410 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 9411 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
9411 v8::Handle<v8::FunctionTemplate> method_templ = | 9412 v8::Handle<v8::FunctionTemplate> method_templ = |
9412 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, | 9413 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, |
9413 v8_str("method_data"), | 9414 v8_str("method_data"), |
9414 v8::Signature::New(fun_templ)); | 9415 v8::Signature::New(fun_templ)); |
9415 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 9416 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
9416 proto_templ->Set(v8_str("method"), method_templ); | 9417 proto_templ->Set(v8_str("method"), method_templ); |
9417 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 9418 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
9418 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, | 9419 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, |
9419 NULL, NULL, NULL, NULL, | 9420 NULL, NULL, NULL, NULL, |
9420 v8::External::Wrap(&interceptor_call_count)); | 9421 v8::External::Wrap(&interceptor_call_count)); |
9421 LocalContext context; | 9422 LocalContext context; |
9422 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 9423 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
9423 GenerateSomeGarbage(); | 9424 GenerateSomeGarbage(); |
9424 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 9425 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
9425 v8::TryCatch try_catch; | 9426 v8::TryCatch try_catch; |
9426 v8::Handle<Value> value(CompileRun( | 9427 CompileRun( |
9427 "o.foo = 17;" | 9428 "o.foo = 17;" |
9428 "var receiver = {};" | 9429 "var receiver = {};" |
9429 "receiver.__proto__ = o;" | 9430 "receiver.__proto__ = o;" |
9430 "var result = 0;" | 9431 "var result = 0;" |
9431 "var saved_result = 0;" | 9432 "var saved_result = 0;" |
9432 "for (var i = 0; i < 100; i++) {" | 9433 "for (var i = 0; i < 100; i++) {" |
9433 " result = receiver.method(41);" | 9434 " result = receiver.method(41);" |
9434 " if (i == 50) {" | 9435 " if (i == 50) {" |
9435 " saved_result = result;" | 9436 " saved_result = result;" |
9436 " receiver = {method: receiver.method};" | 9437 " receiver = {method: receiver.method};" |
9437 " }" | 9438 " }" |
9438 "}")); | 9439 "}"); |
9439 CHECK(try_catch.HasCaught()); | 9440 CHECK(try_catch.HasCaught()); |
9440 CHECK_EQ(v8_str("TypeError: Illegal invocation"), | 9441 CHECK_EQ(v8_str("TypeError: Illegal invocation"), |
9441 try_catch.Exception()->ToString()); | 9442 try_catch.Exception()->ToString()); |
9442 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 9443 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); |
9443 CHECK_GE(interceptor_call_count, 50); | 9444 CHECK_GE(interceptor_call_count, 50); |
9444 } | 9445 } |
9445 | 9446 |
9446 THREADED_TEST(CallICFastApi_TrivialSignature) { | 9447 THREADED_TEST(CallICFastApi_TrivialSignature) { |
9447 v8::HandleScope scope; | 9448 v8::HandleScope scope; |
9448 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 9449 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
9449 v8::Handle<v8::FunctionTemplate> method_templ = | 9450 v8::Handle<v8::FunctionTemplate> method_templ = |
9450 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature, | 9451 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature, |
9451 v8_str("method_data"), | 9452 v8_str("method_data"), |
9452 v8::Handle<v8::Signature>()); | 9453 v8::Handle<v8::Signature>()); |
9453 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 9454 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
9454 proto_templ->Set(v8_str("method"), method_templ); | 9455 proto_templ->Set(v8_str("method"), method_templ); |
9455 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); | 9456 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); |
| 9457 USE(templ); |
9456 LocalContext context; | 9458 LocalContext context; |
9457 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 9459 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
9458 GenerateSomeGarbage(); | 9460 GenerateSomeGarbage(); |
9459 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 9461 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
9460 v8::Handle<Value> value(CompileRun( | 9462 CompileRun( |
9461 "var result = 0;" | 9463 "var result = 0;" |
9462 "for (var i = 0; i < 100; i++) {" | 9464 "for (var i = 0; i < 100; i++) {" |
9463 " result = o.method(41);" | 9465 " result = o.method(41);" |
9464 "}")); | 9466 "}"); |
9465 | 9467 |
9466 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); | 9468 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); |
9467 } | 9469 } |
9468 | 9470 |
9469 THREADED_TEST(CallICFastApi_SimpleSignature) { | 9471 THREADED_TEST(CallICFastApi_SimpleSignature) { |
9470 v8::HandleScope scope; | 9472 v8::HandleScope scope; |
9471 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 9473 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
9472 v8::Handle<v8::FunctionTemplate> method_templ = | 9474 v8::Handle<v8::FunctionTemplate> method_templ = |
9473 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, | 9475 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, |
9474 v8_str("method_data"), | 9476 v8_str("method_data"), |
9475 v8::Signature::New(fun_templ)); | 9477 v8::Signature::New(fun_templ)); |
9476 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 9478 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
9477 proto_templ->Set(v8_str("method"), method_templ); | 9479 proto_templ->Set(v8_str("method"), method_templ); |
9478 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); | 9480 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); |
| 9481 CHECK(!templ.IsEmpty()); |
9479 LocalContext context; | 9482 LocalContext context; |
9480 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 9483 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
9481 GenerateSomeGarbage(); | 9484 GenerateSomeGarbage(); |
9482 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 9485 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
9483 v8::Handle<Value> value(CompileRun( | 9486 CompileRun( |
9484 "o.foo = 17;" | 9487 "o.foo = 17;" |
9485 "var receiver = {};" | 9488 "var receiver = {};" |
9486 "receiver.__proto__ = o;" | 9489 "receiver.__proto__ = o;" |
9487 "var result = 0;" | 9490 "var result = 0;" |
9488 "for (var i = 0; i < 100; i++) {" | 9491 "for (var i = 0; i < 100; i++) {" |
9489 " result = receiver.method(41);" | 9492 " result = receiver.method(41);" |
9490 "}")); | 9493 "}"); |
9491 | 9494 |
9492 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); | 9495 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); |
9493 } | 9496 } |
9494 | 9497 |
9495 THREADED_TEST(CallICFastApi_SimpleSignature_Miss1) { | 9498 THREADED_TEST(CallICFastApi_SimpleSignature_Miss1) { |
9496 v8::HandleScope scope; | 9499 v8::HandleScope scope; |
9497 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 9500 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
9498 v8::Handle<v8::FunctionTemplate> method_templ = | 9501 v8::Handle<v8::FunctionTemplate> method_templ = |
9499 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, | 9502 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, |
9500 v8_str("method_data"), | 9503 v8_str("method_data"), |
9501 v8::Signature::New(fun_templ)); | 9504 v8::Signature::New(fun_templ)); |
9502 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 9505 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
9503 proto_templ->Set(v8_str("method"), method_templ); | 9506 proto_templ->Set(v8_str("method"), method_templ); |
9504 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); | 9507 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); |
| 9508 CHECK(!templ.IsEmpty()); |
9505 LocalContext context; | 9509 LocalContext context; |
9506 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 9510 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
9507 GenerateSomeGarbage(); | 9511 GenerateSomeGarbage(); |
9508 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 9512 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
9509 v8::Handle<Value> value(CompileRun( | 9513 CompileRun( |
9510 "o.foo = 17;" | 9514 "o.foo = 17;" |
9511 "var receiver = {};" | 9515 "var receiver = {};" |
9512 "receiver.__proto__ = o;" | 9516 "receiver.__proto__ = o;" |
9513 "var result = 0;" | 9517 "var result = 0;" |
9514 "var saved_result = 0;" | 9518 "var saved_result = 0;" |
9515 "for (var i = 0; i < 100; i++) {" | 9519 "for (var i = 0; i < 100; i++) {" |
9516 " result = receiver.method(41);" | 9520 " result = receiver.method(41);" |
9517 " if (i == 50) {" | 9521 " if (i == 50) {" |
9518 " saved_result = result;" | 9522 " saved_result = result;" |
9519 " receiver = {method: function(x) { return x - 1 }};" | 9523 " receiver = {method: function(x) { return x - 1 }};" |
9520 " }" | 9524 " }" |
9521 "}")); | 9525 "}"); |
9522 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); | 9526 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); |
9523 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 9527 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); |
9524 } | 9528 } |
9525 | 9529 |
9526 THREADED_TEST(CallICFastApi_SimpleSignature_Miss2) { | 9530 THREADED_TEST(CallICFastApi_SimpleSignature_Miss2) { |
9527 v8::HandleScope scope; | 9531 v8::HandleScope scope; |
9528 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 9532 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
9529 v8::Handle<v8::FunctionTemplate> method_templ = | 9533 v8::Handle<v8::FunctionTemplate> method_templ = |
9530 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, | 9534 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, |
9531 v8_str("method_data"), | 9535 v8_str("method_data"), |
9532 v8::Signature::New(fun_templ)); | 9536 v8::Signature::New(fun_templ)); |
9533 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 9537 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
9534 proto_templ->Set(v8_str("method"), method_templ); | 9538 proto_templ->Set(v8_str("method"), method_templ); |
9535 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); | 9539 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); |
| 9540 CHECK(!templ.IsEmpty()); |
9536 LocalContext context; | 9541 LocalContext context; |
9537 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 9542 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
9538 GenerateSomeGarbage(); | 9543 GenerateSomeGarbage(); |
9539 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 9544 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
9540 v8::TryCatch try_catch; | 9545 v8::TryCatch try_catch; |
9541 v8::Handle<Value> value(CompileRun( | 9546 CompileRun( |
9542 "o.foo = 17;" | 9547 "o.foo = 17;" |
9543 "var receiver = {};" | 9548 "var receiver = {};" |
9544 "receiver.__proto__ = o;" | 9549 "receiver.__proto__ = o;" |
9545 "var result = 0;" | 9550 "var result = 0;" |
9546 "var saved_result = 0;" | 9551 "var saved_result = 0;" |
9547 "for (var i = 0; i < 100; i++) {" | 9552 "for (var i = 0; i < 100; i++) {" |
9548 " result = receiver.method(41);" | 9553 " result = receiver.method(41);" |
9549 " if (i == 50) {" | 9554 " if (i == 50) {" |
9550 " saved_result = result;" | 9555 " saved_result = result;" |
9551 " receiver = 333;" | 9556 " receiver = 333;" |
9552 " }" | 9557 " }" |
9553 "}")); | 9558 "}"); |
9554 CHECK(try_catch.HasCaught()); | 9559 CHECK(try_catch.HasCaught()); |
9555 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"), | 9560 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"), |
9556 try_catch.Exception()->ToString()); | 9561 try_catch.Exception()->ToString()); |
9557 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 9562 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); |
9558 } | 9563 } |
9559 | 9564 |
9560 | 9565 |
9561 v8::Handle<Value> keyed_call_ic_function; | 9566 v8::Handle<Value> keyed_call_ic_function; |
9562 | 9567 |
9563 static v8::Handle<Value> InterceptorKeyedCallICGetter( | 9568 static v8::Handle<Value> InterceptorKeyedCallICGetter( |
9564 Local<String> name, const AccessorInfo& info) { | 9569 Local<String> name, const AccessorInfo& info) { |
9565 ApiTestFuzzer::Fuzz(); | 9570 ApiTestFuzzer::Fuzz(); |
9566 if (v8_str("x")->Equals(name)) { | 9571 if (v8_str("x")->Equals(name)) { |
9567 return keyed_call_ic_function; | 9572 return keyed_call_ic_function; |
9568 } | 9573 } |
9569 return v8::Handle<Value>(); | 9574 return v8::Handle<Value>(); |
9570 } | 9575 } |
9571 | 9576 |
9572 | 9577 |
9573 // Test the case when we stored cacheable lookup into | 9578 // Test the case when we stored cacheable lookup into |
9574 // a stub, but the function name changed (to another cacheable function). | 9579 // a stub, but the function name changed (to another cacheable function). |
9575 THREADED_TEST(InterceptorKeyedCallICKeyChange1) { | 9580 THREADED_TEST(InterceptorKeyedCallICKeyChange1) { |
9576 v8::HandleScope scope; | 9581 v8::HandleScope scope; |
9577 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | 9582 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); |
9578 templ->SetNamedPropertyHandler(NoBlockGetterX); | 9583 templ->SetNamedPropertyHandler(NoBlockGetterX); |
9579 LocalContext context; | 9584 LocalContext context; |
9580 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 9585 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
9581 v8::Handle<Value> value(CompileRun( | 9586 CompileRun( |
9582 "proto = new Object();" | 9587 "proto = new Object();" |
9583 "proto.y = function(x) { return x + 1; };" | 9588 "proto.y = function(x) { return x + 1; };" |
9584 "proto.z = function(x) { return x - 1; };" | 9589 "proto.z = function(x) { return x - 1; };" |
9585 "o.__proto__ = proto;" | 9590 "o.__proto__ = proto;" |
9586 "var result = 0;" | 9591 "var result = 0;" |
9587 "var method = 'y';" | 9592 "var method = 'y';" |
9588 "for (var i = 0; i < 10; i++) {" | 9593 "for (var i = 0; i < 10; i++) {" |
9589 " if (i == 5) { method = 'z'; };" | 9594 " if (i == 5) { method = 'z'; };" |
9590 " result += o[method](41);" | 9595 " result += o[method](41);" |
9591 "}")); | 9596 "}"); |
9592 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); | 9597 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); |
9593 } | 9598 } |
9594 | 9599 |
9595 | 9600 |
9596 // Test the case when we stored cacheable lookup into | 9601 // Test the case when we stored cacheable lookup into |
9597 // a stub, but the function name changed (and the new function is present | 9602 // a stub, but the function name changed (and the new function is present |
9598 // both before and after the interceptor in the prototype chain). | 9603 // both before and after the interceptor in the prototype chain). |
9599 THREADED_TEST(InterceptorKeyedCallICKeyChange2) { | 9604 THREADED_TEST(InterceptorKeyedCallICKeyChange2) { |
9600 v8::HandleScope scope; | 9605 v8::HandleScope scope; |
9601 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | 9606 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); |
9602 templ->SetNamedPropertyHandler(InterceptorKeyedCallICGetter); | 9607 templ->SetNamedPropertyHandler(InterceptorKeyedCallICGetter); |
9603 LocalContext context; | 9608 LocalContext context; |
9604 context->Global()->Set(v8_str("proto1"), templ->NewInstance()); | 9609 context->Global()->Set(v8_str("proto1"), templ->NewInstance()); |
9605 keyed_call_ic_function = | 9610 keyed_call_ic_function = |
9606 v8_compile("function f(x) { return x - 1; }; f")->Run(); | 9611 v8_compile("function f(x) { return x - 1; }; f")->Run(); |
9607 v8::Handle<Value> value(CompileRun( | 9612 CompileRun( |
9608 "o = new Object();" | 9613 "o = new Object();" |
9609 "proto2 = new Object();" | 9614 "proto2 = new Object();" |
9610 "o.y = function(x) { return x + 1; };" | 9615 "o.y = function(x) { return x + 1; };" |
9611 "proto2.y = function(x) { return x + 2; };" | 9616 "proto2.y = function(x) { return x + 2; };" |
9612 "o.__proto__ = proto1;" | 9617 "o.__proto__ = proto1;" |
9613 "proto1.__proto__ = proto2;" | 9618 "proto1.__proto__ = proto2;" |
9614 "var result = 0;" | 9619 "var result = 0;" |
9615 "var method = 'x';" | 9620 "var method = 'x';" |
9616 "for (var i = 0; i < 10; i++) {" | 9621 "for (var i = 0; i < 10; i++) {" |
9617 " if (i == 5) { method = 'y'; };" | 9622 " if (i == 5) { method = 'y'; };" |
9618 " result += o[method](41);" | 9623 " result += o[method](41);" |
9619 "}")); | 9624 "}"); |
9620 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); | 9625 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); |
9621 } | 9626 } |
9622 | 9627 |
9623 | 9628 |
9624 // Same as InterceptorKeyedCallICKeyChange1 only the cacheable function sit | 9629 // Same as InterceptorKeyedCallICKeyChange1 only the cacheable function sit |
9625 // on the global object. | 9630 // on the global object. |
9626 THREADED_TEST(InterceptorKeyedCallICKeyChangeOnGlobal) { | 9631 THREADED_TEST(InterceptorKeyedCallICKeyChangeOnGlobal) { |
9627 v8::HandleScope scope; | 9632 v8::HandleScope scope; |
9628 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | 9633 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); |
9629 templ->SetNamedPropertyHandler(NoBlockGetterX); | 9634 templ->SetNamedPropertyHandler(NoBlockGetterX); |
9630 LocalContext context; | 9635 LocalContext context; |
9631 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 9636 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
9632 v8::Handle<Value> value(CompileRun( | 9637 CompileRun( |
9633 "function inc(x) { return x + 1; };" | 9638 "function inc(x) { return x + 1; };" |
9634 "inc(1);" | 9639 "inc(1);" |
9635 "function dec(x) { return x - 1; };" | 9640 "function dec(x) { return x - 1; };" |
9636 "dec(1);" | 9641 "dec(1);" |
9637 "o.__proto__ = this;" | 9642 "o.__proto__ = this;" |
9638 "this.__proto__.x = inc;" | 9643 "this.__proto__.x = inc;" |
9639 "this.__proto__.y = dec;" | 9644 "this.__proto__.y = dec;" |
9640 "var result = 0;" | 9645 "var result = 0;" |
9641 "var method = 'x';" | 9646 "var method = 'x';" |
9642 "for (var i = 0; i < 10; i++) {" | 9647 "for (var i = 0; i < 10; i++) {" |
9643 " if (i == 5) { method = 'y'; };" | 9648 " if (i == 5) { method = 'y'; };" |
9644 " result += o[method](41);" | 9649 " result += o[method](41);" |
9645 "}")); | 9650 "}"); |
9646 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); | 9651 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); |
9647 } | 9652 } |
9648 | 9653 |
9649 | 9654 |
9650 // Test the case when actual function to call sits on global object. | 9655 // Test the case when actual function to call sits on global object. |
9651 THREADED_TEST(InterceptorKeyedCallICFromGlobal) { | 9656 THREADED_TEST(InterceptorKeyedCallICFromGlobal) { |
9652 v8::HandleScope scope; | 9657 v8::HandleScope scope; |
9653 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); | 9658 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); |
9654 templ_o->SetNamedPropertyHandler(NoBlockGetterX); | 9659 templ_o->SetNamedPropertyHandler(NoBlockGetterX); |
9655 LocalContext context; | 9660 LocalContext context; |
9656 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); | 9661 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); |
9657 | 9662 |
9658 v8::Handle<Value> value(CompileRun( | 9663 CompileRun( |
9659 "function len(x) { return x.length; };" | 9664 "function len(x) { return x.length; };" |
9660 "o.__proto__ = this;" | 9665 "o.__proto__ = this;" |
9661 "var m = 'parseFloat';" | 9666 "var m = 'parseFloat';" |
9662 "var result = 0;" | 9667 "var result = 0;" |
9663 "for (var i = 0; i < 10; i++) {" | 9668 "for (var i = 0; i < 10; i++) {" |
9664 " if (i == 5) {" | 9669 " if (i == 5) {" |
9665 " m = 'len';" | 9670 " m = 'len';" |
9666 " saved_result = result;" | 9671 " saved_result = result;" |
9667 " };" | 9672 " };" |
9668 " result = o[m]('239');" | 9673 " result = o[m]('239');" |
9669 "}")); | 9674 "}"); |
9670 CHECK_EQ(3, context->Global()->Get(v8_str("result"))->Int32Value()); | 9675 CHECK_EQ(3, context->Global()->Get(v8_str("result"))->Int32Value()); |
9671 CHECK_EQ(239, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 9676 CHECK_EQ(239, context->Global()->Get(v8_str("saved_result"))->Int32Value()); |
9672 } | 9677 } |
9673 | 9678 |
9674 // Test the map transition before the interceptor. | 9679 // Test the map transition before the interceptor. |
9675 THREADED_TEST(InterceptorKeyedCallICMapChangeBefore) { | 9680 THREADED_TEST(InterceptorKeyedCallICMapChangeBefore) { |
9676 v8::HandleScope scope; | 9681 v8::HandleScope scope; |
9677 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); | 9682 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); |
9678 templ_o->SetNamedPropertyHandler(NoBlockGetterX); | 9683 templ_o->SetNamedPropertyHandler(NoBlockGetterX); |
9679 LocalContext context; | 9684 LocalContext context; |
9680 context->Global()->Set(v8_str("proto"), templ_o->NewInstance()); | 9685 context->Global()->Set(v8_str("proto"), templ_o->NewInstance()); |
9681 | 9686 |
9682 v8::Handle<Value> value(CompileRun( | 9687 CompileRun( |
9683 "var o = new Object();" | 9688 "var o = new Object();" |
9684 "o.__proto__ = proto;" | 9689 "o.__proto__ = proto;" |
9685 "o.method = function(x) { return x + 1; };" | 9690 "o.method = function(x) { return x + 1; };" |
9686 "var m = 'method';" | 9691 "var m = 'method';" |
9687 "var result = 0;" | 9692 "var result = 0;" |
9688 "for (var i = 0; i < 10; i++) {" | 9693 "for (var i = 0; i < 10; i++) {" |
9689 " if (i == 5) { o.method = function(x) { return x - 1; }; };" | 9694 " if (i == 5) { o.method = function(x) { return x - 1; }; };" |
9690 " result += o[m](41);" | 9695 " result += o[m](41);" |
9691 "}")); | 9696 "}"); |
9692 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); | 9697 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); |
9693 } | 9698 } |
9694 | 9699 |
9695 | 9700 |
9696 // Test the map transition after the interceptor. | 9701 // Test the map transition after the interceptor. |
9697 THREADED_TEST(InterceptorKeyedCallICMapChangeAfter) { | 9702 THREADED_TEST(InterceptorKeyedCallICMapChangeAfter) { |
9698 v8::HandleScope scope; | 9703 v8::HandleScope scope; |
9699 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); | 9704 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); |
9700 templ_o->SetNamedPropertyHandler(NoBlockGetterX); | 9705 templ_o->SetNamedPropertyHandler(NoBlockGetterX); |
9701 LocalContext context; | 9706 LocalContext context; |
9702 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); | 9707 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); |
9703 | 9708 |
9704 v8::Handle<Value> value(CompileRun( | 9709 CompileRun( |
9705 "var proto = new Object();" | 9710 "var proto = new Object();" |
9706 "o.__proto__ = proto;" | 9711 "o.__proto__ = proto;" |
9707 "proto.method = function(x) { return x + 1; };" | 9712 "proto.method = function(x) { return x + 1; };" |
9708 "var m = 'method';" | 9713 "var m = 'method';" |
9709 "var result = 0;" | 9714 "var result = 0;" |
9710 "for (var i = 0; i < 10; i++) {" | 9715 "for (var i = 0; i < 10; i++) {" |
9711 " if (i == 5) { proto.method = function(x) { return x - 1; }; };" | 9716 " if (i == 5) { proto.method = function(x) { return x - 1; }; };" |
9712 " result += o[m](41);" | 9717 " result += o[m](41);" |
9713 "}")); | 9718 "}"); |
9714 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); | 9719 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); |
9715 } | 9720 } |
9716 | 9721 |
9717 | 9722 |
9718 static int interceptor_call_count = 0; | 9723 static int interceptor_call_count = 0; |
9719 | 9724 |
9720 static v8::Handle<Value> InterceptorICRefErrorGetter(Local<String> name, | 9725 static v8::Handle<Value> InterceptorICRefErrorGetter(Local<String> name, |
9721 const AccessorInfo& info) { | 9726 const AccessorInfo& info) { |
9722 ApiTestFuzzer::Fuzz(); | 9727 ApiTestFuzzer::Fuzz(); |
9723 if (v8_str("x")->Equals(name) && interceptor_call_count++ < 20) { | 9728 if (v8_str("x")->Equals(name) && interceptor_call_count++ < 20) { |
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10620 return value; | 10625 return value; |
10621 } | 10626 } |
10622 | 10627 |
10623 | 10628 |
10624 THREADED_TEST(NestedHandleScopeAndContexts) { | 10629 THREADED_TEST(NestedHandleScopeAndContexts) { |
10625 v8::HandleScope outer; | 10630 v8::HandleScope outer; |
10626 v8::Persistent<Context> env = Context::New(); | 10631 v8::Persistent<Context> env = Context::New(); |
10627 env->Enter(); | 10632 env->Enter(); |
10628 v8::Handle<Value> value = NestedScope(env); | 10633 v8::Handle<Value> value = NestedScope(env); |
10629 v8::Handle<String> str(value->ToString()); | 10634 v8::Handle<String> str(value->ToString()); |
| 10635 CHECK(!str.IsEmpty()); |
10630 env->Exit(); | 10636 env->Exit(); |
10631 env.Dispose(); | 10637 env.Dispose(); |
10632 } | 10638 } |
10633 | 10639 |
10634 | 10640 |
10635 THREADED_TEST(ExternalAllocatedMemory) { | 10641 THREADED_TEST(ExternalAllocatedMemory) { |
10636 v8::HandleScope outer; | 10642 v8::HandleScope outer; |
10637 v8::Persistent<Context> env(Context::New()); | 10643 v8::Persistent<Context> env(Context::New()); |
| 10644 CHECK(!env.IsEmpty()); |
10638 const int kSize = 1024*1024; | 10645 const int kSize = 1024*1024; |
10639 CHECK_EQ(v8::V8::AdjustAmountOfExternalAllocatedMemory(kSize), kSize); | 10646 CHECK_EQ(v8::V8::AdjustAmountOfExternalAllocatedMemory(kSize), kSize); |
10640 CHECK_EQ(v8::V8::AdjustAmountOfExternalAllocatedMemory(-kSize), 0); | 10647 CHECK_EQ(v8::V8::AdjustAmountOfExternalAllocatedMemory(-kSize), 0); |
10641 } | 10648 } |
10642 | 10649 |
10643 | 10650 |
10644 THREADED_TEST(DisposeEnteredContext) { | 10651 THREADED_TEST(DisposeEnteredContext) { |
10645 v8::HandleScope scope; | 10652 v8::HandleScope scope; |
10646 LocalContext outer; | 10653 LocalContext outer; |
10647 { v8::Persistent<v8::Context> inner = v8::Context::New(); | 10654 { v8::Persistent<v8::Context> inner = v8::Context::New(); |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10966 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 10973 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); |
10967 global_template->SetAccessCheckCallbacks(NamedSetAccessBlocker, | 10974 global_template->SetAccessCheckCallbacks(NamedSetAccessBlocker, |
10968 IndexedSetAccessBlocker); | 10975 IndexedSetAccessBlocker); |
10969 i::Handle<i::ObjectTemplateInfo> internal_template = | 10976 i::Handle<i::ObjectTemplateInfo> internal_template = |
10970 v8::Utils::OpenHandle(*global_template); | 10977 v8::Utils::OpenHandle(*global_template); |
10971 CHECK(!internal_template->constructor()->IsUndefined()); | 10978 CHECK(!internal_template->constructor()->IsUndefined()); |
10972 i::Handle<i::FunctionTemplateInfo> constructor( | 10979 i::Handle<i::FunctionTemplateInfo> constructor( |
10973 i::FunctionTemplateInfo::cast(internal_template->constructor())); | 10980 i::FunctionTemplateInfo::cast(internal_template->constructor())); |
10974 CHECK(!constructor->access_check_info()->IsUndefined()); | 10981 CHECK(!constructor->access_check_info()->IsUndefined()); |
10975 v8::Persistent<Context> context0(Context::New(NULL, global_template)); | 10982 v8::Persistent<Context> context0(Context::New(NULL, global_template)); |
| 10983 CHECK(!context0.IsEmpty()); |
10976 CHECK(!constructor->access_check_info()->IsUndefined()); | 10984 CHECK(!constructor->access_check_info()->IsUndefined()); |
10977 } | 10985 } |
10978 | 10986 |
10979 | 10987 |
10980 THREADED_TEST(TurnOnAccessCheck) { | 10988 THREADED_TEST(TurnOnAccessCheck) { |
10981 v8::HandleScope handle_scope; | 10989 v8::HandleScope handle_scope; |
10982 | 10990 |
10983 // Create an environment with access check to the global object disabled by | 10991 // Create an environment with access check to the global object disabled by |
10984 // default. | 10992 // default. |
10985 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 10993 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); |
(...skipping 2055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13041 // Test more complex manipulations which cause eax to contain values | 13049 // Test more complex manipulations which cause eax to contain values |
13042 // that won't be completely overwritten by loads from the arrays. | 13050 // that won't be completely overwritten by loads from the arrays. |
13043 // This catches bugs in the instructions used for the KeyedLoadIC | 13051 // This catches bugs in the instructions used for the KeyedLoadIC |
13044 // for byte and word types. | 13052 // for byte and word types. |
13045 { | 13053 { |
13046 const int kXSize = 300; | 13054 const int kXSize = 300; |
13047 const int kYSize = 300; | 13055 const int kYSize = 300; |
13048 const int kLargeElementCount = kXSize * kYSize * 4; | 13056 const int kLargeElementCount = kXSize * kYSize * 4; |
13049 ElementType* large_array_data = | 13057 ElementType* large_array_data = |
13050 static_cast<ElementType*>(malloc(kLargeElementCount * element_size)); | 13058 static_cast<ElementType*>(malloc(kLargeElementCount * element_size)); |
13051 i::Handle<ExternalArrayClass> large_array( | |
13052 i::Handle<ExternalArrayClass>::cast( | |
13053 FACTORY->NewExternalArray(kLargeElementCount, | |
13054 array_type, | |
13055 array_data))); | |
13056 v8::Handle<v8::Object> large_obj = v8::Object::New(); | 13059 v8::Handle<v8::Object> large_obj = v8::Object::New(); |
13057 // Set the elements to be the external array. | 13060 // Set the elements to be the external array. |
13058 large_obj->SetIndexedPropertiesToExternalArrayData(large_array_data, | 13061 large_obj->SetIndexedPropertiesToExternalArrayData(large_array_data, |
13059 array_type, | 13062 array_type, |
13060 kLargeElementCount); | 13063 kLargeElementCount); |
13061 context->Global()->Set(v8_str("large_array"), large_obj); | 13064 context->Global()->Set(v8_str("large_array"), large_obj); |
13062 // Initialize contents of a few rows. | 13065 // Initialize contents of a few rows. |
13063 for (int x = 0; x < 300; x++) { | 13066 for (int x = 0; x < 300; x++) { |
13064 int row = 0; | 13067 int row = 0; |
13065 int offset = row * 300 * 4; | 13068 int offset = row * 300 * 4; |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13446 " var y; AnalyzeStackInNativeCode(1);\n" | 13449 " var y; AnalyzeStackInNativeCode(1);\n" |
13447 "}\n" | 13450 "}\n" |
13448 "function foo() {\n" | 13451 "function foo() {\n" |
13449 "\n" | 13452 "\n" |
13450 " bar();\n" | 13453 " bar();\n" |
13451 "}\n" | 13454 "}\n" |
13452 "var x;eval('new foo();');"; | 13455 "var x;eval('new foo();');"; |
13453 v8::Handle<v8::String> overview_src = v8::String::New(overview_source); | 13456 v8::Handle<v8::String> overview_src = v8::String::New(overview_source); |
13454 v8::Handle<Value> overview_result( | 13457 v8::Handle<Value> overview_result( |
13455 v8::Script::New(overview_src, origin)->Run()); | 13458 v8::Script::New(overview_src, origin)->Run()); |
13456 ASSERT(!overview_result.IsEmpty()); | 13459 CHECK(!overview_result.IsEmpty()); |
13457 ASSERT(overview_result->IsObject()); | 13460 CHECK(overview_result->IsObject()); |
13458 | 13461 |
13459 // Test getting DETAILED information. | 13462 // Test getting DETAILED information. |
13460 const char *detailed_source = | 13463 const char *detailed_source = |
13461 "function bat() {AnalyzeStackInNativeCode(2);\n" | 13464 "function bat() {AnalyzeStackInNativeCode(2);\n" |
13462 "}\n" | 13465 "}\n" |
13463 "\n" | 13466 "\n" |
13464 "function baz() {\n" | 13467 "function baz() {\n" |
13465 " bat();\n" | 13468 " bat();\n" |
13466 "}\n" | 13469 "}\n" |
13467 "eval('new baz();');"; | 13470 "eval('new baz();');"; |
13468 v8::Handle<v8::String> detailed_src = v8::String::New(detailed_source); | 13471 v8::Handle<v8::String> detailed_src = v8::String::New(detailed_source); |
13469 // Make the script using a non-zero line and column offset. | 13472 // Make the script using a non-zero line and column offset. |
13470 v8::Handle<v8::Integer> line_offset = v8::Integer::New(3); | 13473 v8::Handle<v8::Integer> line_offset = v8::Integer::New(3); |
13471 v8::Handle<v8::Integer> column_offset = v8::Integer::New(5); | 13474 v8::Handle<v8::Integer> column_offset = v8::Integer::New(5); |
13472 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset); | 13475 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset); |
13473 v8::Handle<v8::Script> detailed_script( | 13476 v8::Handle<v8::Script> detailed_script( |
13474 v8::Script::New(detailed_src, &detailed_origin)); | 13477 v8::Script::New(detailed_src, &detailed_origin)); |
13475 v8::Handle<Value> detailed_result(detailed_script->Run()); | 13478 v8::Handle<Value> detailed_result(detailed_script->Run()); |
13476 ASSERT(!detailed_result.IsEmpty()); | 13479 CHECK(!detailed_result.IsEmpty()); |
13477 ASSERT(detailed_result->IsObject()); | 13480 CHECK(detailed_result->IsObject()); |
13478 } | 13481 } |
13479 | 13482 |
13480 | 13483 |
13481 static void StackTraceForUncaughtExceptionListener( | 13484 static void StackTraceForUncaughtExceptionListener( |
13482 v8::Handle<v8::Message> message, | 13485 v8::Handle<v8::Message> message, |
13483 v8::Handle<Value>) { | 13486 v8::Handle<Value>) { |
13484 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); | 13487 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); |
13485 CHECK_EQ(2, stack_trace->GetFrameCount()); | 13488 CHECK_EQ(2, stack_trace->GetFrameCount()); |
13486 checkStackFrame("origin", "foo", 2, 3, false, false, | 13489 checkStackFrame("origin", "foo", 2, 3, false, false, |
13487 stack_trace->GetFrame(0)); | 13490 stack_trace->GetFrame(0)); |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13887 #endif | 13890 #endif |
13888 } | 13891 } |
13889 } | 13892 } |
13890 } | 13893 } |
13891 | 13894 |
13892 | 13895 |
13893 static v8::Handle<Value> SpaghettiIncident(const v8::Arguments& args) { | 13896 static v8::Handle<Value> SpaghettiIncident(const v8::Arguments& args) { |
13894 v8::HandleScope scope; | 13897 v8::HandleScope scope; |
13895 v8::TryCatch tc; | 13898 v8::TryCatch tc; |
13896 v8::Handle<v8::String> str(args[0]->ToString()); | 13899 v8::Handle<v8::String> str(args[0]->ToString()); |
| 13900 USE(str); |
13897 if (tc.HasCaught()) | 13901 if (tc.HasCaught()) |
13898 return tc.ReThrow(); | 13902 return tc.ReThrow(); |
13899 return v8::Undefined(); | 13903 return v8::Undefined(); |
13900 } | 13904 } |
13901 | 13905 |
13902 | 13906 |
13903 // Test that an exception can be propagated down through a spaghetti | 13907 // Test that an exception can be propagated down through a spaghetti |
13904 // stack using ReThrow. | 13908 // stack using ReThrow. |
13905 THREADED_TEST(SpaghettiStackReThrow) { | 13909 THREADED_TEST(SpaghettiStackReThrow) { |
13906 v8::HandleScope scope; | 13910 v8::HandleScope scope; |
(...skipping 1278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15185 CHECK(re->GetSource()->Equals(v8_str("foobarbaz"))); | 15189 CHECK(re->GetSource()->Equals(v8_str("foobarbaz"))); |
15186 CHECK_EQ(v8::RegExp::kIgnoreCase | v8::RegExp::kMultiline, | 15190 CHECK_EQ(v8::RegExp::kIgnoreCase | v8::RegExp::kMultiline, |
15187 static_cast<int>(re->GetFlags())); | 15191 static_cast<int>(re->GetFlags())); |
15188 | 15192 |
15189 context->Global()->Set(v8_str("re"), re); | 15193 context->Global()->Set(v8_str("re"), re); |
15190 ExpectTrue("re.test('FoobarbaZ')"); | 15194 ExpectTrue("re.test('FoobarbaZ')"); |
15191 | 15195 |
15192 // RegExps are objects on which you can set properties. | 15196 // RegExps are objects on which you can set properties. |
15193 re->Set(v8_str("property"), v8::Integer::New(32)); | 15197 re->Set(v8_str("property"), v8::Integer::New(32)); |
15194 v8::Handle<v8::Value> value(CompileRun("re.property")); | 15198 v8::Handle<v8::Value> value(CompileRun("re.property")); |
15195 ASSERT_EQ(32, value->Int32Value()); | 15199 CHECK_EQ(32, value->Int32Value()); |
15196 | 15200 |
15197 v8::TryCatch try_catch; | 15201 v8::TryCatch try_catch; |
15198 re = v8::RegExp::New(v8_str("foo["), v8::RegExp::kNone); | 15202 re = v8::RegExp::New(v8_str("foo["), v8::RegExp::kNone); |
15199 CHECK(re.IsEmpty()); | 15203 CHECK(re.IsEmpty()); |
15200 CHECK(try_catch.HasCaught()); | 15204 CHECK(try_catch.HasCaught()); |
15201 context->Global()->Set(v8_str("ex"), try_catch.Exception()); | 15205 context->Global()->Set(v8_str("ex"), try_catch.Exception()); |
15202 ExpectTrue("ex instanceof SyntaxError"); | 15206 ExpectTrue("ex instanceof SyntaxError"); |
15203 } | 15207 } |
15204 | 15208 |
15205 | 15209 |
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15926 CompileRun("throw 'exception';"); | 15930 CompileRun("throw 'exception';"); |
15927 } | 15931 } |
15928 | 15932 |
15929 | 15933 |
15930 TEST(CallCompletedCallbackTwoExceptions) { | 15934 TEST(CallCompletedCallbackTwoExceptions) { |
15931 v8::HandleScope scope; | 15935 v8::HandleScope scope; |
15932 LocalContext env; | 15936 LocalContext env; |
15933 v8::V8::AddCallCompletedCallback(CallCompletedCallbackException); | 15937 v8::V8::AddCallCompletedCallback(CallCompletedCallbackException); |
15934 CompileRun("throw 'first exception';"); | 15938 CompileRun("throw 'first exception';"); |
15935 } | 15939 } |
OLD | NEW |