Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: test/cctest/test-api.cc

Issue 6606006: [Isolates] Merge 6500:6700 from bleeding_edge to isolates. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: '' Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/cctest.status ('k') | test/cctest/test-assembler-arm.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2350 matching lines...) Expand 10 before | Expand all | Expand 10 after
2361 2361
2362 2362
2363 static void check_reference_error_message( 2363 static void check_reference_error_message(
2364 v8::Handle<v8::Message> message, 2364 v8::Handle<v8::Message> message,
2365 v8::Handle<v8::Value> data) { 2365 v8::Handle<v8::Value> data) {
2366 const char* reference_error = "Uncaught ReferenceError: asdf is not defined"; 2366 const char* reference_error = "Uncaught ReferenceError: asdf is not defined";
2367 CHECK(message->Get()->Equals(v8_str(reference_error))); 2367 CHECK(message->Get()->Equals(v8_str(reference_error)));
2368 } 2368 }
2369 2369
2370 2370
2371 // Test that overwritten toString methods are not invoked on uncaught 2371 static v8::Handle<Value> Fail(const v8::Arguments& args) {
2372 // exception formatting. However, they are invoked when performing 2372 ApiTestFuzzer::Fuzz();
2373 // normal error string conversions. 2373 CHECK(false);
2374 return v8::Undefined();
2375 }
2376
2377
2378 // Test that overwritten methods are not invoked on uncaught exception
2379 // formatting. However, they are invoked when performing normal error
2380 // string conversions.
2374 TEST(APIThrowMessageOverwrittenToString) { 2381 TEST(APIThrowMessageOverwrittenToString) {
2375 v8::HandleScope scope; 2382 v8::HandleScope scope;
2376 v8::V8::AddMessageListener(check_reference_error_message); 2383 v8::V8::AddMessageListener(check_reference_error_message);
2377 LocalContext context; 2384 Local<ObjectTemplate> templ = ObjectTemplate::New();
2385 templ->Set(v8_str("fail"), v8::FunctionTemplate::New(Fail));
2386 LocalContext context(NULL, templ);
2387 CompileRun("asdf;");
2388 CompileRun("var limit = {};"
2389 "limit.valueOf = fail;"
2390 "Error.stackTraceLimit = limit;");
2391 CompileRun("asdf");
2392 CompileRun("Array.prototype.pop = fail;");
2393 CompileRun("Object.prototype.hasOwnProperty = fail;");
2394 CompileRun("Object.prototype.toString = function f() { return 'Yikes'; }");
2395 CompileRun("Number.prototype.toString = function f() { return 'Yikes'; }");
2396 CompileRun("String.prototype.toString = function f() { return 'Yikes'; }");
2378 CompileRun("ReferenceError.prototype.toString =" 2397 CompileRun("ReferenceError.prototype.toString ="
2379 " function() { return 'Whoops' }"); 2398 " function() { return 'Whoops' }");
2380 CompileRun("asdf;"); 2399 CompileRun("asdf;");
2381 CompileRun("ReferenceError.prototype.constructor.name = void 0;"); 2400 CompileRun("ReferenceError.prototype.constructor.name = void 0;");
2382 CompileRun("asdf;"); 2401 CompileRun("asdf;");
2383 CompileRun("ReferenceError.prototype.constructor = void 0;"); 2402 CompileRun("ReferenceError.prototype.constructor = void 0;");
2384 CompileRun("asdf;"); 2403 CompileRun("asdf;");
2385 CompileRun("ReferenceError.prototype.__proto__ = new Object();"); 2404 CompileRun("ReferenceError.prototype.__proto__ = new Object();");
2386 CompileRun("asdf;"); 2405 CompileRun("asdf;");
2387 CompileRun("ReferenceError.prototype = new Object();"); 2406 CompileRun("ReferenceError.prototype = new Object();");
(...skipping 2894 matching lines...) Expand 10 before | Expand all | Expand 10 after
5282 // the global object for env2 which has the same security token as env1. 5301 // the global object for env2 which has the same security token as env1.
5283 result = CompileRun("other.p"); 5302 result = CompileRun("other.p");
5284 CHECK(result->IsInt32()); 5303 CHECK(result->IsInt32());
5285 CHECK_EQ(42, result->Int32Value()); 5304 CHECK_EQ(42, result->Int32Value());
5286 5305
5287 env2.Dispose(); 5306 env2.Dispose();
5288 env3.Dispose(); 5307 env3.Dispose();
5289 } 5308 }
5290 5309
5291 5310
5311 static bool allowed_access_type[v8::ACCESS_KEYS + 1] = { false };
5292 static bool NamedAccessBlocker(Local<v8::Object> global, 5312 static bool NamedAccessBlocker(Local<v8::Object> global,
5293 Local<Value> name, 5313 Local<Value> name,
5294 v8::AccessType type, 5314 v8::AccessType type,
5295 Local<Value> data) { 5315 Local<Value> data) {
5296 return Context::GetCurrent()->Global()->Equals(global); 5316 return Context::GetCurrent()->Global()->Equals(global) ||
5317 allowed_access_type[type];
5297 } 5318 }
5298 5319
5299 5320
5300 static bool IndexedAccessBlocker(Local<v8::Object> global, 5321 static bool IndexedAccessBlocker(Local<v8::Object> global,
5301 uint32_t key, 5322 uint32_t key,
5302 v8::AccessType type, 5323 v8::AccessType type,
5303 Local<Value> data) { 5324 Local<Value> data) {
5304 return Context::GetCurrent()->Global()->Equals(global); 5325 return Context::GetCurrent()->Global()->Equals(global) ||
5326 allowed_access_type[type];
5305 } 5327 }
5306 5328
5307 5329
5308 static int g_echo_value = -1; 5330 static int g_echo_value = -1;
5309 static v8::Handle<Value> EchoGetter(Local<String> name, 5331 static v8::Handle<Value> EchoGetter(Local<String> name,
5310 const AccessorInfo& info) { 5332 const AccessorInfo& info) {
5311 return v8_num(g_echo_value); 5333 return v8_num(g_echo_value);
5312 } 5334 }
5313 5335
5314 5336
(...skipping 11 matching lines...) Expand all
5326 return v8::Undefined(); 5348 return v8::Undefined();
5327 } 5349 }
5328 5350
5329 5351
5330 static void UnreachableSetter(Local<String>, Local<Value>, 5352 static void UnreachableSetter(Local<String>, Local<Value>,
5331 const AccessorInfo&) { 5353 const AccessorInfo&) {
5332 CHECK(false); // This function should nto be called. 5354 CHECK(false); // This function should nto be called.
5333 } 5355 }
5334 5356
5335 5357
5336 THREADED_TEST(AccessControl) { 5358 TEST(AccessControl) {
5337 v8::HandleScope handle_scope; 5359 v8::HandleScope handle_scope;
5338 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 5360 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
5339 5361
5340 global_template->SetAccessCheckCallbacks(NamedAccessBlocker, 5362 global_template->SetAccessCheckCallbacks(NamedAccessBlocker,
5341 IndexedAccessBlocker); 5363 IndexedAccessBlocker);
5342 5364
5343 // Add an accessor accessible by cross-domain JS code. 5365 // Add an accessor accessible by cross-domain JS code.
5344 global_template->SetAccessor( 5366 global_template->SetAccessor(
5345 v8_str("accessible_prop"), 5367 v8_str("accessible_prop"),
5346 EchoGetter, EchoSetter, 5368 EchoGetter, EchoSetter,
5347 v8::Handle<Value>(), 5369 v8::Handle<Value>(),
5348 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); 5370 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE));
5349 5371
5350 // Add an accessor that is not accessible by cross-domain JS code. 5372 // Add an accessor that is not accessible by cross-domain JS code.
5351 global_template->SetAccessor(v8_str("blocked_prop"), 5373 global_template->SetAccessor(v8_str("blocked_prop"),
5352 UnreachableGetter, UnreachableSetter, 5374 UnreachableGetter, UnreachableSetter,
5353 v8::Handle<Value>(), 5375 v8::Handle<Value>(),
5354 v8::DEFAULT); 5376 v8::DEFAULT);
5355 5377
5356 // Create an environment 5378 // Create an environment
5357 v8::Persistent<Context> context0 = Context::New(NULL, global_template); 5379 v8::Persistent<Context> context0 = Context::New(NULL, global_template);
5358 context0->Enter(); 5380 context0->Enter();
5359 5381
5360 v8::Handle<v8::Object> global0 = context0->Global(); 5382 v8::Handle<v8::Object> global0 = context0->Global();
5361 5383
5384 // Define a property with JS getter and setter.
5385 CompileRun(
5386 "function getter() { return 'getter'; };\n"
5387 "function setter() { return 'setter'; }\n"
5388 "Object.defineProperty(this, 'js_accessor_p', {get:getter, set:setter})");
5389
5390 Local<Value> getter = global0->Get(v8_str("getter"));
5391 Local<Value> setter = global0->Get(v8_str("setter"));
5392
5393 // And define normal element.
5394 global0->Set(239, v8_str("239"));
5395
5396 // Define an element with JS getter and setter.
5397 CompileRun(
5398 "function el_getter() { return 'el_getter'; };\n"
5399 "function el_setter() { return 'el_setter'; };\n"
5400 "Object.defineProperty(this, '42', {get: el_getter, set: el_setter});");
5401
5402 Local<Value> el_getter = global0->Get(v8_str("el_getter"));
5403 Local<Value> el_setter = global0->Get(v8_str("el_setter"));
5404
5362 v8::HandleScope scope1; 5405 v8::HandleScope scope1;
5363 5406
5364 v8::Persistent<Context> context1 = Context::New(); 5407 v8::Persistent<Context> context1 = Context::New();
5365 context1->Enter(); 5408 context1->Enter();
5366 5409
5367 v8::Handle<v8::Object> global1 = context1->Global(); 5410 v8::Handle<v8::Object> global1 = context1->Global();
5368 global1->Set(v8_str("other"), global0); 5411 global1->Set(v8_str("other"), global0);
5369 5412
5413 // Access blocked property.
5414 CompileRun("other.blocked_prop = 1");
5415
5416 ExpectUndefined("other.blocked_prop");
5417 ExpectUndefined(
5418 "Object.getOwnPropertyDescriptor(other, 'blocked_prop')");
5419 ExpectFalse("propertyIsEnumerable.call(other, 'blocked_prop')");
5420
5421 // Enable ACCESS_HAS
5422 allowed_access_type[v8::ACCESS_HAS] = true;
5423 ExpectUndefined("other.blocked_prop");
5424 // ... and now we can get the descriptor...
5425 ExpectUndefined(
5426 "Object.getOwnPropertyDescriptor(other, 'blocked_prop').value");
5427 // ... and enumerate the property.
5428 ExpectTrue("propertyIsEnumerable.call(other, 'blocked_prop')");
5429 allowed_access_type[v8::ACCESS_HAS] = false;
5430
5431 // Access blocked element.
5432 CompileRun("other[239] = 1");
5433
5434 ExpectUndefined("other[239]");
5435 ExpectUndefined("Object.getOwnPropertyDescriptor(other, '239')");
5436 ExpectFalse("propertyIsEnumerable.call(other, '239')");
5437
5438 // Enable ACCESS_HAS
5439 allowed_access_type[v8::ACCESS_HAS] = true;
5440 ExpectUndefined("other[239]");
5441 // ... and now we can get the descriptor...
5442 ExpectUndefined("Object.getOwnPropertyDescriptor(other, '239').value");
5443 // ... and enumerate the property.
5444 ExpectTrue("propertyIsEnumerable.call(other, '239')");
5445 allowed_access_type[v8::ACCESS_HAS] = false;
5446
5447 // Access a property with JS accessor.
5448 CompileRun("other.js_accessor_p = 2");
5449
5450 ExpectUndefined("other.js_accessor_p");
5451 ExpectUndefined(
5452 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p')");
5453
5454 // Enable ACCESS_HAS.
5455 allowed_access_type[v8::ACCESS_HAS] = true;
5456 ExpectUndefined("other.js_accessor_p");
5457 ExpectUndefined(
5458 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get");
5459 ExpectUndefined(
5460 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set");
5461 ExpectUndefined(
5462 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value");
5463 allowed_access_type[v8::ACCESS_HAS] = false;
5464
5465 // Enable both ACCESS_HAS and ACCESS_GET.
5466 allowed_access_type[v8::ACCESS_HAS] = true;
5467 allowed_access_type[v8::ACCESS_GET] = true;
5468
5469 ExpectString("other.js_accessor_p", "getter");
5470 ExpectObject(
5471 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get", getter);
5472 ExpectUndefined(
5473 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set");
5474 ExpectUndefined(
5475 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value");
5476
5477 allowed_access_type[v8::ACCESS_GET] = false;
5478 allowed_access_type[v8::ACCESS_HAS] = false;
5479
5480 // Enable both ACCESS_HAS and ACCESS_SET.
5481 allowed_access_type[v8::ACCESS_HAS] = true;
5482 allowed_access_type[v8::ACCESS_SET] = true;
5483
5484 ExpectUndefined("other.js_accessor_p");
5485 ExpectUndefined(
5486 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get");
5487 ExpectObject(
5488 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set", setter);
5489 ExpectUndefined(
5490 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value");
5491
5492 allowed_access_type[v8::ACCESS_SET] = false;
5493 allowed_access_type[v8::ACCESS_HAS] = false;
5494
5495 // Enable both ACCESS_HAS, ACCESS_GET and ACCESS_SET.
5496 allowed_access_type[v8::ACCESS_HAS] = true;
5497 allowed_access_type[v8::ACCESS_GET] = true;
5498 allowed_access_type[v8::ACCESS_SET] = true;
5499
5500 ExpectString("other.js_accessor_p", "getter");
5501 ExpectObject(
5502 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get", getter);
5503 ExpectObject(
5504 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set", setter);
5505 ExpectUndefined(
5506 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value");
5507
5508 allowed_access_type[v8::ACCESS_SET] = false;
5509 allowed_access_type[v8::ACCESS_GET] = false;
5510 allowed_access_type[v8::ACCESS_HAS] = false;
5511
5512 // Access an element with JS accessor.
5513 CompileRun("other[42] = 2");
5514
5515 ExpectUndefined("other[42]");
5516 ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42')");
5517
5518 // Enable ACCESS_HAS.
5519 allowed_access_type[v8::ACCESS_HAS] = true;
5520 ExpectUndefined("other[42]");
5521 ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42').get");
5522 ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42').set");
5523 ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42').value");
5524 allowed_access_type[v8::ACCESS_HAS] = false;
5525
5526 // Enable both ACCESS_HAS and ACCESS_GET.
5527 allowed_access_type[v8::ACCESS_HAS] = true;
5528 allowed_access_type[v8::ACCESS_GET] = true;
5529
5530 ExpectString("other[42]", "el_getter");
5531 ExpectObject("Object.getOwnPropertyDescriptor(other, '42').get", el_getter);
5532 ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42').set");
5533 ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42').value");
5534
5535 allowed_access_type[v8::ACCESS_GET] = false;
5536 allowed_access_type[v8::ACCESS_HAS] = false;
5537
5538 // Enable both ACCESS_HAS and ACCESS_SET.
5539 allowed_access_type[v8::ACCESS_HAS] = true;
5540 allowed_access_type[v8::ACCESS_SET] = true;
5541
5542 ExpectUndefined("other[42]");
5543 ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42').get");
5544 ExpectObject("Object.getOwnPropertyDescriptor(other, '42').set", el_setter);
5545 ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42').value");
5546
5547 allowed_access_type[v8::ACCESS_SET] = false;
5548 allowed_access_type[v8::ACCESS_HAS] = false;
5549
5550 // Enable both ACCESS_HAS, ACCESS_GET and ACCESS_SET.
5551 allowed_access_type[v8::ACCESS_HAS] = true;
5552 allowed_access_type[v8::ACCESS_GET] = true;
5553 allowed_access_type[v8::ACCESS_SET] = true;
5554
5555 ExpectString("other[42]", "el_getter");
5556 ExpectObject("Object.getOwnPropertyDescriptor(other, '42').get", el_getter);
5557 ExpectObject("Object.getOwnPropertyDescriptor(other, '42').set", el_setter);
5558 ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42').value");
5559
5560 allowed_access_type[v8::ACCESS_SET] = false;
5561 allowed_access_type[v8::ACCESS_GET] = false;
5562 allowed_access_type[v8::ACCESS_HAS] = false;
5563
5370 v8::Handle<Value> value; 5564 v8::Handle<Value> value;
5371 5565
5372 // Access blocked property
5373 value = v8_compile("other.blocked_prop = 1")->Run();
5374 value = v8_compile("other.blocked_prop")->Run();
5375 CHECK(value->IsUndefined());
5376
5377 value = v8_compile("propertyIsEnumerable.call(other, 'blocked_prop')")->Run();
5378 CHECK(value->IsFalse());
5379
5380 // Access accessible property 5566 // Access accessible property
5381 value = v8_compile("other.accessible_prop = 3")->Run(); 5567 value = CompileRun("other.accessible_prop = 3");
5382 CHECK(value->IsNumber()); 5568 CHECK(value->IsNumber());
5383 CHECK_EQ(3, value->Int32Value()); 5569 CHECK_EQ(3, value->Int32Value());
5384 CHECK_EQ(3, g_echo_value); 5570 CHECK_EQ(3, g_echo_value);
5385 5571
5386 value = v8_compile("other.accessible_prop")->Run(); 5572 value = CompileRun("other.accessible_prop");
5387 CHECK(value->IsNumber()); 5573 CHECK(value->IsNumber());
5388 CHECK_EQ(3, value->Int32Value()); 5574 CHECK_EQ(3, value->Int32Value());
5389 5575
5390 value = 5576 value = CompileRun(
5391 v8_compile("propertyIsEnumerable.call(other, 'accessible_prop')")->Run(); 5577 "Object.getOwnPropertyDescriptor(other, 'accessible_prop').value");
5578 CHECK(value->IsNumber());
5579 CHECK_EQ(3, value->Int32Value());
5580
5581 value = CompileRun("propertyIsEnumerable.call(other, 'accessible_prop')");
5392 CHECK(value->IsTrue()); 5582 CHECK(value->IsTrue());
5393 5583
5394 // Enumeration doesn't enumerate accessors from inaccessible objects in 5584 // Enumeration doesn't enumerate accessors from inaccessible objects in
5395 // the prototype chain even if the accessors are in themselves accessible. 5585 // the prototype chain even if the accessors are in themselves accessible.
5396 Local<Value> result = 5586 value =
5397 CompileRun("(function(){var obj = {'__proto__':other};" 5587 CompileRun("(function(){var obj = {'__proto__':other};"
5398 "for (var p in obj)" 5588 "for (var p in obj)"
5399 " if (p == 'accessible_prop' || p == 'blocked_prop') {" 5589 " if (p == 'accessible_prop' || p == 'blocked_prop') {"
5400 " return false;" 5590 " return false;"
5401 " }" 5591 " }"
5402 "return true;})()"); 5592 "return true;})()");
5403 CHECK(result->IsTrue()); 5593 CHECK(value->IsTrue());
5404 5594
5405 context1->Exit(); 5595 context1->Exit();
5406 context0->Exit(); 5596 context0->Exit();
5407 context1.Dispose(); 5597 context1.Dispose();
5408 context0.Dispose(); 5598 context0.Dispose();
5409 } 5599 }
5410 5600
5411 5601
5412 static bool GetOwnPropertyNamesNamedBlocker(Local<v8::Object> global, 5602 static bool GetOwnPropertyNamesNamedBlocker(Local<v8::Object> global,
5413 Local<Value> name, 5603 Local<Value> name,
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after
6238 Local<Function> cons = templ->GetFunction(); 6428 Local<Function> cons = templ->GetFunction();
6239 context->Global()->Set(v8_str("Fun"), cons); 6429 context->Global()->Set(v8_str("Fun"), cons);
6240 Local<Value> value = CompileRun( 6430 Local<Value> value = CompileRun(
6241 "function test() {" 6431 "function test() {"
6242 " try {" 6432 " try {"
6243 " (new Fun()).blah()" 6433 " (new Fun()).blah()"
6244 " } catch (e) {" 6434 " } catch (e) {"
6245 " var str = String(e);" 6435 " var str = String(e);"
6246 " if (str.indexOf('TypeError') == -1) return 1;" 6436 " if (str.indexOf('TypeError') == -1) return 1;"
6247 " if (str.indexOf('[object Fun]') != -1) return 2;" 6437 " if (str.indexOf('[object Fun]') != -1) return 2;"
6248 " if (str.indexOf('#<a Fun>') == -1) return 3;" 6438 " if (str.indexOf('#<Fun>') == -1) return 3;"
6249 " return 0;" 6439 " return 0;"
6250 " }" 6440 " }"
6251 " return 4;" 6441 " return 4;"
6252 "}" 6442 "}"
6253 "test();"); 6443 "test();");
6254 CHECK_EQ(0, value->Int32Value()); 6444 CHECK_EQ(0, value->Int32Value());
6255 } 6445 }
6256 6446
6257 6447
6258 THREADED_TEST(EvalAliasedDynamic) { 6448 THREADED_TEST(EvalAliasedDynamic) {
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after
7327 // Helper to maximize the odds of object moving. 7517 // Helper to maximize the odds of object moving.
7328 static void GenerateSomeGarbage() { 7518 static void GenerateSomeGarbage() {
7329 CompileRun( 7519 CompileRun(
7330 "var garbage;" 7520 "var garbage;"
7331 "for (var i = 0; i < 1000; i++) {" 7521 "for (var i = 0; i < 1000; i++) {"
7332 " garbage = [1/i, \"garbage\" + i, garbage, {foo: garbage}];" 7522 " garbage = [1/i, \"garbage\" + i, garbage, {foo: garbage}];"
7333 "}" 7523 "}"
7334 "garbage = undefined;"); 7524 "garbage = undefined;");
7335 } 7525 }
7336 7526
7527 v8::Handle<v8::Value> DirectApiCallback(const v8::Arguments& args) {
7528 static int count = 0;
7529 if (count++ % 3 == 0) {
7530 v8::V8::LowMemoryNotification(); // This should move the stub
7531 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed
7532 }
7533 return v8::Handle<v8::Value>();
7534 }
7535
7536
7537 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) {
7538 v8::HandleScope scope;
7539 LocalContext context;
7540 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New();
7541 nativeobject_templ->Set("callback",
7542 v8::FunctionTemplate::New(DirectApiCallback));
7543 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance();
7544 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj);
7545 // call the api function multiple times to ensure direct call stub creation.
7546 CompileRun(
7547 "function f() {"
7548 " for (var i = 1; i <= 30; i++) {"
7549 " nativeobject.callback();"
7550 " }"
7551 "}"
7552 "f();");
7553 }
7554
7555
7556 v8::Handle<v8::Value> ThrowingDirectApiCallback(const v8::Arguments& args) {
7557 return v8::ThrowException(v8_str("g"));
7558 }
7559
7560
7561 THREADED_TEST(CallICFastApi_DirectCall_Throw) {
7562 v8::HandleScope scope;
7563 LocalContext context;
7564 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New();
7565 nativeobject_templ->Set("callback",
7566 v8::FunctionTemplate::New(ThrowingDirectApiCallback));
7567 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance();
7568 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj);
7569 // call the api function multiple times to ensure direct call stub creation.
7570 v8::Handle<Value> result = CompileRun(
7571 "var result = '';"
7572 "function f() {"
7573 " for (var i = 1; i <= 5; i++) {"
7574 " try { nativeobject.callback(); } catch (e) { result += e; }"
7575 " }"
7576 "}"
7577 "f(); result;");
7578 CHECK_EQ(v8_str("ggggg"), result);
7579 }
7580
7581
7337 THREADED_TEST(InterceptorCallICFastApi_TrivialSignature) { 7582 THREADED_TEST(InterceptorCallICFastApi_TrivialSignature) {
7338 int interceptor_call_count = 0; 7583 int interceptor_call_count = 0;
7339 v8::HandleScope scope; 7584 v8::HandleScope scope;
7340 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 7585 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
7341 v8::Handle<v8::FunctionTemplate> method_templ = 7586 v8::Handle<v8::FunctionTemplate> method_templ =
7342 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature, 7587 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature,
7343 v8_str("method_data"), 7588 v8_str("method_data"),
7344 v8::Handle<v8::Signature>()); 7589 v8::Handle<v8::Signature>());
7345 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 7590 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
7346 proto_templ->Set(v8_str("method"), method_templ); 7591 proto_templ->Set(v8_str("method"), method_templ);
(...skipping 3013 matching lines...) Expand 10 before | Expand all | Expand 10 after
10360 10605
10361 // Test for index greater than 255. Regression test for: 10606 // Test for index greater than 255. Regression test for:
10362 // http://code.google.com/p/chromium/issues/detail?id=26337. 10607 // http://code.google.com/p/chromium/issues/detail?id=26337.
10363 result = CompileRun("pixels[256] = 255;"); 10608 result = CompileRun("pixels[256] = 255;");
10364 CHECK_EQ(255, result->Int32Value()); 10609 CHECK_EQ(255, result->Int32Value());
10365 result = CompileRun("var i = 0;" 10610 result = CompileRun("var i = 0;"
10366 "for (var j = 0; j < 8; j++) { i = pixels[256]; }" 10611 "for (var j = 0; j < 8; j++) { i = pixels[256]; }"
10367 "i"); 10612 "i");
10368 CHECK_EQ(255, result->Int32Value()); 10613 CHECK_EQ(255, result->Int32Value());
10369 10614
10615 // Make sure that pixel array ICs recognize when a non-pixel array
10616 // is passed to it.
10617 result = CompileRun("function pa_load(p) {"
10618 " var sum = 0;"
10619 " for (var j = 0; j < 256; j++) { sum += p[j]; }"
10620 " return sum;"
10621 "}"
10622 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
10623 "for (var i = 0; i < 10; ++i) { pa_load(pixels); }"
10624 "just_ints = new Object();"
10625 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }"
10626 "for (var i = 0; i < 10; ++i) {"
10627 " result = pa_load(just_ints);"
10628 "}"
10629 "result");
10630 CHECK_EQ(32640, result->Int32Value());
10631
10632 // Make sure that pixel array ICs recognize out-of-bound accesses.
10633 result = CompileRun("function pa_load(p, start) {"
10634 " var sum = 0;"
10635 " for (var j = start; j < 256; j++) { sum += p[j]; }"
10636 " return sum;"
10637 "}"
10638 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
10639 "for (var i = 0; i < 10; ++i) { pa_load(pixels,0); }"
10640 "for (var i = 0; i < 10; ++i) {"
10641 " result = pa_load(pixels,-10);"
10642 "}"
10643 "result");
10644 CHECK_EQ(0, result->Int32Value());
10645
10646 // Make sure that generic ICs properly handles a pixel array.
10647 result = CompileRun("function pa_load(p) {"
10648 " var sum = 0;"
10649 " for (var j = 0; j < 256; j++) { sum += p[j]; }"
10650 " return sum;"
10651 "}"
10652 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
10653 "just_ints = new Object();"
10654 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }"
10655 "for (var i = 0; i < 10; ++i) { pa_load(just_ints); }"
10656 "for (var i = 0; i < 10; ++i) {"
10657 " result = pa_load(pixels);"
10658 "}"
10659 "result");
10660 CHECK_EQ(32640, result->Int32Value());
10661
10662 // Make sure that generic load ICs recognize out-of-bound accesses in
10663 // pixel arrays.
10664 result = CompileRun("function pa_load(p, start) {"
10665 " var sum = 0;"
10666 " for (var j = start; j < 256; j++) { sum += p[j]; }"
10667 " return sum;"
10668 "}"
10669 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
10670 "just_ints = new Object();"
10671 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }"
10672 "for (var i = 0; i < 10; ++i) { pa_load(just_ints,0); }"
10673 "for (var i = 0; i < 10; ++i) { pa_load(pixels,0); }"
10674 "for (var i = 0; i < 10; ++i) {"
10675 " result = pa_load(pixels,-10);"
10676 "}"
10677 "result");
10678 CHECK_EQ(0, result->Int32Value());
10679
10680 // Make sure that generic ICs properly handles other types than pixel
10681 // arrays (that the inlined fast pixel array test leaves the right information
10682 // in the right registers).
10683 result = CompileRun("function pa_load(p) {"
10684 " var sum = 0;"
10685 " for (var j = 0; j < 256; j++) { sum += p[j]; }"
10686 " return sum;"
10687 "}"
10688 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
10689 "just_ints = new Object();"
10690 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }"
10691 "for (var i = 0; i < 10; ++i) { pa_load(just_ints); }"
10692 "for (var i = 0; i < 10; ++i) { pa_load(pixels); }"
10693 "sparse_array = new Object();"
10694 "for (var i = 0; i < 256; ++i) { sparse_array[i] = i; }"
10695 "sparse_array[1000000] = 3;"
10696 "for (var i = 0; i < 10; ++i) {"
10697 " result = pa_load(sparse_array);"
10698 "}"
10699 "result");
10700 CHECK_EQ(32640, result->Int32Value());
10701
10370 free(pixel_data); 10702 free(pixel_data);
10371 } 10703 }
10372 10704
10373 10705
10374 THREADED_TEST(PixelArrayInfo) { 10706 THREADED_TEST(PixelArrayInfo) {
10375 v8::HandleScope scope; 10707 v8::HandleScope scope;
10376 LocalContext context; 10708 LocalContext context;
10377 for (int size = 0; size < 100; size += 10) { 10709 for (int size = 0; size < 100; size += 10) {
10378 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(size)); 10710 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(size));
10379 v8::Handle<v8::Object> obj = v8::Object::New(); 10711 v8::Handle<v8::Object> obj = v8::Object::New();
(...skipping 2134 matching lines...) Expand 10 before | Expand all | Expand 10 after
12514 v8::Context::Scope context_scope(context.local()); 12846 v8::Context::Scope context_scope(context.local());
12515 12847
12516 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(); 12848 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New();
12517 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); 12849 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator);
12518 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); 12850 context->Global()->Set(v8_str("o"), tmpl->NewInstance());
12519 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( 12851 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun(
12520 "var result = []; for (var k in o) result.push(k); result")); 12852 "var result = []; for (var k in o) result.push(k); result"));
12521 CHECK_EQ(1, result->Length()); 12853 CHECK_EQ(1, result->Length());
12522 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); 12854 CHECK_EQ(v8_str("universalAnswer"), result->Get(0));
12523 } 12855 }
12856
12857
12858 TEST(DefinePropertyPostDetach) {
12859 v8::HandleScope scope;
12860 LocalContext context;
12861 v8::Handle<v8::Object> proxy = context->Global();
12862 v8::Handle<v8::Function> define_property =
12863 CompileRun("(function() {"
12864 " Object.defineProperty("
12865 " this,"
12866 " 1,"
12867 " { configurable: true, enumerable: true, value: 3 });"
12868 "})").As<Function>();
12869 context->DetachGlobal();
12870 define_property->Call(proxy, 0, NULL);
12871 }
OLDNEW
« no previous file with comments | « test/cctest/cctest.status ('k') | test/cctest/test-assembler-arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698