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

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

Issue 332863003: Remove AccessControl from AccessorPairs, as it's an invalid usecase of AllCan* (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 6 months 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
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/runtime-gen/setaccessorproperty.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 9001 matching lines...) Expand 10 before | Expand all | Expand 10 after
9012 9012
9013 static bool IndexedAccessBlocker(Local<v8::Object> global, 9013 static bool IndexedAccessBlocker(Local<v8::Object> global,
9014 uint32_t key, 9014 uint32_t key,
9015 v8::AccessType type, 9015 v8::AccessType type,
9016 Local<Value> data) { 9016 Local<Value> data) {
9017 return CcTest::isolate()->GetCurrentContext()->Global()->Equals(global) || 9017 return CcTest::isolate()->GetCurrentContext()->Global()->Equals(global) ||
9018 allowed_access_type[type]; 9018 allowed_access_type[type];
9019 } 9019 }
9020 9020
9021 9021
9022 static int g_echo_value_1 = -1; 9022 static int g_echo_value = -1;
9023 static int g_echo_value_2 = -1;
9024 9023
9025 9024
9026 static void EchoGetter( 9025 static void EchoGetter(
9027 Local<String> name, 9026 Local<String> name,
9028 const v8::PropertyCallbackInfo<v8::Value>& info) { 9027 const v8::PropertyCallbackInfo<v8::Value>& info) {
9029 info.GetReturnValue().Set(v8_num(g_echo_value_1)); 9028 info.GetReturnValue().Set(v8_num(g_echo_value));
9030 } 9029 }
9031 9030
9032 9031
9033 static void EchoGetter(const v8::FunctionCallbackInfo<v8::Value>& info) {
9034 info.GetReturnValue().Set(v8_num(g_echo_value_2));
9035 }
9036
9037
9038 static void EchoSetter(Local<String> name, 9032 static void EchoSetter(Local<String> name,
9039 Local<Value> value, 9033 Local<Value> value,
9040 const v8::PropertyCallbackInfo<void>&) { 9034 const v8::PropertyCallbackInfo<void>&) {
9041 if (value->IsNumber()) 9035 if (value->IsNumber())
9042 g_echo_value_1 = value->Int32Value(); 9036 g_echo_value = value->Int32Value();
9043 } 9037 }
9044 9038
9045 9039
9046 static void EchoSetter(const v8::FunctionCallbackInfo<v8::Value>& info) {
9047 v8::Handle<v8::Value> value = info[0];
9048 if (value->IsNumber())
9049 g_echo_value_2 = value->Int32Value();
9050 }
9051
9052
9053 static void UnreachableGetter( 9040 static void UnreachableGetter(
9054 Local<String> name, 9041 Local<String> name,
9055 const v8::PropertyCallbackInfo<v8::Value>& info) { 9042 const v8::PropertyCallbackInfo<v8::Value>& info) {
9056 CHECK(false); // This function should not be called.. 9043 CHECK(false); // This function should not be called..
9057 } 9044 }
9058 9045
9059 9046
9060 static void UnreachableSetter(Local<String>, 9047 static void UnreachableSetter(Local<String>,
9061 Local<Value>, 9048 Local<Value>,
9062 const v8::PropertyCallbackInfo<void>&) { 9049 const v8::PropertyCallbackInfo<void>&) {
(...skipping 17 matching lines...) Expand all
9080 IndexedAccessBlocker); 9067 IndexedAccessBlocker);
9081 9068
9082 // Add an accessor accessible by cross-domain JS code. 9069 // Add an accessor accessible by cross-domain JS code.
9083 global_template->SetAccessor( 9070 global_template->SetAccessor(
9084 v8_str("accessible_prop"), 9071 v8_str("accessible_prop"),
9085 EchoGetter, EchoSetter, 9072 EchoGetter, EchoSetter,
9086 v8::Handle<Value>(), 9073 v8::Handle<Value>(),
9087 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); 9074 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE));
9088 9075
9089 9076
9090 global_template->SetAccessorProperty(
9091 v8_str("accessible_js_prop"),
9092 v8::FunctionTemplate::New(isolate, EchoGetter),
9093 v8::FunctionTemplate::New(isolate, EchoSetter),
9094 v8::None,
9095 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE));
9096
9097 // Add an accessor that is not accessible by cross-domain JS code. 9077 // Add an accessor that is not accessible by cross-domain JS code.
9098 global_template->SetAccessor(v8_str("blocked_prop"), 9078 global_template->SetAccessor(v8_str("blocked_prop"),
9099 UnreachableGetter, UnreachableSetter, 9079 UnreachableGetter, UnreachableSetter,
9100 v8::Handle<Value>(), 9080 v8::Handle<Value>(),
9101 v8::DEFAULT); 9081 v8::DEFAULT);
9102 9082
9103 global_template->SetAccessorProperty( 9083 global_template->SetAccessorProperty(
9104 v8_str("blocked_js_prop"), 9084 v8_str("blocked_js_prop"),
9105 v8::FunctionTemplate::New(isolate, UnreachableFunction), 9085 v8::FunctionTemplate::New(isolate, UnreachableFunction),
9106 v8::FunctionTemplate::New(isolate, UnreachableFunction), 9086 v8::FunctionTemplate::New(isolate, UnreachableFunction),
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
9215 9195
9216 allowed_access_type[v8::ACCESS_HAS] = false; 9196 allowed_access_type[v8::ACCESS_HAS] = false;
9217 allowed_access_type[v8::ACCESS_GET] = false; 9197 allowed_access_type[v8::ACCESS_GET] = false;
9218 9198
9219 v8::Handle<Value> value; 9199 v8::Handle<Value> value;
9220 9200
9221 // Access accessible property 9201 // Access accessible property
9222 value = CompileRun("other.accessible_prop = 3"); 9202 value = CompileRun("other.accessible_prop = 3");
9223 CHECK(value->IsNumber()); 9203 CHECK(value->IsNumber());
9224 CHECK_EQ(3, value->Int32Value()); 9204 CHECK_EQ(3, value->Int32Value());
9225 CHECK_EQ(3, g_echo_value_1); 9205 CHECK_EQ(3, g_echo_value);
9226
9227 // Access accessible js property
9228 value = CompileRun("other.accessible_js_prop = 3");
9229 CHECK(value->IsNumber());
9230 CHECK_EQ(3, value->Int32Value());
9231 CHECK_EQ(3, g_echo_value_2);
9232 9206
9233 value = CompileRun("other.accessible_prop"); 9207 value = CompileRun("other.accessible_prop");
9234 CHECK(value->IsNumber()); 9208 CHECK(value->IsNumber());
9235 CHECK_EQ(3, value->Int32Value()); 9209 CHECK_EQ(3, value->Int32Value());
9236 9210
9237 value = CompileRun("other.accessible_js_prop");
9238 CHECK(value->IsNumber());
9239 CHECK_EQ(3, value->Int32Value());
9240
9241 value = CompileRun( 9211 value = CompileRun(
9242 "Object.getOwnPropertyDescriptor(other, 'accessible_prop').value"); 9212 "Object.getOwnPropertyDescriptor(other, 'accessible_prop').value");
9243 CHECK(value->IsNumber()); 9213 CHECK(value->IsNumber());
9244 CHECK_EQ(3, value->Int32Value()); 9214 CHECK_EQ(3, value->Int32Value());
9245 9215
9246 value = CompileRun(
9247 "Object.getOwnPropertyDescriptor(other, 'accessible_js_prop').get()");
9248 CHECK(value->IsNumber());
9249 CHECK_EQ(3, value->Int32Value());
9250
9251 value = CompileRun("propertyIsEnumerable.call(other, 'accessible_prop')"); 9216 value = CompileRun("propertyIsEnumerable.call(other, 'accessible_prop')");
9252 CHECK(value->IsTrue()); 9217 CHECK(value->IsTrue());
9253 9218
9254 value = CompileRun("propertyIsEnumerable.call(other, 'accessible_js_prop')");
9255 CHECK(value->IsTrue());
9256
9257 // Enumeration doesn't enumerate accessors from inaccessible objects in 9219 // Enumeration doesn't enumerate accessors from inaccessible objects in
9258 // the prototype chain even if the accessors are in themselves accessible. 9220 // the prototype chain even if the accessors are in themselves accessible.
9259 value = 9221 value =
9260 CompileRun("(function(){var obj = {'__proto__':other};" 9222 CompileRun("(function(){var obj = {'__proto__':other};"
9261 "for (var p in obj)" 9223 "for (var p in obj)"
9262 " if (p == 'accessible_prop' ||" 9224 " if (p == 'accessible_prop' ||"
9263 " p == 'accessible_js_prop' ||"
9264 " p == 'blocked_js_prop' ||" 9225 " p == 'blocked_js_prop' ||"
9265 " p == 'blocked_js_prop') {" 9226 " p == 'blocked_js_prop') {"
9266 " return false;" 9227 " return false;"
9267 " }" 9228 " }"
9268 "return true;})()"); 9229 "return true;})()");
9269 CHECK(value->IsTrue()); 9230 CHECK(value->IsTrue());
9270 9231
9271 context1->Exit(); 9232 context1->Exit();
9272 context0->Exit(); 9233 context0->Exit();
9273 } 9234 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
9328 CompileRun("Object.freeze(other)"); 9289 CompileRun("Object.freeze(other)");
9329 ExpectTrue("Object.isExtensible(other)"); 9290 ExpectTrue("Object.isExtensible(other)");
9330 9291
9331 CompileRun("Object.seal(other)"); 9292 CompileRun("Object.seal(other)");
9332 ExpectTrue("Object.isExtensible(other)"); 9293 ExpectTrue("Object.isExtensible(other)");
9333 9294
9334 // Regression test for issue 1250. 9295 // Regression test for issue 1250.
9335 // Make sure that we can set the accessible accessors value using normal 9296 // Make sure that we can set the accessible accessors value using normal
9336 // assignment. 9297 // assignment.
9337 CompileRun("other.accessible_prop = 42"); 9298 CompileRun("other.accessible_prop = 42");
9338 CHECK_EQ(42, g_echo_value_1); 9299 CHECK_EQ(42, g_echo_value);
9339 9300
9340 v8::Handle<Value> value; 9301 v8::Handle<Value> value;
9341 CompileRun("Object.defineProperty(other, 'accessible_prop', {value: -1})"); 9302 CompileRun("Object.defineProperty(other, 'accessible_prop', {value: -1})");
9342 value = CompileRun("other.accessible_prop == 42"); 9303 value = CompileRun("other.accessible_prop == 42");
9343 CHECK(value->IsTrue()); 9304 CHECK(value->IsTrue());
9344 } 9305 }
9345 9306
9346 9307
9347 static bool GetOwnPropertyNamesNamedBlocker(Local<v8::Object> global, 9308 static bool GetOwnPropertyNamesNamedBlocker(Local<v8::Object> global,
9348 Local<Value> name, 9309 Local<Value> name,
(...skipping 13373 matching lines...) Expand 10 before | Expand all | Expand 10 after
22722 call_eval_context = v8::Context::New(isolate); 22683 call_eval_context = v8::Context::New(isolate);
22723 v8::Context::Scope scope(call_eval_context); 22684 v8::Context::Scope scope(call_eval_context);
22724 call_eval_bound_function = 22685 call_eval_bound_function =
22725 Local<Function>::Cast(CompileRun("eval.bind(this, '1')")); 22686 Local<Function>::Cast(CompileRun("eval.bind(this, '1')"));
22726 } 22687 }
22727 env->Global()->Set(v8_str("CallEval"), 22688 env->Global()->Set(v8_str("CallEval"),
22728 v8::FunctionTemplate::New(isolate, CallEval)->GetFunction()); 22689 v8::FunctionTemplate::New(isolate, CallEval)->GetFunction());
22729 Local<Value> result = CompileRun("CallEval();"); 22690 Local<Value> result = CompileRun("CallEval();");
22730 CHECK_EQ(result, v8::Integer::New(isolate, 1)); 22691 CHECK_EQ(result, v8::Integer::New(isolate, 1));
22731 } 22692 }
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/runtime-gen/setaccessorproperty.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698