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

Side by Side Diff: test/cctest/test-object-observe.cc

Issue 11802003: Add API for access checks on observed objects (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 11 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') | no next file » | 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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 " objArr.push({});" 212 " objArr.push({});"
213 " Object.observe(objArr[objArr.length-1], function(){});" 213 " Object.observe(objArr[objArr.length-1], function(){});"
214 "}" 214 "}"
215 "Object.observe(obj, observer);"); 215 "Object.observe(obj, observer);");
216 } 216 }
217 // obj is now marked "is_observed", but our map has moved. 217 // obj is now marked "is_observed", but our map has moved.
218 CompileRun("obj.foo = 'bar'"); 218 CompileRun("obj.foo = 'bar'");
219 CHECK(CompileRun("ran")->BooleanValue()); 219 CHECK(CompileRun("ran")->BooleanValue());
220 } 220 }
221 221
222
222 TEST(GlobalObjectObservation) { 223 TEST(GlobalObjectObservation) {
223 HarmonyIsolate isolate; 224 HarmonyIsolate isolate;
224 HandleScope scope; 225 HandleScope scope;
225 LocalContext context; 226 LocalContext context;
226 Handle<Object> global_proxy = context->Global(); 227 Handle<Object> global_proxy = context->Global();
227 Handle<Object> inner_global = global_proxy->GetPrototype().As<Object>(); 228 Handle<Object> inner_global = global_proxy->GetPrototype().As<Object>();
228 CompileRun( 229 CompileRun(
229 "var records = [];" 230 "var records = [];"
230 "var global = this;" 231 "var global = this;"
231 "Object.observe(global, function(r) { [].push.apply(records, r) });" 232 "Object.observe(global, function(r) { [].push.apply(records, r) });"
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 "Object.unobserve(obj, observer);" 391 "Object.unobserve(obj, observer);"
391 "obj.foo = 44;"); 392 "obj.foo = 44;");
392 const RecordExpectation expected_records3[] = { 393 const RecordExpectation expected_records3[] = {
393 { proto, "new", "bar", Handle<Value>() } 394 { proto, "new", "bar", Handle<Value>() }
394 // TODO(adamk): The below record should be emitted since proto is observed 395 // TODO(adamk): The below record should be emitted since proto is observed
395 // and has been modified. Not clear if this happens in practice. 396 // and has been modified. Not clear if this happens in practice.
396 // { proto, "updated", "foo", Number::New(43) } 397 // { proto, "updated", "foo", Number::New(43) }
397 }; 398 };
398 EXPECT_RECORDS(CompileRun("records"), expected_records3); 399 EXPECT_RECORDS(CompileRun("records"), expected_records3);
399 } 400 }
401
402
403 static bool NamedAccessAlwaysAllowed(Local<Object> host, Local<Value> key,
404 AccessType type, Local<Value> data) {
405 return true;
406 }
407
408 static bool IndexedAccessAlwaysAllowed(Local<Object> host, uint32_t index,
409 AccessType type, Local<Value> data) {
410 return true;
411 }
412
413 static bool ObservationAlwaysDisallowed(Local<Object> host, Local<Value> data) {
414 return false;
415 }
416
417 TEST(ObserveWithAccessChecks) {
418 HarmonyIsolate isolate;
419 HandleScope scope;
420 LocalContext context;
421 Handle<ObjectTemplate> tmpl = ObjectTemplate::New();
422 tmpl->SetAccessCheckCallbacks(NamedAccessAlwaysAllowed,
423 IndexedAccessAlwaysAllowed,
424 ObservationAlwaysDisallowed);
425 Handle<Object> instance = tmpl->NewInstance();
426 context->Global()->Set(String::New("obj"), instance);
427 TryCatch try_catch;
428 CompileRun("var records = null;"
429 "Object.observe(obj, function(r) { records = r });");
430 CHECK(try_catch.HasCaught());
431 CompileRun("obj.foo = 'bar'");
432 CHECK(CompileRun("records")->IsNull());
433 }
434
435 TEST(ObserveWithAccessChecksDeprecatedAPI) {
436 HarmonyIsolate isolate;
437 HandleScope scope;
438 LocalContext context;
439 Handle<ObjectTemplate> tmpl = ObjectTemplate::New();
440 tmpl->SetAccessCheckCallbacks(NamedAccessAlwaysAllowed,
441 IndexedAccessAlwaysAllowed);
442 Handle<Object> instance = tmpl->NewInstance();
443 context->Global()->Set(String::New("obj"), instance);
444 TryCatch try_catch;
445 CompileRun("var records = null;"
446 "Object.observe(obj, function(r) { records = r });");
447 CHECK(try_catch.HasCaught());
448 CompileRun("obj.foo = 'bar'");
449 CHECK(CompileRun("records")->IsNull());
450 }
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698