| 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 8686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8697 env3->SetSecurityToken(v8_str("bar")); | 8697 env3->SetSecurityToken(v8_str("bar")); |
| 8698 | 8698 |
| 8699 // Check that we do not have access to other.p in env1. |other| is now | 8699 // Check that we do not have access to other.p in env1. |other| is now |
| 8700 // the global object for env3 which has a different security token, | 8700 // the global object for env3 which has a different security token, |
| 8701 // so access should be blocked. | 8701 // so access should be blocked. |
| 8702 result = CompileRun("other.p"); | 8702 result = CompileRun("other.p"); |
| 8703 CHECK(result->IsUndefined()); | 8703 CHECK(result->IsUndefined()); |
| 8704 } | 8704 } |
| 8705 | 8705 |
| 8706 | 8706 |
| 8707 void GetThisX(const v8::FunctionCallbackInfo<v8::Value>& info) { | |
| 8708 info.GetReturnValue().Set( | |
| 8709 info.GetIsolate()->GetCurrentContext()->Global()->Get(v8_str("x"))); | |
| 8710 } | |
| 8711 | |
| 8712 | |
| 8713 TEST(DetachedAccesses) { | 8707 TEST(DetachedAccesses) { |
| 8714 LocalContext env1; | 8708 LocalContext env1; |
| 8715 v8::HandleScope scope(env1->GetIsolate()); | 8709 v8::HandleScope scope(env1->GetIsolate()); |
| 8716 | 8710 |
| 8717 // Create second environment. | 8711 // Create second environment. |
| 8718 Local<ObjectTemplate> inner_global_template = | 8712 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); |
| 8719 FunctionTemplate::New(env1->GetIsolate())->InstanceTemplate(); | |
| 8720 inner_global_template ->SetAccessorProperty( | |
| 8721 v8_str("this_x"), FunctionTemplate::New(env1->GetIsolate(), GetThisX)); | |
| 8722 v8::Local<Context> env2 = | |
| 8723 Context::New(env1->GetIsolate(), NULL, inner_global_template); | |
| 8724 | 8713 |
| 8725 Local<Value> foo = v8_str("foo"); | 8714 Local<Value> foo = v8_str("foo"); |
| 8726 | 8715 |
| 8727 // Set same security token for env1 and env2. | 8716 // Set same security token for env1 and env2. |
| 8728 env1->SetSecurityToken(foo); | 8717 env1->SetSecurityToken(foo); |
| 8729 env2->SetSecurityToken(foo); | 8718 env2->SetSecurityToken(foo); |
| 8730 | 8719 |
| 8731 env1->Global()->Set(v8_str("x"), v8_str("env1_x")); | |
| 8732 | |
| 8733 { | 8720 { |
| 8734 v8::Context::Scope scope(env2); | 8721 v8::Context::Scope scope(env2); |
| 8735 env2->Global()->Set(v8_str("x"), v8_str("env2_x")); | |
| 8736 CompileRun( | 8722 CompileRun( |
| 8737 "function bound_x() { return x; }" | 8723 "var x = 'x';" |
| 8738 "function get_x() { return this.x; }" | 8724 "function get_x() { return this.x; }" |
| 8739 "function get_x_w() { return (function() {return this.x;})(); }"); | 8725 "function get_x_w() { return get_x(); }" |
| 8740 env1->Global()->Set(v8_str("bound_x"), CompileRun("bound_x")); | 8726 ""); |
| 8741 env1->Global()->Set(v8_str("get_x"), CompileRun("get_x")); | 8727 env1->Global()->Set(v8_str("get_x"), CompileRun("get_x")); |
| 8742 env1->Global()->Set(v8_str("get_x_w"), CompileRun("get_x_w")); | 8728 env1->Global()->Set(v8_str("get_x_w"), CompileRun("get_x_w")); |
| 8743 env1->Global()->Set( | |
| 8744 v8_str("this_x"), | |
| 8745 CompileRun("Object.getOwnPropertyDescriptor(this, 'this_x').get")); | |
| 8746 } | 8729 } |
| 8747 | 8730 |
| 8748 Local<Object> env2_global = env2->Global(); | 8731 Local<Object> env2_global = env2->Global(); |
| 8749 env2_global->TurnOnAccessCheck(); | 8732 env2_global->TurnOnAccessCheck(); |
| 8750 env2->DetachGlobal(); | 8733 env2->DetachGlobal(); |
| 8751 | 8734 |
| 8752 Local<Value> result; | 8735 Local<Value> result; |
| 8753 result = CompileRun("bound_x()"); | |
| 8754 CHECK_EQ(v8_str("env2_x"), result); | |
| 8755 result = CompileRun("get_x()"); | 8736 result = CompileRun("get_x()"); |
| 8756 CHECK(result->IsUndefined()); | 8737 CHECK(result->IsUndefined()); |
| 8757 result = CompileRun("get_x_w()"); | 8738 result = CompileRun("get_x_w()"); |
| 8758 CHECK(result->IsUndefined()); | 8739 CHECK(result->IsUndefined()); |
| 8759 result = CompileRun("this_x()"); | |
| 8760 CHECK_EQ(v8_str("env2_x"), result); | |
| 8761 | 8740 |
| 8762 // Reattach env2's proxy | 8741 // Reattach env2's proxy |
| 8763 env2 = Context::New(env1->GetIsolate(), | 8742 env2 = Context::New(env1->GetIsolate(), |
| 8764 0, | 8743 0, |
| 8765 v8::Handle<v8::ObjectTemplate>(), | 8744 v8::Handle<v8::ObjectTemplate>(), |
| 8766 env2_global); | 8745 env2_global); |
| 8767 env2->SetSecurityToken(foo); | 8746 env2->SetSecurityToken(foo); |
| 8768 { | 8747 { |
| 8769 v8::Context::Scope scope(env2); | 8748 v8::Context::Scope scope(env2); |
| 8770 env2->Global()->Set(v8_str("x"), v8_str("env3_x")); | 8749 CompileRun("var x = 'x2';"); |
| 8771 env2->Global()->Set(v8_str("env1"), env1->Global()); | |
| 8772 result = CompileRun( | |
| 8773 "results = [];" | |
| 8774 "for (var i = 0; i < 4; i++ ) {" | |
| 8775 " results.push(env1.bound_x());" | |
| 8776 " results.push(env1.get_x());" | |
| 8777 " results.push(env1.get_x_w());" | |
| 8778 " results.push(env1.this_x());" | |
| 8779 "}" | |
| 8780 "results"); | |
| 8781 Local<v8::Array> results = Local<v8::Array>::Cast(result); | |
| 8782 CHECK_EQ(16, results->Length()); | |
| 8783 for (int i = 0; i < 16; i += 4) { | |
| 8784 CHECK_EQ(v8_str("env2_x"), results->Get(i + 0)); | |
| 8785 CHECK_EQ(v8_str("env1_x"), results->Get(i + 1)); | |
| 8786 CHECK_EQ(v8_str("env3_x"), results->Get(i + 2)); | |
| 8787 CHECK_EQ(v8_str("env2_x"), results->Get(i + 3)); | |
| 8788 } | |
| 8789 } | 8750 } |
| 8790 | 8751 |
| 8791 result = CompileRun( | 8752 result = CompileRun("get_x()"); |
| 8792 "results = [];" | 8753 CHECK(result->IsUndefined()); |
| 8793 "for (var i = 0; i < 4; i++ ) {" | 8754 result = CompileRun("get_x_w()"); |
| 8794 " results.push(bound_x());" | 8755 CHECK_EQ(v8_str("x2"), result); |
| 8795 " results.push(get_x());" | |
| 8796 " results.push(get_x_w());" | |
| 8797 " results.push(this_x());" | |
| 8798 "}" | |
| 8799 "results"); | |
| 8800 Local<v8::Array> results = Local<v8::Array>::Cast(result); | |
| 8801 CHECK_EQ(16, results->Length()); | |
| 8802 for (int i = 0; i < 16; i += 4) { | |
| 8803 CHECK_EQ(v8_str("env2_x"), results->Get(i + 0)); | |
| 8804 CHECK_EQ(v8_str("env3_x"), results->Get(i + 1)); | |
| 8805 CHECK_EQ(v8_str("env3_x"), results->Get(i + 2)); | |
| 8806 CHECK_EQ(v8_str("env2_x"), results->Get(i + 3)); | |
| 8807 } | |
| 8808 | |
| 8809 result = CompileRun( | |
| 8810 "results = [];" | |
| 8811 "for (var i = 0; i < 4; i++ ) {" | |
| 8812 " results.push(this.bound_x());" | |
| 8813 " results.push(this.get_x());" | |
| 8814 " results.push(this.get_x_w());" | |
| 8815 " results.push(this.this_x());" | |
| 8816 "}" | |
| 8817 "results"); | |
| 8818 results = Local<v8::Array>::Cast(result); | |
| 8819 CHECK_EQ(16, results->Length()); | |
| 8820 for (int i = 0; i < 16; i += 4) { | |
| 8821 CHECK_EQ(v8_str("env2_x"), results->Get(i + 0)); | |
| 8822 CHECK_EQ(v8_str("env1_x"), results->Get(i + 1)); | |
| 8823 CHECK_EQ(v8_str("env3_x"), results->Get(i + 2)); | |
| 8824 CHECK_EQ(v8_str("env2_x"), results->Get(i + 3)); | |
| 8825 } | |
| 8826 } | 8756 } |
| 8827 | 8757 |
| 8828 | 8758 |
| 8829 static bool allowed_access_type[v8::ACCESS_KEYS + 1] = { false }; | 8759 static bool allowed_access_type[v8::ACCESS_KEYS + 1] = { false }; |
| 8830 static bool NamedAccessBlocker(Local<v8::Object> global, | 8760 static bool NamedAccessBlocker(Local<v8::Object> global, |
| 8831 Local<Value> name, | 8761 Local<Value> name, |
| 8832 v8::AccessType type, | 8762 v8::AccessType type, |
| 8833 Local<Value> data) { | 8763 Local<Value> data) { |
| 8834 return CcTest::isolate()->GetCurrentContext()->Global()->Equals(global) || | 8764 return CcTest::isolate()->GetCurrentContext()->Global()->Equals(global) || |
| 8835 allowed_access_type[type]; | 8765 allowed_access_type[type]; |
| (...skipping 11337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20173 "Function.prototype.apply.call(func)"); | 20103 "Function.prototype.apply.call(func)"); |
| 20174 TestReceiver(i, foreign_context->Global(), | 20104 TestReceiver(i, foreign_context->Global(), |
| 20175 "Function.prototype.apply.apply(func)"); | 20105 "Function.prototype.apply.apply(func)"); |
| 20176 // Making calls through built-in functions. | 20106 // Making calls through built-in functions. |
| 20177 TestReceiver(i, foreign_context->Global(), "[1].map(func)[0]"); | 20107 TestReceiver(i, foreign_context->Global(), "[1].map(func)[0]"); |
| 20178 // ToString(func()) is func()[0], i.e., the returned this.id. | 20108 // ToString(func()) is func()[0], i.e., the returned this.id. |
| 20179 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/,func)[1]"))); | 20109 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/,func)[1]"))); |
| 20180 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[1]"))); | 20110 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[1]"))); |
| 20181 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]"))); | 20111 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]"))); |
| 20182 | 20112 |
| 20113 // TODO(1547): Make the following also return "i". |
| 20183 // Calling with environment record as base. | 20114 // Calling with environment record as base. |
| 20184 TestReceiver(i, foreign_context->Global(), "func()"); | 20115 TestReceiver(o, context->Global(), "func()"); |
| 20185 // Calling with no base. | 20116 // Calling with no base. |
| 20186 TestReceiver(i, foreign_context->Global(), "(1,func)()"); | 20117 TestReceiver(o, context->Global(), "(1,func)()"); |
| 20187 } | 20118 } |
| 20188 | 20119 |
| 20189 | 20120 |
| 20190 uint8_t callback_fired = 0; | 20121 uint8_t callback_fired = 0; |
| 20191 | 20122 |
| 20192 | 20123 |
| 20193 void CallCompletedCallback1() { | 20124 void CallCompletedCallback1() { |
| 20194 i::OS::Print("Firing callback 1.\n"); | 20125 i::OS::Print("Firing callback 1.\n"); |
| 20195 callback_fired ^= 1; // Toggle first bit. | 20126 callback_fired ^= 1; // Toggle first bit. |
| 20196 } | 20127 } |
| (...skipping 1344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 21541 } | 21472 } |
| 21542 for (int i = 0; i < runs; i++) { | 21473 for (int i = 0; i < runs; i++) { |
| 21543 Local<String> expected; | 21474 Local<String> expected; |
| 21544 if (i != 0) { | 21475 if (i != 0) { |
| 21545 CHECK_EQ(v8_str("escape value"), values[i]); | 21476 CHECK_EQ(v8_str("escape value"), values[i]); |
| 21546 } else { | 21477 } else { |
| 21547 CHECK(values[i].IsEmpty()); | 21478 CHECK(values[i].IsEmpty()); |
| 21548 } | 21479 } |
| 21549 } | 21480 } |
| 21550 } | 21481 } |
| OLD | NEW |