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

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

Issue 22903012: js accessor creation on Template (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: grokdump Created 7 years, 3 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 | « test/cctest/test-accessors.cc ('k') | test/mjsunit/fuzz-natives-part2.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 8239 matching lines...) Expand 10 before | Expand all | Expand 10 after
8250 8250
8251 static bool IndexedAccessBlocker(Local<v8::Object> global, 8251 static bool IndexedAccessBlocker(Local<v8::Object> global,
8252 uint32_t key, 8252 uint32_t key,
8253 v8::AccessType type, 8253 v8::AccessType type,
8254 Local<Value> data) { 8254 Local<Value> data) {
8255 return Context::GetCurrent()->Global()->Equals(global) || 8255 return Context::GetCurrent()->Global()->Equals(global) ||
8256 allowed_access_type[type]; 8256 allowed_access_type[type];
8257 } 8257 }
8258 8258
8259 8259
8260 static int g_echo_value = -1; 8260 static int g_echo_value_1 = -1;
8261 static int g_echo_value_2 = -1;
8262
8263
8261 static void EchoGetter( 8264 static void EchoGetter(
8262 Local<String> name, 8265 Local<String> name,
8263 const v8::PropertyCallbackInfo<v8::Value>& info) { 8266 const v8::PropertyCallbackInfo<v8::Value>& info) {
8264 info.GetReturnValue().Set(v8_num(g_echo_value)); 8267 info.GetReturnValue().Set(v8_num(g_echo_value_1));
8265 } 8268 }
8266 8269
8267 8270
8271 static void EchoGetter(const v8::FunctionCallbackInfo<v8::Value>& info) {
8272 info.GetReturnValue().Set(v8_num(g_echo_value_2));
8273 }
8274
8275
8268 static void EchoSetter(Local<String> name, 8276 static void EchoSetter(Local<String> name,
8269 Local<Value> value, 8277 Local<Value> value,
8270 const v8::PropertyCallbackInfo<void>&) { 8278 const v8::PropertyCallbackInfo<void>&) {
8271 if (value->IsNumber()) 8279 if (value->IsNumber())
8272 g_echo_value = value->Int32Value(); 8280 g_echo_value_1 = value->Int32Value();
8273 } 8281 }
8274 8282
8275 8283
8284 static void EchoSetter(const v8::FunctionCallbackInfo<v8::Value>& info) {
8285 v8::Handle<v8::Value> value = info[0];
8286 if (value->IsNumber())
8287 g_echo_value_2 = value->Int32Value();
8288 }
8289
8290
8276 static void UnreachableGetter( 8291 static void UnreachableGetter(
8277 Local<String> name, 8292 Local<String> name,
8278 const v8::PropertyCallbackInfo<v8::Value>& info) { 8293 const v8::PropertyCallbackInfo<v8::Value>& info) {
8279 CHECK(false); // This function should not be called.. 8294 CHECK(false); // This function should not be called..
8280 } 8295 }
8281 8296
8282 8297
8283 static void UnreachableSetter(Local<String>, 8298 static void UnreachableSetter(Local<String>,
8284 Local<Value>, 8299 Local<Value>,
8285 const v8::PropertyCallbackInfo<void>&) { 8300 const v8::PropertyCallbackInfo<void>&) {
8286 CHECK(false); // This function should nto be called. 8301 CHECK(false); // This function should nto be called.
8287 } 8302 }
8288 8303
8289 8304
8305 static void UnreachableFunction(
8306 const v8::FunctionCallbackInfo<v8::Value>& info) {
8307 CHECK(false); // This function should not be called..
8308 }
8309
8310
8290 TEST(AccessControl) { 8311 TEST(AccessControl) {
8291 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 8312 v8::Isolate* isolate = v8::Isolate::GetCurrent();
8292 v8::HandleScope handle_scope(isolate); 8313 v8::HandleScope handle_scope(isolate);
8293 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 8314 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
8294 8315
8295 global_template->SetAccessCheckCallbacks(NamedAccessBlocker, 8316 global_template->SetAccessCheckCallbacks(NamedAccessBlocker,
8296 IndexedAccessBlocker); 8317 IndexedAccessBlocker);
8297 8318
8298 // Add an accessor accessible by cross-domain JS code. 8319 // Add an accessor accessible by cross-domain JS code.
8299 global_template->SetAccessor( 8320 global_template->SetAccessor(
8300 v8_str("accessible_prop"), 8321 v8_str("accessible_prop"),
8301 EchoGetter, EchoSetter, 8322 EchoGetter, EchoSetter,
8302 v8::Handle<Value>(), 8323 v8::Handle<Value>(),
8303 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); 8324 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE));
8304 8325
8326
8327 global_template->SetAccessorProperty(
8328 v8_str("accessible_js_prop"),
8329 v8::FunctionTemplate::New(EchoGetter),
8330 v8::FunctionTemplate::New(EchoSetter),
8331 v8::None,
8332 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE));
8333
8305 // Add an accessor that is not accessible by cross-domain JS code. 8334 // Add an accessor that is not accessible by cross-domain JS code.
8306 global_template->SetAccessor(v8_str("blocked_prop"), 8335 global_template->SetAccessor(v8_str("blocked_prop"),
8307 UnreachableGetter, UnreachableSetter, 8336 UnreachableGetter, UnreachableSetter,
8308 v8::Handle<Value>(), 8337 v8::Handle<Value>(),
8309 v8::DEFAULT); 8338 v8::DEFAULT);
8310 8339
8340 global_template->SetAccessorProperty(
8341 v8_str("blocked_js_prop"),
8342 v8::FunctionTemplate::New(UnreachableFunction),
8343 v8::FunctionTemplate::New(UnreachableFunction),
8344 v8::None,
8345 v8::DEFAULT);
8346
8311 // Create an environment 8347 // Create an environment
8312 v8::Local<Context> context0 = Context::New(isolate, NULL, global_template); 8348 v8::Local<Context> context0 = Context::New(isolate, NULL, global_template);
8313 context0->Enter(); 8349 context0->Enter();
8314 8350
8315 v8::Handle<v8::Object> global0 = context0->Global(); 8351 v8::Handle<v8::Object> global0 = context0->Global();
8316 8352
8317 // Define a property with JS getter and setter. 8353 // Define a property with JS getter and setter.
8318 CompileRun( 8354 CompileRun(
8319 "function getter() { return 'getter'; };\n" 8355 "function getter() { return 'getter'; };\n"
8320 "function setter() { return 'setter'; }\n" 8356 "function setter() { return 'setter'; }\n"
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
8493 allowed_access_type[v8::ACCESS_SET] = false; 8529 allowed_access_type[v8::ACCESS_SET] = false;
8494 allowed_access_type[v8::ACCESS_GET] = false; 8530 allowed_access_type[v8::ACCESS_GET] = false;
8495 allowed_access_type[v8::ACCESS_HAS] = false; 8531 allowed_access_type[v8::ACCESS_HAS] = false;
8496 8532
8497 v8::Handle<Value> value; 8533 v8::Handle<Value> value;
8498 8534
8499 // Access accessible property 8535 // Access accessible property
8500 value = CompileRun("other.accessible_prop = 3"); 8536 value = CompileRun("other.accessible_prop = 3");
8501 CHECK(value->IsNumber()); 8537 CHECK(value->IsNumber());
8502 CHECK_EQ(3, value->Int32Value()); 8538 CHECK_EQ(3, value->Int32Value());
8503 CHECK_EQ(3, g_echo_value); 8539 CHECK_EQ(3, g_echo_value_1);
8540
8541 // Access accessible js property
8542 value = CompileRun("other.accessible_js_prop = 3");
8543 CHECK(value->IsNumber());
8544 CHECK_EQ(3, value->Int32Value());
8545 CHECK_EQ(3, g_echo_value_2);
8504 8546
8505 value = CompileRun("other.accessible_prop"); 8547 value = CompileRun("other.accessible_prop");
8506 CHECK(value->IsNumber()); 8548 CHECK(value->IsNumber());
8507 CHECK_EQ(3, value->Int32Value()); 8549 CHECK_EQ(3, value->Int32Value());
8508 8550
8551 value = CompileRun("other.accessible_js_prop");
8552 CHECK(value->IsNumber());
8553 CHECK_EQ(3, value->Int32Value());
8554
8509 value = CompileRun( 8555 value = CompileRun(
8510 "Object.getOwnPropertyDescriptor(other, 'accessible_prop').value"); 8556 "Object.getOwnPropertyDescriptor(other, 'accessible_prop').value");
8511 CHECK(value->IsNumber()); 8557 CHECK(value->IsNumber());
8512 CHECK_EQ(3, value->Int32Value()); 8558 CHECK_EQ(3, value->Int32Value());
8513 8559
8560 value = CompileRun(
8561 "Object.getOwnPropertyDescriptor(other, 'accessible_js_prop').get()");
8562 CHECK(value->IsNumber());
8563 CHECK_EQ(3, value->Int32Value());
8564
8514 value = CompileRun("propertyIsEnumerable.call(other, 'accessible_prop')"); 8565 value = CompileRun("propertyIsEnumerable.call(other, 'accessible_prop')");
8515 CHECK(value->IsTrue()); 8566 CHECK(value->IsTrue());
8516 8567
8568 value = CompileRun("propertyIsEnumerable.call(other, 'accessible_js_prop')");
8569 CHECK(value->IsTrue());
8570
8517 // Enumeration doesn't enumerate accessors from inaccessible objects in 8571 // Enumeration doesn't enumerate accessors from inaccessible objects in
8518 // the prototype chain even if the accessors are in themselves accessible. 8572 // the prototype chain even if the accessors are in themselves accessible.
8519 value = 8573 value =
8520 CompileRun("(function(){var obj = {'__proto__':other};" 8574 CompileRun("(function(){var obj = {'__proto__':other};"
8521 "for (var p in obj)" 8575 "for (var p in obj)"
8522 " if (p == 'accessible_prop' || p == 'blocked_prop') {" 8576 " if (p == 'accessible_prop' ||"
8577 " p == 'accessible_js_prop' ||"
8578 " p == 'blocked_js_prop' ||"
8579 " p == 'blocked_js_prop') {"
8523 " return false;" 8580 " return false;"
8524 " }" 8581 " }"
8525 "return true;})()"); 8582 "return true;})()");
8526 CHECK(value->IsTrue()); 8583 CHECK(value->IsTrue());
8527 8584
8528 context1->Exit(); 8585 context1->Exit();
8529 context0->Exit(); 8586 context0->Exit();
8530 } 8587 }
8531 8588
8532 8589
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
8584 CompileRun("Object.freeze(other)"); 8641 CompileRun("Object.freeze(other)");
8585 ExpectTrue("Object.isExtensible(other)"); 8642 ExpectTrue("Object.isExtensible(other)");
8586 8643
8587 CompileRun("Object.seal(other)"); 8644 CompileRun("Object.seal(other)");
8588 ExpectTrue("Object.isExtensible(other)"); 8645 ExpectTrue("Object.isExtensible(other)");
8589 8646
8590 // Regression test for issue 1250. 8647 // Regression test for issue 1250.
8591 // Make sure that we can set the accessible accessors value using normal 8648 // Make sure that we can set the accessible accessors value using normal
8592 // assignment. 8649 // assignment.
8593 CompileRun("other.accessible_prop = 42"); 8650 CompileRun("other.accessible_prop = 42");
8594 CHECK_EQ(42, g_echo_value); 8651 CHECK_EQ(42, g_echo_value_1);
8595 8652
8596 v8::Handle<Value> value; 8653 v8::Handle<Value> value;
8597 // We follow Safari in ignoring assignments to host object accessors. 8654 // We follow Safari in ignoring assignments to host object accessors.
8598 CompileRun("Object.defineProperty(other, 'accessible_prop', {value: -1})"); 8655 CompileRun("Object.defineProperty(other, 'accessible_prop', {value: -1})");
8599 value = CompileRun("other.accessible_prop == 42"); 8656 value = CompileRun("other.accessible_prop == 42");
8600 CHECK(value->IsTrue()); 8657 CHECK(value->IsTrue());
8601 } 8658 }
8602 8659
8603 8660
8604 static bool GetOwnPropertyNamesNamedBlocker(Local<v8::Object> global, 8661 static bool GetOwnPropertyNamesNamedBlocker(Local<v8::Object> global,
(...skipping 11587 matching lines...) Expand 10 before | Expand all | Expand 10 after
20192 CheckCorrectThrow("%GetLocalPropertyNames(other, true)"); 20249 CheckCorrectThrow("%GetLocalPropertyNames(other, true)");
20193 CheckCorrectThrow("%DefineOrRedefineAccessorProperty(" 20250 CheckCorrectThrow("%DefineOrRedefineAccessorProperty("
20194 "other, 'x', null, null, 1)"); 20251 "other, 'x', null, null, 1)");
20195 20252
20196 // Reset the failed access check callback so it does not influence 20253 // Reset the failed access check callback so it does not influence
20197 // the other tests. 20254 // the other tests.
20198 v8::V8::SetFailedAccessCheckCallbackFunction(NULL); 20255 v8::V8::SetFailedAccessCheckCallbackFunction(NULL);
20199 } 20256 }
20200 20257
20201 #endif // WIN32 20258 #endif // WIN32
OLDNEW
« no previous file with comments | « test/cctest/test-accessors.cc ('k') | test/mjsunit/fuzz-natives-part2.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698