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 6590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6601 // the property | 6601 // the property |
6602 pass_on_get = false; | 6602 pass_on_get = false; |
6603 CHECK_EQ(3, global->Get(some_property)->Int32Value()); | 6603 CHECK_EQ(3, global->Get(some_property)->Int32Value()); |
6604 CHECK_EQ(1, force_set_set_count); | 6604 CHECK_EQ(1, force_set_set_count); |
6605 CHECK_EQ(5, force_set_get_count); | 6605 CHECK_EQ(5, force_set_get_count); |
6606 // The interceptor should also work for other properties | 6606 // The interceptor should also work for other properties |
6607 CHECK_EQ(3, global->Get(v8::String::New("b"))->Int32Value()); | 6607 CHECK_EQ(3, global->Get(v8::String::New("b"))->Int32Value()); |
6608 CHECK_EQ(1, force_set_set_count); | 6608 CHECK_EQ(1, force_set_set_count); |
6609 CHECK_EQ(6, force_set_get_count); | 6609 CHECK_EQ(6, force_set_get_count); |
6610 } | 6610 } |
| 6611 |
| 6612 |
| 6613 v8::Persistent<Context> calling_context0; |
| 6614 v8::Persistent<Context> calling_context1; |
| 6615 v8::Persistent<Context> calling_context2; |
| 6616 |
| 6617 |
| 6618 // Check that the call to the callback is initiated in |
| 6619 // calling_context2, the directly calling context is calling_context1 |
| 6620 // and the callback itself is in calling_context0. |
| 6621 static v8::Handle<Value> GetCallingContextCallback(const v8::Arguments& args) { |
| 6622 ApiTestFuzzer::Fuzz(); |
| 6623 CHECK(Context::GetCurrent() == calling_context0); |
| 6624 CHECK(Context::GetCalling() == calling_context1); |
| 6625 CHECK(Context::GetEntered() == calling_context2); |
| 6626 return v8::Integer::New(42); |
| 6627 } |
| 6628 |
| 6629 |
| 6630 THREADED_TEST(GetCallingContext) { |
| 6631 v8::HandleScope scope; |
| 6632 |
| 6633 calling_context0 = Context::New(); |
| 6634 calling_context1 = Context::New(); |
| 6635 calling_context2 = Context::New(); |
| 6636 |
| 6637 // Allow cross-domain access. |
| 6638 Local<String> token = v8_str("<security token>"); |
| 6639 calling_context0->SetSecurityToken(token); |
| 6640 calling_context1->SetSecurityToken(token); |
| 6641 calling_context2->SetSecurityToken(token); |
| 6642 |
| 6643 // Create an object with a C++ callback in context0. |
| 6644 calling_context0->Enter(); |
| 6645 Local<v8::FunctionTemplate> callback_templ = |
| 6646 v8::FunctionTemplate::New(GetCallingContextCallback); |
| 6647 calling_context0->Global()->Set(v8_str("callback"), |
| 6648 callback_templ->GetFunction()); |
| 6649 calling_context0->Exit(); |
| 6650 |
| 6651 // Expose context0 in context1 and setup a function that calls the |
| 6652 // callback function. |
| 6653 calling_context1->Enter(); |
| 6654 calling_context1->Global()->Set(v8_str("context0"), |
| 6655 calling_context0->Global()); |
| 6656 CompileRun("function f() { context0.callback() }"); |
| 6657 calling_context1->Exit(); |
| 6658 |
| 6659 // Expose context1 in context2 and call the callback function in |
| 6660 // context0 indirectly through f in context1. |
| 6661 calling_context2->Enter(); |
| 6662 calling_context2->Global()->Set(v8_str("context1"), |
| 6663 calling_context1->Global()); |
| 6664 CompileRun("context1.f()"); |
| 6665 calling_context2->Exit(); |
| 6666 |
| 6667 // Dispose the contexts to allow them to be garbage collected. |
| 6668 calling_context0.Dispose(); |
| 6669 calling_context1.Dispose(); |
| 6670 calling_context2.Dispose(); |
| 6671 calling_context0.Clear(); |
| 6672 calling_context1.Clear(); |
| 6673 calling_context2.Clear(); |
| 6674 } |
OLD | NEW |