OLD | NEW |
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 env->Global()->Set(v8_str("obj"), fun); | 626 env->Global()->Set(v8_str("obj"), fun); |
627 Local<Script> script = v8_compile("var s = new obj(); s.x"); | 627 Local<Script> script = v8_compile("var s = new obj(); s.x"); |
628 CHECK_EQ(1, script->Run()->Int32Value()); | 628 CHECK_EQ(1, script->Run()->Int32Value()); |
629 | 629 |
630 Local<Value> result = v8_compile("(new obj()).toString()")->Run(); | 630 Local<Value> result = v8_compile("(new obj()).toString()")->Run(); |
631 CHECK_EQ(v8_str("[object funky]"), result); | 631 CHECK_EQ(v8_str("[object funky]"), result); |
632 } | 632 } |
633 } | 633 } |
634 | 634 |
635 | 635 |
| 636 THREADED_TEST(FindInstanceInPrototypeChain) { |
| 637 v8::HandleScope scope; |
| 638 LocalContext env; |
| 639 |
| 640 Local<v8::FunctionTemplate> base = v8::FunctionTemplate::New(); |
| 641 Local<v8::FunctionTemplate> derived = v8::FunctionTemplate::New(); |
| 642 Local<v8::FunctionTemplate> other = v8::FunctionTemplate::New(); |
| 643 derived->Inherit(base); |
| 644 |
| 645 Local<v8::Function> base_function = base->GetFunction(); |
| 646 Local<v8::Function> derived_function = derived->GetFunction(); |
| 647 Local<v8::Function> other_function = other->GetFunction(); |
| 648 |
| 649 Local<v8::Object> base_instance = base_function->NewInstance(); |
| 650 Local<v8::Object> derived_instance = derived_function->NewInstance(); |
| 651 Local<v8::Object> derived_instance2 = derived_function->NewInstance(); |
| 652 Local<v8::Object> other_instance = other_function->NewInstance(); |
| 653 derived_instance2->Set(v8_str("__proto__"), derived_instance); |
| 654 other_instance->Set(v8_str("__proto__"), derived_instance2); |
| 655 |
| 656 // base_instance is only an instance of base. |
| 657 CHECK_EQ(base_instance, |
| 658 base_instance->FindInstanceInPrototypeChain(base)); |
| 659 CHECK(base_instance->FindInstanceInPrototypeChain(derived).IsEmpty()); |
| 660 CHECK(base_instance->FindInstanceInPrototypeChain(other).IsEmpty()); |
| 661 |
| 662 // derived_instance is an instance of base and derived. |
| 663 CHECK_EQ(derived_instance, |
| 664 derived_instance->FindInstanceInPrototypeChain(base)); |
| 665 CHECK_EQ(derived_instance, |
| 666 derived_instance->FindInstanceInPrototypeChain(derived)); |
| 667 CHECK(derived_instance->FindInstanceInPrototypeChain(other).IsEmpty()); |
| 668 |
| 669 // other_instance is an instance of other and its immediate |
| 670 // prototype derived_instance2 is an instance of base and derived. |
| 671 // Note, derived_instance is an instance of base and derived too, |
| 672 // but it comes after derived_instance2 in the prototype chain of |
| 673 // other_instance. |
| 674 CHECK_EQ(derived_instance2, |
| 675 other_instance->FindInstanceInPrototypeChain(base)); |
| 676 CHECK_EQ(derived_instance2, |
| 677 other_instance->FindInstanceInPrototypeChain(derived)); |
| 678 CHECK_EQ(other_instance, |
| 679 other_instance->FindInstanceInPrototypeChain(other)); |
| 680 } |
| 681 |
| 682 |
636 static v8::Handle<Value> handle_property(Local<String> name, | 683 static v8::Handle<Value> handle_property(Local<String> name, |
637 const AccessorInfo&) { | 684 const AccessorInfo&) { |
638 ApiTestFuzzer::Fuzz(); | 685 ApiTestFuzzer::Fuzz(); |
639 return v8_num(900); | 686 return v8_num(900); |
640 } | 687 } |
641 | 688 |
642 | 689 |
643 THREADED_TEST(PropertyHandler) { | 690 THREADED_TEST(PropertyHandler) { |
644 v8::HandleScope scope; | 691 v8::HandleScope scope; |
645 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 692 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
(...skipping 7038 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7684 | 7731 |
7685 result = CompileRun("pixels[1] = 23;" | 7732 result = CompileRun("pixels[1] = 23;" |
7686 "pixels.__proto__ = [];" | 7733 "pixels.__proto__ = [];" |
7687 "js_array.__proto__ = pixels;" | 7734 "js_array.__proto__ = pixels;" |
7688 "js_array.concat(pixels);"); | 7735 "js_array.concat(pixels);"); |
7689 CHECK_EQ(77, v8::Object::Cast(*result)->Get(v8_str("0"))->Int32Value()); | 7736 CHECK_EQ(77, v8::Object::Cast(*result)->Get(v8_str("0"))->Int32Value()); |
7690 CHECK_EQ(23, v8::Object::Cast(*result)->Get(v8_str("1"))->Int32Value()); | 7737 CHECK_EQ(23, v8::Object::Cast(*result)->Get(v8_str("1"))->Int32Value()); |
7691 | 7738 |
7692 free(pixel_data); | 7739 free(pixel_data); |
7693 } | 7740 } |
OLD | NEW |