| OLD | NEW |
| 1 // Copyright 2007-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2009 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 7507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7518 // Helper to maximize the odds of object moving. | 7518 // Helper to maximize the odds of object moving. |
| 7519 static void GenerateSomeGarbage() { | 7519 static void GenerateSomeGarbage() { |
| 7520 CompileRun( | 7520 CompileRun( |
| 7521 "var garbage;" | 7521 "var garbage;" |
| 7522 "for (var i = 0; i < 1000; i++) {" | 7522 "for (var i = 0; i < 1000; i++) {" |
| 7523 " garbage = [1/i, \"garbage\" + i, garbage, {foo: garbage}];" | 7523 " garbage = [1/i, \"garbage\" + i, garbage, {foo: garbage}];" |
| 7524 "}" | 7524 "}" |
| 7525 "garbage = undefined;"); | 7525 "garbage = undefined;"); |
| 7526 } | 7526 } |
| 7527 | 7527 |
| 7528 v8::Handle<v8::Value> DirectApiCallback(const v8::Arguments& args) { |
| 7529 static int count = 0; |
| 7530 if (count++ % 3 == 0) { |
| 7531 v8::V8::LowMemoryNotification(); // This should move the stub |
| 7532 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed |
| 7533 } |
| 7534 return v8::Handle<v8::Value>(); |
| 7535 } |
| 7536 |
| 7537 |
| 7538 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) { |
| 7539 v8::HandleScope scope; |
| 7540 LocalContext context; |
| 7541 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New(); |
| 7542 nativeobject_templ->Set("callback", |
| 7543 v8::FunctionTemplate::New(DirectApiCallback)); |
| 7544 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); |
| 7545 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); |
| 7546 // call the api function multiple times to ensure direct call stub creation. |
| 7547 CompileRun( |
| 7548 "function f() {" |
| 7549 " for (var i = 1; i <= 30; i++) {" |
| 7550 " nativeobject.callback();" |
| 7551 " }" |
| 7552 "}" |
| 7553 "f();"); |
| 7554 } |
| 7555 |
| 7556 |
| 7557 v8::Handle<v8::Value> ThrowingDirectApiCallback(const v8::Arguments& args) { |
| 7558 return v8::ThrowException(v8_str("g")); |
| 7559 } |
| 7560 |
| 7561 |
| 7562 THREADED_TEST(CallICFastApi_DirectCall_Throw) { |
| 7563 v8::HandleScope scope; |
| 7564 LocalContext context; |
| 7565 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New(); |
| 7566 nativeobject_templ->Set("callback", |
| 7567 v8::FunctionTemplate::New(ThrowingDirectApiCallback)); |
| 7568 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); |
| 7569 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); |
| 7570 // call the api function multiple times to ensure direct call stub creation. |
| 7571 v8::Handle<Value> result = CompileRun( |
| 7572 "var result = '';" |
| 7573 "function f() {" |
| 7574 " for (var i = 1; i <= 5; i++) {" |
| 7575 " try { nativeobject.callback(); } catch (e) { result += e; }" |
| 7576 " }" |
| 7577 "}" |
| 7578 "f(); result;"); |
| 7579 CHECK_EQ(v8_str("ggggg"), result); |
| 7580 } |
| 7581 |
| 7582 |
| 7528 THREADED_TEST(InterceptorCallICFastApi_TrivialSignature) { | 7583 THREADED_TEST(InterceptorCallICFastApi_TrivialSignature) { |
| 7529 int interceptor_call_count = 0; | 7584 int interceptor_call_count = 0; |
| 7530 v8::HandleScope scope; | 7585 v8::HandleScope scope; |
| 7531 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 7586 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
| 7532 v8::Handle<v8::FunctionTemplate> method_templ = | 7587 v8::Handle<v8::FunctionTemplate> method_templ = |
| 7533 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature, | 7588 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature, |
| 7534 v8_str("method_data"), | 7589 v8_str("method_data"), |
| 7535 v8::Handle<v8::Signature>()); | 7590 v8::Handle<v8::Signature>()); |
| 7536 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 7591 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
| 7537 proto_templ->Set(v8_str("method"), method_templ); | 7592 proto_templ->Set(v8_str("method"), method_templ); |
| (...skipping 4878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12416 v8::Handle<v8::Function> define_property = | 12471 v8::Handle<v8::Function> define_property = |
| 12417 CompileRun("(function() {" | 12472 CompileRun("(function() {" |
| 12418 " Object.defineProperty(" | 12473 " Object.defineProperty(" |
| 12419 " this," | 12474 " this," |
| 12420 " 1," | 12475 " 1," |
| 12421 " { configurable: true, enumerable: true, value: 3 });" | 12476 " { configurable: true, enumerable: true, value: 3 });" |
| 12422 "})").As<Function>(); | 12477 "})").As<Function>(); |
| 12423 context->DetachGlobal(); | 12478 context->DetachGlobal(); |
| 12424 define_property->Call(proxy, 0, NULL); | 12479 define_property->Call(proxy, 0, NULL); |
| 12425 } | 12480 } |
| OLD | NEW |