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 4609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4620 | 4620 |
4621 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); | 4621 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); |
4622 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); | 4622 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); |
4623 instance_template->SetCallAsFunctionHandler(call_as_function); | 4623 instance_template->SetCallAsFunctionHandler(call_as_function); |
4624 Local<v8::Object> instance = t->GetFunction()->NewInstance(); | 4624 Local<v8::Object> instance = t->GetFunction()->NewInstance(); |
4625 context->Global()->Set(v8_str("obj"), instance); | 4625 context->Global()->Set(v8_str("obj"), instance); |
4626 v8::TryCatch try_catch; | 4626 v8::TryCatch try_catch; |
4627 Local<Value> value; | 4627 Local<Value> value; |
4628 CHECK(!try_catch.HasCaught()); | 4628 CHECK(!try_catch.HasCaught()); |
4629 | 4629 |
4630 value = Script::Compile(v8_str("obj(42)"))->Run(); | 4630 value = CompileRun("obj(42)"); |
4631 CHECK(!try_catch.HasCaught()); | 4631 CHECK(!try_catch.HasCaught()); |
4632 CHECK_EQ(42, value->Int32Value()); | 4632 CHECK_EQ(42, value->Int32Value()); |
4633 | 4633 |
4634 value = Script::Compile(v8_str("(function(o){return o(49)})(obj)"))->Run(); | 4634 value = CompileRun("(function(o){return o(49)})(obj)"); |
4635 CHECK(!try_catch.HasCaught()); | 4635 CHECK(!try_catch.HasCaught()); |
4636 CHECK_EQ(49, value->Int32Value()); | 4636 CHECK_EQ(49, value->Int32Value()); |
4637 | 4637 |
4638 // test special case of call as function | 4638 // test special case of call as function |
4639 value = Script::Compile(v8_str("[obj]['0'](45)"))->Run(); | 4639 value = CompileRun("[obj]['0'](45)"); |
4640 CHECK(!try_catch.HasCaught()); | 4640 CHECK(!try_catch.HasCaught()); |
4641 CHECK_EQ(45, value->Int32Value()); | 4641 CHECK_EQ(45, value->Int32Value()); |
4642 | 4642 |
4643 value = Script::Compile(v8_str("obj.call = Function.prototype.call;" | 4643 value = CompileRun("obj.call = Function.prototype.call;" |
4644 "obj.call(null, 87)"))->Run(); | 4644 "obj.call(null, 87)"); |
4645 CHECK(!try_catch.HasCaught()); | 4645 CHECK(!try_catch.HasCaught()); |
4646 CHECK_EQ(87, value->Int32Value()); | 4646 CHECK_EQ(87, value->Int32Value()); |
4647 | 4647 |
4648 // Regression tests for bug #1116356: Calling call through call/apply | 4648 // Regression tests for bug #1116356: Calling call through call/apply |
4649 // must work for non-function receivers. | 4649 // must work for non-function receivers. |
4650 const char* apply_99 = "Function.prototype.call.apply(obj, [this, 99])"; | 4650 const char* apply_99 = "Function.prototype.call.apply(obj, [this, 99])"; |
4651 value = Script::Compile(v8_str(apply_99))->Run(); | 4651 value = CompileRun(apply_99); |
4652 CHECK(!try_catch.HasCaught()); | 4652 CHECK(!try_catch.HasCaught()); |
4653 CHECK_EQ(99, value->Int32Value()); | 4653 CHECK_EQ(99, value->Int32Value()); |
4654 | 4654 |
4655 const char* call_17 = "Function.prototype.call.call(obj, this, 17)"; | 4655 const char* call_17 = "Function.prototype.call.call(obj, this, 17)"; |
4656 value = Script::Compile(v8_str(call_17))->Run(); | 4656 value = CompileRun(call_17); |
4657 CHECK(!try_catch.HasCaught()); | 4657 CHECK(!try_catch.HasCaught()); |
4658 CHECK_EQ(17, value->Int32Value()); | 4658 CHECK_EQ(17, value->Int32Value()); |
| 4659 |
| 4660 // Check that the call-as-function handler can be called through |
| 4661 // new. Currently, there is no way to check in the call-as-function |
| 4662 // handler if it has been called through new or not. |
| 4663 value = CompileRun("new obj(42)"); |
| 4664 CHECK(!try_catch.HasCaught()); |
| 4665 CHECK_EQ(42, value->Int32Value()); |
4659 } | 4666 } |
4660 | 4667 |
4661 | 4668 |
4662 static int CountHandles() { | 4669 static int CountHandles() { |
4663 return v8::HandleScope::NumberOfHandles(); | 4670 return v8::HandleScope::NumberOfHandles(); |
4664 } | 4671 } |
4665 | 4672 |
4666 | 4673 |
4667 static int Recurse(int depth, int iterations) { | 4674 static int Recurse(int depth, int iterations) { |
4668 v8::HandleScope scope; | 4675 v8::HandleScope scope; |
(...skipping 1850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6519 // the property | 6526 // the property |
6520 pass_on_get = false; | 6527 pass_on_get = false; |
6521 CHECK_EQ(3, global->Get(some_property)->Int32Value()); | 6528 CHECK_EQ(3, global->Get(some_property)->Int32Value()); |
6522 CHECK_EQ(1, force_set_set_count); | 6529 CHECK_EQ(1, force_set_set_count); |
6523 CHECK_EQ(5, force_set_get_count); | 6530 CHECK_EQ(5, force_set_get_count); |
6524 // The interceptor should also work for other properties | 6531 // The interceptor should also work for other properties |
6525 CHECK_EQ(3, global->Get(v8::String::New("b"))->Int32Value()); | 6532 CHECK_EQ(3, global->Get(v8::String::New("b"))->Int32Value()); |
6526 CHECK_EQ(1, force_set_set_count); | 6533 CHECK_EQ(1, force_set_set_count); |
6527 CHECK_EQ(6, force_set_get_count); | 6534 CHECK_EQ(6, force_set_get_count); |
6528 } | 6535 } |
OLD | NEW |