OLD | NEW |
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 13611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13622 v8::Handle<v8::Function> define_property = | 13622 v8::Handle<v8::Function> define_property = |
13623 CompileRun("(function() {" | 13623 CompileRun("(function() {" |
13624 " Object.defineProperty(" | 13624 " Object.defineProperty(" |
13625 " this," | 13625 " this," |
13626 " 1," | 13626 " 1," |
13627 " { configurable: true, enumerable: true, value: 3 });" | 13627 " { configurable: true, enumerable: true, value: 3 });" |
13628 "})").As<Function>(); | 13628 "})").As<Function>(); |
13629 context->DetachGlobal(); | 13629 context->DetachGlobal(); |
13630 define_property->Call(proxy, 0, NULL); | 13630 define_property->Call(proxy, 0, NULL); |
13631 } | 13631 } |
| 13632 |
| 13633 |
| 13634 static void InstallContextId(v8::Handle<Context> context, int id) { |
| 13635 Context::Scope scope(context); |
| 13636 CompileRun("Object.prototype").As<Object>()-> |
| 13637 Set(v8_str("context_id"), v8::Integer::New(id)); |
| 13638 } |
| 13639 |
| 13640 |
| 13641 static void CheckContextId(v8::Handle<Object> object, int expected) { |
| 13642 CHECK_EQ(expected, object->Get(v8_str("context_id"))->Int32Value()); |
| 13643 } |
| 13644 |
| 13645 |
| 13646 THREADED_TEST(CreationContext) { |
| 13647 HandleScope handle_scope; |
| 13648 Persistent<Context> context1 = Context::New(); |
| 13649 InstallContextId(context1, 1); |
| 13650 Persistent<Context> context2 = Context::New(); |
| 13651 InstallContextId(context2, 2); |
| 13652 Persistent<Context> context3 = Context::New(); |
| 13653 InstallContextId(context3, 3); |
| 13654 |
| 13655 Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); |
| 13656 |
| 13657 Local<Object> object1; |
| 13658 Local<Function> func1; |
| 13659 { |
| 13660 Context::Scope scope(context1); |
| 13661 object1 = Object::New(); |
| 13662 func1 = tmpl->GetFunction(); |
| 13663 } |
| 13664 |
| 13665 Local<Object> object2; |
| 13666 Local<Function> func2; |
| 13667 { |
| 13668 Context::Scope scope(context2); |
| 13669 object2 = Object::New(); |
| 13670 func2 = tmpl->GetFunction(); |
| 13671 } |
| 13672 |
| 13673 Local<Object> instance1; |
| 13674 Local<Object> instance2; |
| 13675 |
| 13676 { |
| 13677 Context::Scope scope(context3); |
| 13678 instance1 = func1->NewInstance(); |
| 13679 instance2 = func2->NewInstance(); |
| 13680 } |
| 13681 |
| 13682 CHECK(object1->CreationContext() == context1); |
| 13683 CheckContextId(object1, 1); |
| 13684 CHECK(func1->CreationContext() == context1); |
| 13685 CheckContextId(func1, 1); |
| 13686 CHECK(instance1->CreationContext() == context1); |
| 13687 CheckContextId(instance1, 1); |
| 13688 CHECK(object2->CreationContext() == context2); |
| 13689 CheckContextId(object2, 2); |
| 13690 CHECK(func2->CreationContext() == context2); |
| 13691 CheckContextId(func2, 2); |
| 13692 CHECK(instance2->CreationContext() == context2); |
| 13693 CheckContextId(instance2, 2); |
| 13694 |
| 13695 { |
| 13696 Context::Scope scope(context1); |
| 13697 CHECK(object1->CreationContext() == context1); |
| 13698 CheckContextId(object1, 1); |
| 13699 CHECK(func1->CreationContext() == context1); |
| 13700 CheckContextId(func1, 1); |
| 13701 CHECK(instance1->CreationContext() == context1); |
| 13702 CheckContextId(instance1, 1); |
| 13703 CHECK(object2->CreationContext() == context2); |
| 13704 CheckContextId(object2, 2); |
| 13705 CHECK(func2->CreationContext() == context2); |
| 13706 CheckContextId(func2, 2); |
| 13707 CHECK(instance2->CreationContext() == context2); |
| 13708 CheckContextId(instance2, 2); |
| 13709 } |
| 13710 |
| 13711 { |
| 13712 Context::Scope scope(context2); |
| 13713 CHECK(object1->CreationContext() == context1); |
| 13714 CheckContextId(object1, 1); |
| 13715 CHECK(func1->CreationContext() == context1); |
| 13716 CheckContextId(func1, 1); |
| 13717 CHECK(instance1->CreationContext() == context1); |
| 13718 CheckContextId(instance1, 1); |
| 13719 CHECK(object2->CreationContext() == context2); |
| 13720 CheckContextId(object2, 2); |
| 13721 CHECK(func2->CreationContext() == context2); |
| 13722 CheckContextId(func2, 2); |
| 13723 CHECK(instance2->CreationContext() == context2); |
| 13724 CheckContextId(instance2, 2); |
| 13725 } |
| 13726 |
| 13727 context1.Dispose(); |
| 13728 context2.Dispose(); |
| 13729 context3.Dispose(); |
| 13730 } |
OLD | NEW |