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 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); | |
antonm
2011/02/02 13:56:28
looks like you shouldn't use this global any more.
Zaheer
2011/02/03 07:27:31
Done.
| |
7361 LocalContext context; | |
7362 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New(); | |
7363 nativeobject_templ->Set("callback", | |
7364 v8::FunctionTemplate::New(DirectApiCallback)); | |
7365 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); | |
7366 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); | |
7367 // call the api function multiple times to ensure direct call stub creation. | |
7368 CompileRun( | |
7369 "function f() { " | |
7370 " for (var i = 1; i <= 30; i++) { " | |
7371 " nativeobject.callback(); " | |
7372 " } " | |
7373 "} " | |
7374 "f();"); | |
7375 } | |
7376 | |
7348 THREADED_TEST(InterceptorCallICFastApi_TrivialSignature) { | 7377 THREADED_TEST(InterceptorCallICFastApi_TrivialSignature) { |
7349 int interceptor_call_count = 0; | 7378 int interceptor_call_count = 0; |
7350 v8::HandleScope scope; | 7379 v8::HandleScope scope; |
7351 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 7380 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
7352 v8::Handle<v8::FunctionTemplate> method_templ = | 7381 v8::Handle<v8::FunctionTemplate> method_templ = |
7353 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature, | 7382 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature, |
7354 v8_str("method_data"), | 7383 v8_str("method_data"), |
7355 v8::Handle<v8::Signature>()); | 7384 v8::Handle<v8::Signature>()); |
7356 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 7385 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
7357 proto_templ->Set(v8_str("method"), method_templ); | 7386 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()); | 12249 v8::Context::Scope context_scope(context.local()); |
12221 | 12250 |
12222 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(); | 12251 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(); |
12223 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); | 12252 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); |
12224 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); | 12253 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); |
12225 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( | 12254 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( |
12226 "var result = []; for (var k in o) result.push(k); result")); | 12255 "var result = []; for (var k in o) result.push(k); result")); |
12227 CHECK_EQ(1, result->Length()); | 12256 CHECK_EQ(1, result->Length()); |
12228 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); | 12257 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); |
12229 } | 12258 } |
OLD | NEW |