OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 8663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8674 env3->SetSecurityToken(v8_str("bar")); | 8674 env3->SetSecurityToken(v8_str("bar")); |
8675 | 8675 |
8676 // Check that we do not have access to other.p in env1. |other| is now | 8676 // Check that we do not have access to other.p in env1. |other| is now |
8677 // the global object for env3 which has a different security token, | 8677 // the global object for env3 which has a different security token, |
8678 // so access should be blocked. | 8678 // so access should be blocked. |
8679 result = CompileRun("other.p"); | 8679 result = CompileRun("other.p"); |
8680 CHECK(result->IsUndefined()); | 8680 CHECK(result->IsUndefined()); |
8681 } | 8681 } |
8682 | 8682 |
8683 | 8683 |
| 8684 void GetThisX(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 8685 info.GetReturnValue().Set( |
| 8686 info.GetIsolate()->GetCurrentContext()->Global()->Get(v8_str("x"))); |
| 8687 } |
| 8688 |
| 8689 |
8684 TEST(DetachedAccesses) { | 8690 TEST(DetachedAccesses) { |
8685 LocalContext env1; | 8691 LocalContext env1; |
8686 v8::HandleScope scope(env1->GetIsolate()); | 8692 v8::HandleScope scope(env1->GetIsolate()); |
8687 | 8693 |
8688 // Create second environment. | 8694 // Create second environment. |
8689 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); | 8695 Local<ObjectTemplate> inner_global_template = |
| 8696 FunctionTemplate::New(env1->GetIsolate())->InstanceTemplate(); |
| 8697 inner_global_template ->SetAccessorProperty( |
| 8698 v8_str("this_x"), FunctionTemplate::New(env1->GetIsolate(), GetThisX)); |
| 8699 v8::Local<Context> env2 = |
| 8700 Context::New(env1->GetIsolate(), NULL, inner_global_template); |
8690 | 8701 |
8691 Local<Value> foo = v8_str("foo"); | 8702 Local<Value> foo = v8_str("foo"); |
8692 | 8703 |
8693 // Set same security token for env1 and env2. | 8704 // Set same security token for env1 and env2. |
8694 env1->SetSecurityToken(foo); | 8705 env1->SetSecurityToken(foo); |
8695 env2->SetSecurityToken(foo); | 8706 env2->SetSecurityToken(foo); |
8696 | 8707 |
| 8708 env1->Global()->Set(v8_str("x"), v8_str("env1_x")); |
| 8709 |
8697 { | 8710 { |
8698 v8::Context::Scope scope(env2); | 8711 v8::Context::Scope scope(env2); |
| 8712 env2->Global()->Set(v8_str("x"), v8_str("env2_x")); |
8699 CompileRun( | 8713 CompileRun( |
8700 "var x = 'x';" | 8714 "function bound_x() { return x; }" |
8701 "function get_x() { return this.x; }" | 8715 "function get_x() { return this.x; }" |
8702 "function get_x_w() { return get_x(); }" | 8716 "function get_x_w() { return (function() {return this.x;})(); }"); |
8703 ""); | 8717 env1->Global()->Set(v8_str("bound_x"), CompileRun("bound_x")); |
8704 env1->Global()->Set(v8_str("get_x"), CompileRun("get_x")); | 8718 env1->Global()->Set(v8_str("get_x"), CompileRun("get_x")); |
8705 env1->Global()->Set(v8_str("get_x_w"), CompileRun("get_x_w")); | 8719 env1->Global()->Set(v8_str("get_x_w"), CompileRun("get_x_w")); |
| 8720 env1->Global()->Set( |
| 8721 v8_str("this_x"), |
| 8722 CompileRun("Object.getOwnPropertyDescriptor(this, 'this_x').get")); |
8706 } | 8723 } |
8707 | 8724 |
8708 Local<Object> env2_global = env2->Global(); | 8725 Local<Object> env2_global = env2->Global(); |
8709 env2_global->TurnOnAccessCheck(); | 8726 env2_global->TurnOnAccessCheck(); |
8710 env2->DetachGlobal(); | 8727 env2->DetachGlobal(); |
8711 | 8728 |
8712 Local<Value> result; | 8729 Local<Value> result; |
| 8730 result = CompileRun("bound_x()"); |
| 8731 CHECK_EQ(v8_str("env2_x"), result); |
8713 result = CompileRun("get_x()"); | 8732 result = CompileRun("get_x()"); |
8714 CHECK(result->IsUndefined()); | 8733 CHECK(result->IsUndefined()); |
8715 result = CompileRun("get_x_w()"); | 8734 result = CompileRun("get_x_w()"); |
8716 CHECK(result->IsUndefined()); | 8735 CHECK(result->IsUndefined()); |
| 8736 result = CompileRun("this_x()"); |
| 8737 CHECK_EQ(v8_str("env2_x"), result); |
8717 | 8738 |
8718 // Reattach env2's proxy | 8739 // Reattach env2's proxy |
8719 env2 = Context::New(env1->GetIsolate(), | 8740 env2 = Context::New(env1->GetIsolate(), |
8720 0, | 8741 0, |
8721 v8::Handle<v8::ObjectTemplate>(), | 8742 v8::Handle<v8::ObjectTemplate>(), |
8722 env2_global); | 8743 env2_global); |
8723 env2->SetSecurityToken(foo); | 8744 env2->SetSecurityToken(foo); |
8724 { | 8745 { |
8725 v8::Context::Scope scope(env2); | 8746 v8::Context::Scope scope(env2); |
8726 CompileRun("var x = 'x2';"); | 8747 env2->Global()->Set(v8_str("x"), v8_str("env3_x")); |
| 8748 env2->Global()->Set(v8_str("env1"), env1->Global()); |
| 8749 result = CompileRun( |
| 8750 "results = [];" |
| 8751 "for (var i = 0; i < 4; i++ ) {" |
| 8752 " results.push(env1.bound_x());" |
| 8753 " results.push(env1.get_x());" |
| 8754 " results.push(env1.get_x_w());" |
| 8755 " results.push(env1.this_x());" |
| 8756 "}" |
| 8757 "results"); |
| 8758 Local<v8::Array> results = Local<v8::Array>::Cast(result); |
| 8759 CHECK_EQ(16, results->Length()); |
| 8760 for (int i = 0; i < 16; i += 4) { |
| 8761 CHECK_EQ(v8_str("env2_x"), results->Get(i + 0)); |
| 8762 CHECK_EQ(v8_str("env1_x"), results->Get(i + 1)); |
| 8763 CHECK_EQ(v8_str("env3_x"), results->Get(i + 2)); |
| 8764 CHECK_EQ(v8_str("env2_x"), results->Get(i + 3)); |
| 8765 } |
8727 } | 8766 } |
8728 | 8767 |
8729 result = CompileRun("get_x()"); | 8768 result = CompileRun( |
8730 CHECK(result->IsUndefined()); | 8769 "results = [];" |
8731 result = CompileRun("get_x_w()"); | 8770 "for (var i = 0; i < 4; i++ ) {" |
8732 CHECK_EQ(v8_str("x2"), result); | 8771 " results.push(bound_x());" |
| 8772 " results.push(get_x());" |
| 8773 " results.push(get_x_w());" |
| 8774 " results.push(this_x());" |
| 8775 "}" |
| 8776 "results"); |
| 8777 Local<v8::Array> results = Local<v8::Array>::Cast(result); |
| 8778 CHECK_EQ(16, results->Length()); |
| 8779 for (int i = 0; i < 16; i += 4) { |
| 8780 CHECK_EQ(v8_str("env2_x"), results->Get(i + 0)); |
| 8781 CHECK_EQ(v8_str("env3_x"), results->Get(i + 1)); |
| 8782 CHECK_EQ(v8_str("env3_x"), results->Get(i + 2)); |
| 8783 CHECK_EQ(v8_str("env2_x"), results->Get(i + 3)); |
| 8784 } |
| 8785 |
| 8786 result = CompileRun( |
| 8787 "results = [];" |
| 8788 "for (var i = 0; i < 4; i++ ) {" |
| 8789 " results.push(this.bound_x());" |
| 8790 " results.push(this.get_x());" |
| 8791 " results.push(this.get_x_w());" |
| 8792 " results.push(this.this_x());" |
| 8793 "}" |
| 8794 "results"); |
| 8795 results = Local<v8::Array>::Cast(result); |
| 8796 CHECK_EQ(16, results->Length()); |
| 8797 for (int i = 0; i < 16; i += 4) { |
| 8798 CHECK_EQ(v8_str("env2_x"), results->Get(i + 0)); |
| 8799 CHECK_EQ(v8_str("env1_x"), results->Get(i + 1)); |
| 8800 CHECK_EQ(v8_str("env3_x"), results->Get(i + 2)); |
| 8801 CHECK_EQ(v8_str("env2_x"), results->Get(i + 3)); |
| 8802 } |
8733 } | 8803 } |
8734 | 8804 |
8735 | 8805 |
8736 static bool allowed_access_type[v8::ACCESS_KEYS + 1] = { false }; | 8806 static bool allowed_access_type[v8::ACCESS_KEYS + 1] = { false }; |
8737 static bool NamedAccessBlocker(Local<v8::Object> global, | 8807 static bool NamedAccessBlocker(Local<v8::Object> global, |
8738 Local<Value> name, | 8808 Local<Value> name, |
8739 v8::AccessType type, | 8809 v8::AccessType type, |
8740 Local<Value> data) { | 8810 Local<Value> data) { |
8741 return CcTest::isolate()->GetCurrentContext()->Global()->Equals(global) || | 8811 return CcTest::isolate()->GetCurrentContext()->Global()->Equals(global) || |
8742 allowed_access_type[type]; | 8812 allowed_access_type[type]; |
(...skipping 11242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19985 "Function.prototype.apply.call(func)"); | 20055 "Function.prototype.apply.call(func)"); |
19986 TestReceiver(i, foreign_context->Global(), | 20056 TestReceiver(i, foreign_context->Global(), |
19987 "Function.prototype.apply.apply(func)"); | 20057 "Function.prototype.apply.apply(func)"); |
19988 // Making calls through built-in functions. | 20058 // Making calls through built-in functions. |
19989 TestReceiver(i, foreign_context->Global(), "[1].map(func)[0]"); | 20059 TestReceiver(i, foreign_context->Global(), "[1].map(func)[0]"); |
19990 // ToString(func()) is func()[0], i.e., the returned this.id. | 20060 // ToString(func()) is func()[0], i.e., the returned this.id. |
19991 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/,func)[1]"))); | 20061 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/,func)[1]"))); |
19992 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[1]"))); | 20062 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[1]"))); |
19993 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]"))); | 20063 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]"))); |
19994 | 20064 |
19995 // TODO(1547): Make the following also return "i". | |
19996 // Calling with environment record as base. | 20065 // Calling with environment record as base. |
19997 TestReceiver(o, context->Global(), "func()"); | 20066 TestReceiver(i, foreign_context->Global(), "func()"); |
19998 // Calling with no base. | 20067 // Calling with no base. |
19999 TestReceiver(o, context->Global(), "(1,func)()"); | 20068 TestReceiver(i, foreign_context->Global(), "(1,func)()"); |
20000 } | 20069 } |
20001 | 20070 |
20002 | 20071 |
20003 uint8_t callback_fired = 0; | 20072 uint8_t callback_fired = 0; |
20004 | 20073 |
20005 | 20074 |
20006 void CallCompletedCallback1() { | 20075 void CallCompletedCallback1() { |
20007 i::OS::Print("Firing callback 1.\n"); | 20076 i::OS::Print("Firing callback 1.\n"); |
20008 callback_fired ^= 1; // Toggle first bit. | 20077 callback_fired ^= 1; // Toggle first bit. |
20009 } | 20078 } |
(...skipping 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21355 } | 21424 } |
21356 for (int i = 0; i < runs; i++) { | 21425 for (int i = 0; i < runs; i++) { |
21357 Local<String> expected; | 21426 Local<String> expected; |
21358 if (i != 0) { | 21427 if (i != 0) { |
21359 CHECK_EQ(v8_str("escape value"), values[i]); | 21428 CHECK_EQ(v8_str("escape value"), values[i]); |
21360 } else { | 21429 } else { |
21361 CHECK(values[i].IsEmpty()); | 21430 CHECK(values[i].IsEmpty()); |
21362 } | 21431 } |
21363 } | 21432 } |
21364 } | 21433 } |
OLD | NEW |