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 7425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7436 // Helper to maximize the odds of object moving. | 7436 // Helper to maximize the odds of object moving. |
7437 static void GenerateSomeGarbage() { | 7437 static void GenerateSomeGarbage() { |
7438 CompileRun( | 7438 CompileRun( |
7439 "var garbage;" | 7439 "var garbage;" |
7440 "for (var i = 0; i < 1000; i++) {" | 7440 "for (var i = 0; i < 1000; i++) {" |
7441 " garbage = [1/i, \"garbage\" + i, garbage, {foo: garbage}];" | 7441 " garbage = [1/i, \"garbage\" + i, garbage, {foo: garbage}];" |
7442 "}" | 7442 "}" |
7443 "garbage = undefined;"); | 7443 "garbage = undefined;"); |
7444 } | 7444 } |
7445 | 7445 |
| 7446 v8::Handle<v8::Value> DirectApiCallback(const v8::Arguments& args) { |
| 7447 static int count = 0; |
| 7448 if (count++ % 3 == 0) { |
| 7449 v8::V8::LowMemoryNotification(); // This should move the stub |
| 7450 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed |
| 7451 } |
| 7452 return v8::Handle<v8::Value>(); |
| 7453 } |
| 7454 |
| 7455 |
| 7456 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) { |
| 7457 v8::HandleScope scope; |
| 7458 LocalContext context; |
| 7459 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New(); |
| 7460 nativeobject_templ->Set("callback", |
| 7461 v8::FunctionTemplate::New(DirectApiCallback)); |
| 7462 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); |
| 7463 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); |
| 7464 // call the api function multiple times to ensure direct call stub creation. |
| 7465 CompileRun( |
| 7466 "function f() {" |
| 7467 " for (var i = 1; i <= 30; i++) {" |
| 7468 " nativeobject.callback();" |
| 7469 " }" |
| 7470 "}" |
| 7471 "f();"); |
| 7472 } |
| 7473 |
| 7474 |
| 7475 v8::Handle<v8::Value> ThrowingDirectApiCallback(const v8::Arguments& args) { |
| 7476 return v8::ThrowException(v8_str("g")); |
| 7477 } |
| 7478 |
| 7479 |
| 7480 THREADED_TEST(CallICFastApi_DirectCall_Throw) { |
| 7481 v8::HandleScope scope; |
| 7482 LocalContext context; |
| 7483 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New(); |
| 7484 nativeobject_templ->Set("callback", |
| 7485 v8::FunctionTemplate::New(ThrowingDirectApiCallback)); |
| 7486 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); |
| 7487 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); |
| 7488 // call the api function multiple times to ensure direct call stub creation. |
| 7489 v8::Handle<Value> result = CompileRun( |
| 7490 "var result = '';" |
| 7491 "function f() {" |
| 7492 " for (var i = 1; i <= 5; i++) {" |
| 7493 " try { nativeobject.callback(); } catch (e) { result += e; }" |
| 7494 " }" |
| 7495 "}" |
| 7496 "f(); result;"); |
| 7497 CHECK_EQ(v8_str("ggggg"), result); |
| 7498 } |
| 7499 |
| 7500 |
7446 THREADED_TEST(InterceptorCallICFastApi_TrivialSignature) { | 7501 THREADED_TEST(InterceptorCallICFastApi_TrivialSignature) { |
7447 int interceptor_call_count = 0; | 7502 int interceptor_call_count = 0; |
7448 v8::HandleScope scope; | 7503 v8::HandleScope scope; |
7449 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 7504 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
7450 v8::Handle<v8::FunctionTemplate> method_templ = | 7505 v8::Handle<v8::FunctionTemplate> method_templ = |
7451 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature, | 7506 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature, |
7452 v8_str("method_data"), | 7507 v8_str("method_data"), |
7453 v8::Handle<v8::Signature>()); | 7508 v8::Handle<v8::Signature>()); |
7454 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 7509 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
7455 proto_templ->Set(v8_str("method"), method_templ); | 7510 proto_templ->Set(v8_str("method"), method_templ); |
(...skipping 4862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12318 v8::Context::Scope context_scope(context.local()); | 12373 v8::Context::Scope context_scope(context.local()); |
12319 | 12374 |
12320 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(); | 12375 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(); |
12321 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); | 12376 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); |
12322 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); | 12377 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); |
12323 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( | 12378 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( |
12324 "var result = []; for (var k in o) result.push(k); result")); | 12379 "var result = []; for (var k in o) result.push(k); result")); |
12325 CHECK_EQ(1, result->Length()); | 12380 CHECK_EQ(1, result->Length()); |
12326 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); | 12381 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); |
12327 } | 12382 } |
OLD | NEW |