OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 7435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7446 Local<Value> proto1 = o1->GetPrototype(); | 7446 Local<Value> proto1 = o1->GetPrototype(); |
7447 CHECK(proto1->IsObject()); | 7447 CHECK(proto1->IsObject()); |
7448 CHECK_EQ(proto1.As<v8::Object>(), o2); | 7448 CHECK_EQ(proto1.As<v8::Object>(), o2); |
7449 | 7449 |
7450 Local<Value> proto2 = o2->GetPrototype(); | 7450 Local<Value> proto2 = o2->GetPrototype(); |
7451 CHECK(proto2->IsObject()); | 7451 CHECK(proto2->IsObject()); |
7452 CHECK_EQ(proto2.As<v8::Object>(), o3); | 7452 CHECK_EQ(proto2.As<v8::Object>(), o3); |
7453 } | 7453 } |
7454 | 7454 |
7455 | 7455 |
| 7456 // Getting property names of an object with a prototype chain that |
| 7457 // triggers dictionary elements in GetLocalPropertyNames() shouldn't |
| 7458 // crash the runtime. |
| 7459 THREADED_TEST(Regress91517) { |
| 7460 i::FLAG_allow_natives_syntax = true; |
| 7461 v8::HandleScope handle_scope; |
| 7462 LocalContext context; |
| 7463 |
| 7464 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(); |
| 7465 t1->SetHiddenPrototype(true); |
| 7466 t1->InstanceTemplate()->Set(v8_str("foo"), v8_num(1)); |
| 7467 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(); |
| 7468 t2->SetHiddenPrototype(true); |
| 7469 t2->InstanceTemplate()->Set(v8_str("fuz1"), v8_num(2)); |
| 7470 t2->InstanceTemplate()->Set(v8_str("objects"), v8::Object::New()); |
| 7471 t2->InstanceTemplate()->Set(v8_str("fuz2"), v8_num(2)); |
| 7472 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(); |
| 7473 t3->SetHiddenPrototype(true); |
| 7474 t3->InstanceTemplate()->Set(v8_str("boo"), v8_num(3)); |
| 7475 Local<v8::FunctionTemplate> t4 = v8::FunctionTemplate::New(); |
| 7476 t4->InstanceTemplate()->Set(v8_str("baz"), v8_num(4)); |
| 7477 |
| 7478 // Force dictionary-based properties. |
| 7479 i::ScopedVector<char> name_buf(1024); |
| 7480 for (int i = 1; i <= 1000; i++) { |
| 7481 i::OS::SNPrintF(name_buf, "sdf%d", i); |
| 7482 t2->InstanceTemplate()->Set(v8_str(name_buf.start()), v8_num(2)); |
| 7483 } |
| 7484 |
| 7485 Local<v8::Object> o1 = t1->GetFunction()->NewInstance(); |
| 7486 Local<v8::Object> o2 = t2->GetFunction()->NewInstance(); |
| 7487 Local<v8::Object> o3 = t3->GetFunction()->NewInstance(); |
| 7488 Local<v8::Object> o4 = t4->GetFunction()->NewInstance(); |
| 7489 |
| 7490 // Create prototype chain of hidden prototypes. |
| 7491 CHECK(o4->SetPrototype(o3)); |
| 7492 CHECK(o3->SetPrototype(o2)); |
| 7493 CHECK(o2->SetPrototype(o1)); |
| 7494 |
| 7495 // Call the runtime version of GetLocalPropertyNames() on the natively |
| 7496 // created object through JavaScript. |
| 7497 context->Global()->Set(v8_str("obj"), o4); |
| 7498 CompileRun("var names = %GetLocalPropertyNames(obj);"); |
| 7499 |
| 7500 ExpectInt32("names.length", 1006); |
| 7501 ExpectTrue("names.indexOf(\"baz\") >= 0"); |
| 7502 ExpectTrue("names.indexOf(\"boo\") >= 0"); |
| 7503 ExpectTrue("names.indexOf(\"foo\") >= 0"); |
| 7504 ExpectTrue("names.indexOf(\"fuz1\") >= 0"); |
| 7505 ExpectTrue("names.indexOf(\"fuz2\") >= 0"); |
| 7506 ExpectFalse("names[1005] == undefined"); |
| 7507 } |
| 7508 |
| 7509 |
7456 THREADED_TEST(FunctionReadOnlyPrototype) { | 7510 THREADED_TEST(FunctionReadOnlyPrototype) { |
7457 v8::HandleScope handle_scope; | 7511 v8::HandleScope handle_scope; |
7458 LocalContext context; | 7512 LocalContext context; |
7459 | 7513 |
7460 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(); | 7514 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(); |
7461 t1->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(42)); | 7515 t1->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(42)); |
7462 t1->ReadOnlyPrototype(); | 7516 t1->ReadOnlyPrototype(); |
7463 context->Global()->Set(v8_str("func1"), t1->GetFunction()); | 7517 context->Global()->Set(v8_str("func1"), t1->GetFunction()); |
7464 // Configured value of ReadOnly flag. | 7518 // Configured value of ReadOnly flag. |
7465 CHECK(CompileRun( | 7519 CHECK(CompileRun( |
(...skipping 8070 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15536 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]"))); | 15590 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]"))); |
15537 | 15591 |
15538 // TODO(1547): Make the following also return "i". | 15592 // TODO(1547): Make the following also return "i". |
15539 // Calling with environment record as base. | 15593 // Calling with environment record as base. |
15540 TestReceiver(o, context->Global(), "func()"); | 15594 TestReceiver(o, context->Global(), "func()"); |
15541 // Calling with no base. | 15595 // Calling with no base. |
15542 TestReceiver(o, context->Global(), "(1,func)()"); | 15596 TestReceiver(o, context->Global(), "(1,func)()"); |
15543 | 15597 |
15544 foreign_context.Dispose(); | 15598 foreign_context.Dispose(); |
15545 } | 15599 } |
OLD | NEW |