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 6726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6737 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); | 6737 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); |
6738 templ->SetClassName(v8_str("Fun")); | 6738 templ->SetClassName(v8_str("Fun")); |
6739 Local<Function> cons = templ->GetFunction(); | 6739 Local<Function> cons = templ->GetFunction(); |
6740 context->Global()->Set(v8_str("Fun"), cons); | 6740 context->Global()->Set(v8_str("Fun"), cons); |
6741 Local<v8::Object> inst = cons->NewInstance(); | 6741 Local<v8::Object> inst = cons->NewInstance(); |
6742 i::Handle<i::JSObject> obj = v8::Utils::OpenHandle(*inst); | 6742 i::Handle<i::JSObject> obj = v8::Utils::OpenHandle(*inst); |
6743 Local<Value> value = CompileRun("(new Fun()).constructor === Fun"); | 6743 Local<Value> value = CompileRun("(new Fun()).constructor === Fun"); |
6744 CHECK(value->BooleanValue()); | 6744 CHECK(value->BooleanValue()); |
6745 } | 6745 } |
6746 | 6746 |
6747 | |
6748 static Handle<Value> ConstructorCallback(const Arguments& args) { | |
6749 ApiTestFuzzer::Fuzz(); | |
6750 if (args[0]->IsInt32()) { | |
6751 Local<Object> This; | |
6752 | |
6753 if (args.IsConstructCall()) { | |
6754 Local<Object> Holder = args.Holder(); | |
6755 This = Object::New(); | |
6756 Local<Value> proto = Holder->GetPrototype(); | |
6757 if (proto->IsObject()) | |
Mads Ager (chromium)
2011/04/28 12:14:42
Use braces around if bodies or make this a one-lin
| |
6758 This->SetPrototype(proto); | |
6759 } else { | |
6760 This = args.This(); | |
6761 } | |
6762 | |
6763 This->Set(v8_str("a"), v8_num(args[0]->Int32Value())); | |
6764 return This; | |
6765 } | |
6766 | |
6767 return args[0]; | |
6768 } | |
6769 | |
6770 | |
6771 THREADED_TEST(ConstructorForObject) { | |
6772 v8::HandleScope handle_scope; | |
6773 LocalContext context; | |
6774 Local<ObjectTemplate> instance_template = ObjectTemplate::New(); | |
6775 instance_template->SetCallAsFunctionHandler(ConstructorCallback); | |
6776 Local<Object> instance = instance_template->NewInstance(); | |
6777 | |
6778 context->Global()->Set(v8_str("obj"), instance); | |
6779 Local<Value> value1 = | |
6780 CompileRun("(function() { var o = new obj(28); return o.a; })()"); | |
6781 CHECK_EQ(28, value1->Int32Value()); | |
6782 | |
6783 Local<Value> args[] = { v8_num(29) }; | |
Mads Ager (chromium)
2011/04/28 12:14:42
Please add more testing. Test calling on a random
| |
6784 Local<Object> object = instance->NewInstance(1, args); | |
6785 Local<Value> value2 = object->Get(v8_str("a")); | |
6786 CHECK_EQ(29, value2->Int32Value()); | |
6787 } | |
6788 | |
6789 | |
6747 THREADED_TEST(FunctionDescriptorException) { | 6790 THREADED_TEST(FunctionDescriptorException) { |
6748 v8::HandleScope handle_scope; | 6791 v8::HandleScope handle_scope; |
6749 LocalContext context; | 6792 LocalContext context; |
6750 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); | 6793 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); |
6751 templ->SetClassName(v8_str("Fun")); | 6794 templ->SetClassName(v8_str("Fun")); |
6752 Local<Function> cons = templ->GetFunction(); | 6795 Local<Function> cons = templ->GetFunction(); |
6753 context->Global()->Set(v8_str("Fun"), cons); | 6796 context->Global()->Set(v8_str("Fun"), cons); |
6754 Local<Value> value = CompileRun( | 6797 Local<Value> value = CompileRun( |
6755 "function test() {" | 6798 "function test() {" |
6756 " try {" | 6799 " try {" |
(...skipping 7259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
14016 { // Check that query wins on disagreement. | 14059 { // Check that query wins on disagreement. |
14017 Handle<ObjectTemplate> templ = ObjectTemplate::New(); | 14060 Handle<ObjectTemplate> templ = ObjectTemplate::New(); |
14018 templ->SetNamedPropertyHandler(HasOwnPropertyNamedPropertyGetter, | 14061 templ->SetNamedPropertyHandler(HasOwnPropertyNamedPropertyGetter, |
14019 0, | 14062 0, |
14020 HasOwnPropertyNamedPropertyQuery2); | 14063 HasOwnPropertyNamedPropertyQuery2); |
14021 Handle<Object> instance = templ->NewInstance(); | 14064 Handle<Object> instance = templ->NewInstance(); |
14022 CHECK(!instance->HasOwnProperty(v8_str("foo"))); | 14065 CHECK(!instance->HasOwnProperty(v8_str("foo"))); |
14023 CHECK(instance->HasOwnProperty(v8_str("bar"))); | 14066 CHECK(instance->HasOwnProperty(v8_str("bar"))); |
14024 } | 14067 } |
14025 } | 14068 } |
OLD | NEW |