Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: test/cctest/test-api.cc

Issue 111613003: Load the global proxy from the context of the target function. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: don't embed global object or receiver in hydrogen Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 8665 matching lines...) Expand 10 before | Expand all | Expand 10 after
8676 env3->SetSecurityToken(v8_str("bar")); 8676 env3->SetSecurityToken(v8_str("bar"));
8677 8677
8678 // Check that we do not have access to other.p in env1. |other| is now 8678 // Check that we do not have access to other.p in env1. |other| is now
8679 // the global object for env3 which has a different security token, 8679 // the global object for env3 which has a different security token,
8680 // so access should be blocked. 8680 // so access should be blocked.
8681 result = CompileRun("other.p"); 8681 result = CompileRun("other.p");
8682 CHECK(result->IsUndefined()); 8682 CHECK(result->IsUndefined());
8683 } 8683 }
8684 8684
8685 8685
8686 void GetThisX(const v8::FunctionCallbackInfo<v8::Value>& info) {
8687 info.GetReturnValue().Set(
8688 info.GetIsolate()->GetCurrentContext()->Global()->Get(v8_str("x")));
8689 }
8690
8691
8686 TEST(DetachedAccesses) { 8692 TEST(DetachedAccesses) {
8687 LocalContext env1; 8693 LocalContext env1;
8688 v8::HandleScope scope(env1->GetIsolate()); 8694 v8::HandleScope scope(env1->GetIsolate());
8689 8695
8690 // Create second environment. 8696 // Create second environment.
8691 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); 8697 Local<ObjectTemplate> inner_global_template =
8698 FunctionTemplate::New(env1->GetIsolate())->InstanceTemplate();
8699 inner_global_template ->SetAccessorProperty(
8700 v8_str("this_x"), FunctionTemplate::New(env1->GetIsolate(), GetThisX));
8701 v8::Local<Context> env2 =
8702 Context::New(env1->GetIsolate(), NULL, inner_global_template);
8692 8703
8693 Local<Value> foo = v8_str("foo"); 8704 Local<Value> foo = v8_str("foo");
8694 8705
8695 // Set same security token for env1 and env2. 8706 // Set same security token for env1 and env2.
8696 env1->SetSecurityToken(foo); 8707 env1->SetSecurityToken(foo);
8697 env2->SetSecurityToken(foo); 8708 env2->SetSecurityToken(foo);
8698 8709
8710 env1->Global()->Set(v8_str("x"), v8_str("env1_x"));
8711
8699 { 8712 {
8700 v8::Context::Scope scope(env2); 8713 v8::Context::Scope scope(env2);
8714 env2->Global()->Set(v8_str("x"), v8_str("env2_x"));
8701 CompileRun( 8715 CompileRun(
8702 "var x = 'x';" 8716 "function bound_x() { return x; }"
8703 "function get_x() { return this.x; }" 8717 "function get_x() { return this.x; }"
8704 "function get_x_w() { return get_x(); }" 8718 "function get_x_w() { return (function() {return this.x;})(); }");
8705 ""); 8719 env1->Global()->Set(v8_str("bound_x"), CompileRun("bound_x"));
8706 env1->Global()->Set(v8_str("get_x"), CompileRun("get_x")); 8720 env1->Global()->Set(v8_str("get_x"), CompileRun("get_x"));
8707 env1->Global()->Set(v8_str("get_x_w"), CompileRun("get_x_w")); 8721 env1->Global()->Set(v8_str("get_x_w"), CompileRun("get_x_w"));
8722 env1->Global()->Set(
8723 v8_str("this_x"),
8724 CompileRun("Object.getOwnPropertyDescriptor(this, 'this_x').get"));
8708 } 8725 }
8709 8726
8710 Local<Object> env2_global = env2->Global(); 8727 Local<Object> env2_global = env2->Global();
8711 env2_global->TurnOnAccessCheck(); 8728 env2_global->TurnOnAccessCheck();
8712 env2->DetachGlobal(); 8729 env2->DetachGlobal();
8713 8730
8714 Local<Value> result; 8731 Local<Value> result;
8732 result = CompileRun("bound_x()");
8733 CHECK_EQ(v8_str("env2_x"), result);
8715 result = CompileRun("get_x()"); 8734 result = CompileRun("get_x()");
8716 CHECK(result->IsUndefined()); 8735 CHECK(result->IsUndefined());
8717 result = CompileRun("get_x_w()"); 8736 result = CompileRun("get_x_w()");
8718 CHECK(result->IsUndefined()); 8737 CHECK(result->IsUndefined());
8738 result = CompileRun("this_x()");
8739 CHECK_EQ(v8_str("env2_x"), result);
8719 8740
8720 // Reattach env2's proxy 8741 // Reattach env2's proxy
8721 env2 = Context::New(env1->GetIsolate(), 8742 env2 = Context::New(env1->GetIsolate(),
8722 0, 8743 0,
8723 v8::Handle<v8::ObjectTemplate>(), 8744 v8::Handle<v8::ObjectTemplate>(),
8724 env2_global); 8745 env2_global);
8725 env2->SetSecurityToken(foo); 8746 env2->SetSecurityToken(foo);
8726 { 8747 {
8727 v8::Context::Scope scope(env2); 8748 v8::Context::Scope scope(env2);
8728 CompileRun("var x = 'x2';"); 8749 env2->Global()->Set(v8_str("x"), v8_str("env3_x"));
8750 env2->Global()->Set(v8_str("env1"), env1->Global());
8751 result = CompileRun(
8752 "results = [];"
8753 "for (var i = 0; i < 4; i++ ) {"
8754 " results.push(env1.bound_x());"
8755 " results.push(env1.get_x());"
8756 " results.push(env1.get_x_w());"
8757 " results.push(env1.this_x());"
8758 "}"
8759 "results");
8760 Local<v8::Array> results = Local<v8::Array>::Cast(result);
8761 CHECK_EQ(16, results->Length());
8762 for (int i = 0; i < 16; i += 4) {
8763 CHECK_EQ(v8_str("env2_x"), results->Get(i + 0));
8764 CHECK_EQ(v8_str("env1_x"), results->Get(i + 1));
8765 CHECK_EQ(v8_str("env3_x"), results->Get(i + 2));
8766 CHECK_EQ(v8_str("env2_x"), results->Get(i + 3));
8767 }
8729 } 8768 }
8730 8769
8731 result = CompileRun("get_x()"); 8770 result = CompileRun(
8732 CHECK(result->IsUndefined()); 8771 "results = [];"
8733 result = CompileRun("get_x_w()"); 8772 "for (var i = 0; i < 4; i++ ) {"
8734 CHECK_EQ(v8_str("x2"), result); 8773 " results.push(bound_x());"
8774 " results.push(get_x());"
8775 " results.push(get_x_w());"
8776 " results.push(this_x());"
8777 "}"
8778 "results");
8779 Local<v8::Array> results = Local<v8::Array>::Cast(result);
8780 CHECK_EQ(16, results->Length());
8781 for (int i = 0; i < 16; i += 4) {
8782 CHECK_EQ(v8_str("env2_x"), results->Get(i + 0));
8783 CHECK_EQ(v8_str("env3_x"), results->Get(i + 1));
8784 CHECK_EQ(v8_str("env3_x"), results->Get(i + 2));
8785 CHECK_EQ(v8_str("env2_x"), results->Get(i + 3));
8786 }
8787
8788 result = CompileRun(
8789 "results = [];"
8790 "for (var i = 0; i < 4; i++ ) {"
8791 " results.push(this.bound_x());"
8792 " results.push(this.get_x());"
8793 " results.push(this.get_x_w());"
8794 " results.push(this.this_x());"
8795 "}"
8796 "results");
8797 results = Local<v8::Array>::Cast(result);
8798 CHECK_EQ(16, results->Length());
8799 for (int i = 0; i < 16; i += 4) {
8800 CHECK_EQ(v8_str("env2_x"), results->Get(i + 0));
8801 CHECK_EQ(v8_str("env1_x"), results->Get(i + 1));
8802 CHECK_EQ(v8_str("env3_x"), results->Get(i + 2));
8803 CHECK_EQ(v8_str("env2_x"), results->Get(i + 3));
8804 }
8735 } 8805 }
8736 8806
8737 8807
8738 static bool allowed_access_type[v8::ACCESS_KEYS + 1] = { false }; 8808 static bool allowed_access_type[v8::ACCESS_KEYS + 1] = { false };
8739 static bool NamedAccessBlocker(Local<v8::Object> global, 8809 static bool NamedAccessBlocker(Local<v8::Object> global,
8740 Local<Value> name, 8810 Local<Value> name,
8741 v8::AccessType type, 8811 v8::AccessType type,
8742 Local<Value> data) { 8812 Local<Value> data) {
8743 return CcTest::isolate()->GetCurrentContext()->Global()->Equals(global) || 8813 return CcTest::isolate()->GetCurrentContext()->Global()->Equals(global) ||
8744 allowed_access_type[type]; 8814 allowed_access_type[type];
(...skipping 11215 matching lines...) Expand 10 before | Expand all | Expand 10 after
19960 "Function.prototype.apply.call(func)"); 20030 "Function.prototype.apply.call(func)");
19961 TestReceiver(i, foreign_context->Global(), 20031 TestReceiver(i, foreign_context->Global(),
19962 "Function.prototype.apply.apply(func)"); 20032 "Function.prototype.apply.apply(func)");
19963 // Making calls through built-in functions. 20033 // Making calls through built-in functions.
19964 TestReceiver(i, foreign_context->Global(), "[1].map(func)[0]"); 20034 TestReceiver(i, foreign_context->Global(), "[1].map(func)[0]");
19965 // ToString(func()) is func()[0], i.e., the returned this.id. 20035 // ToString(func()) is func()[0], i.e., the returned this.id.
19966 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/,func)[1]"))); 20036 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/,func)[1]")));
19967 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[1]"))); 20037 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[1]")));
19968 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]"))); 20038 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]")));
19969 20039
19970 // TODO(1547): Make the following also return "i".
19971 // Calling with environment record as base. 20040 // Calling with environment record as base.
19972 TestReceiver(o, context->Global(), "func()"); 20041 TestReceiver(i, foreign_context->Global(), "func()");
19973 // Calling with no base. 20042 // Calling with no base.
19974 TestReceiver(o, context->Global(), "(1,func)()"); 20043 TestReceiver(i, foreign_context->Global(), "(1,func)()");
19975 } 20044 }
19976 20045
19977 20046
19978 uint8_t callback_fired = 0; 20047 uint8_t callback_fired = 0;
19979 20048
19980 20049
19981 void CallCompletedCallback1() { 20050 void CallCompletedCallback1() {
19982 i::OS::Print("Firing callback 1.\n"); 20051 i::OS::Print("Firing callback 1.\n");
19983 callback_fired ^= 1; // Toggle first bit. 20052 callback_fired ^= 1; // Toggle first bit.
19984 } 20053 }
(...skipping 1090 matching lines...) Expand 10 before | Expand all | Expand 10 after
21075 } 21144 }
21076 for (int i = 0; i < runs; i++) { 21145 for (int i = 0; i < runs; i++) {
21077 Local<String> expected; 21146 Local<String> expected;
21078 if (i != 0) { 21147 if (i != 0) {
21079 CHECK_EQ(v8_str("escape value"), values[i]); 21148 CHECK_EQ(v8_str("escape value"), values[i]);
21080 } else { 21149 } else {
21081 CHECK(values[i].IsEmpty()); 21150 CHECK(values[i].IsEmpty());
21082 } 21151 }
21083 } 21152 }
21084 } 21153 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698