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 7327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7338 // Helper to maximize the odds of object moving. | 7338 // Helper to maximize the odds of object moving. |
7339 static void GenerateSomeGarbage() { | 7339 static void GenerateSomeGarbage() { |
7340 CompileRun( | 7340 CompileRun( |
7341 "var garbage;" | 7341 "var garbage;" |
7342 "for (var i = 0; i < 1000; i++) {" | 7342 "for (var i = 0; i < 1000; i++) {" |
7343 " garbage = [1/i, \"garbage\" + i, garbage, {foo: garbage}];" | 7343 " garbage = [1/i, \"garbage\" + i, garbage, {foo: garbage}];" |
7344 "}" | 7344 "}" |
7345 "garbage = undefined;"); | 7345 "garbage = undefined;"); |
7346 } | 7346 } |
7347 | 7347 |
| 7348 v8::Handle<v8::Value> DirectApiCallback(const v8::Arguments& args) { |
| 7349 static int count = 0; |
| 7350 if (count++ % 3 == 0) { |
| 7351 v8::V8::LowMemoryNotification(); // This should move the stub |
| 7352 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed |
| 7353 } |
| 7354 return v8::Handle<v8::Value>(); |
| 7355 } |
| 7356 |
| 7357 |
| 7358 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) { |
| 7359 v8::HandleScope scope; |
| 7360 LocalContext context; |
| 7361 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New(); |
| 7362 nativeobject_templ->Set("callback", |
| 7363 v8::FunctionTemplate::New(DirectApiCallback)); |
| 7364 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); |
| 7365 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); |
| 7366 // call the api function multiple times to ensure direct call stub creation. |
| 7367 CompileRun( |
| 7368 "function f() {" |
| 7369 " for (var i = 1; i <= 30; i++) {" |
| 7370 " nativeobject.callback();" |
| 7371 " }" |
| 7372 "}" |
| 7373 "f();"); |
| 7374 } |
| 7375 |
| 7376 |
| 7377 v8::Handle<v8::Value> ThrowingDirectApiCallback(const v8::Arguments& args) { |
| 7378 return v8::ThrowException(v8_str("g")); |
| 7379 } |
| 7380 |
| 7381 |
| 7382 THREADED_TEST(CallICFastApi_DirectCall_Throw) { |
| 7383 v8::HandleScope scope; |
| 7384 LocalContext context; |
| 7385 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New(); |
| 7386 nativeobject_templ->Set("callback", |
| 7387 v8::FunctionTemplate::New(ThrowingDirectApiCallback)); |
| 7388 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); |
| 7389 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); |
| 7390 // call the api function multiple times to ensure direct call stub creation. |
| 7391 v8::Handle<Value> result = CompileRun( |
| 7392 "var result = '';" |
| 7393 "function f() {" |
| 7394 " for (var i = 1; i <= 5; i++) {" |
| 7395 " try { nativeobject.callback(); } catch (e) { result += e; }" |
| 7396 " }" |
| 7397 "}" |
| 7398 "f(); result;"); |
| 7399 CHECK_EQ(v8_str("ggggg"), result); |
| 7400 } |
| 7401 |
| 7402 |
7348 THREADED_TEST(InterceptorCallICFastApi_TrivialSignature) { | 7403 THREADED_TEST(InterceptorCallICFastApi_TrivialSignature) { |
7349 int interceptor_call_count = 0; | 7404 int interceptor_call_count = 0; |
7350 v8::HandleScope scope; | 7405 v8::HandleScope scope; |
7351 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 7406 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
7352 v8::Handle<v8::FunctionTemplate> method_templ = | 7407 v8::Handle<v8::FunctionTemplate> method_templ = |
7353 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature, | 7408 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature, |
7354 v8_str("method_data"), | 7409 v8_str("method_data"), |
7355 v8::Handle<v8::Signature>()); | 7410 v8::Handle<v8::Signature>()); |
7356 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 7411 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
7357 proto_templ->Set(v8_str("method"), method_templ); | 7412 proto_templ->Set(v8_str("method"), method_templ); |
(...skipping 4862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12220 v8::Context::Scope context_scope(context.local()); | 12275 v8::Context::Scope context_scope(context.local()); |
12221 | 12276 |
12222 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(); | 12277 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(); |
12223 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); | 12278 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); |
12224 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); | 12279 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); |
12225 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( | 12280 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( |
12226 "var result = []; for (var k in o) result.push(k); result")); | 12281 "var result = []; for (var k in o) result.push(k); result")); |
12227 CHECK_EQ(1, result->Length()); | 12282 CHECK_EQ(1, result->Length()); |
12228 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); | 12283 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); |
12229 } | 12284 } |
OLD | NEW |