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

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

Issue 2286323002: [api] Add documentation for PropertyQueryCallback. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@DocPropertyAttribute
Patch Set: Improve note about triggering in some cases. Created 4 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
« no previous file with comments | « include/v8.h ('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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdlib.h> 5 #include <stdlib.h>
6 6
7 #include "test/cctest/test-api.h" 7 #include "test/cctest/test-api.h"
8 8
9 #include "include/v8-util.h" 9 #include "include/v8-util.h"
10 #include "src/api.h" 10 #include "src/api.h"
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 } 339 }
340 340
341 void InterceptorHasOwnPropertyGetterGC( 341 void InterceptorHasOwnPropertyGetterGC(
342 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { 342 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) {
343 ApiTestFuzzer::Fuzz(); 343 ApiTestFuzzer::Fuzz();
344 CcTest::heap()->CollectAllGarbage(); 344 CcTest::heap()->CollectAllGarbage();
345 } 345 }
346 346
347 } // namespace 347 } // namespace
348 348
349 int query_counter_int = 0;
350
351 namespace {
352 void QueryCallback(Local<Name> property,
353 const v8::PropertyCallbackInfo<v8::Integer>& info) {
354 query_counter_int++;
355 }
356
357 } // namespace
358
359 // Examples that show when the query callback is triggered.
360 THREADED_TEST(QueryInterceptor) {
361 v8::HandleScope scope(CcTest::isolate());
362 v8::Local<v8::FunctionTemplate> templ =
363 v8::FunctionTemplate::New(CcTest::isolate());
364 templ->InstanceTemplate()->SetHandler(
365 v8::NamedPropertyHandlerConfiguration(0, 0, QueryCallback));
366 LocalContext env;
367 env->Global()
368 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local())
369 .ToLocalChecked()
370 ->NewInstance(env.local())
371 .ToLocalChecked())
372 .FromJust();
373 CHECK_EQ(query_counter_int, 0);
374 v8::Local<Value> result =
375 v8_compile("Object.getOwnPropertyDescriptor(obj, 'x');")
376 ->Run(env.local())
377 .ToLocalChecked();
378 CHECK_EQ(query_counter_int, 1);
379 CHECK_EQ(v8::PropertyAttribute::None,
380 static_cast<v8::PropertyAttribute>(
381 result->Int32Value(env.local()).FromJust()));
382
383 v8_compile("Object.defineProperty(obj, 'not_enum', {value: 17});")
384 ->Run(env.local())
385 .ToLocalChecked();
386 CHECK_EQ(query_counter_int, 2);
387
388 v8_compile(
389 "Object.defineProperty(obj, 'enum', {value: 17, enumerable: true, "
390 "writable: true});")
391 ->Run(env.local())
392 .ToLocalChecked();
393 CHECK_EQ(query_counter_int, 3);
394
395 CHECK(v8_compile("obj.propertyIsEnumerable('enum');")
396 ->Run(env.local())
397 .ToLocalChecked()
398 ->BooleanValue(env.local())
399 .FromJust());
400 CHECK_EQ(query_counter_int, 4);
401
402 CHECK(!v8_compile("obj.propertyIsEnumerable('not_enum');")
403 ->Run(env.local())
404 .ToLocalChecked()
405 ->BooleanValue(env.local())
406 .FromJust());
407 CHECK_EQ(query_counter_int, 5);
408
409 CHECK(v8_compile("obj.hasOwnProperty('enum');")
410 ->Run(env.local())
411 .ToLocalChecked()
412 ->BooleanValue(env.local())
413 .FromJust());
414 CHECK_EQ(query_counter_int, 5);
415
416 CHECK(v8_compile("obj.hasOwnProperty('not_enum');")
417 ->Run(env.local())
418 .ToLocalChecked()
419 ->BooleanValue(env.local())
420 .FromJust());
421 CHECK_EQ(query_counter_int, 5);
422
423 CHECK(!v8_compile("obj.hasOwnProperty('x');")
424 ->Run(env.local())
425 .ToLocalChecked()
426 ->BooleanValue(env.local())
427 .FromJust());
428 CHECK_EQ(query_counter_int, 6);
429
430 CHECK(!v8_compile("obj.propertyIsEnumerable('undef');")
431 ->Run(env.local())
432 .ToLocalChecked()
433 ->BooleanValue(env.local())
434 .FromJust());
435 CHECK_EQ(query_counter_int, 7);
436
437 v8_compile("Object.defineProperty(obj, 'enum', {value: 42});")
438 ->Run(env.local())
439 .ToLocalChecked();
440 CHECK_EQ(query_counter_int, 8);
441
442 v8_compile("Object.isFrozen('obj.x');")->Run(env.local()).ToLocalChecked();
443 CHECK_EQ(query_counter_int, 8);
444 }
349 445
350 THREADED_TEST(InterceptorHasOwnProperty) { 446 THREADED_TEST(InterceptorHasOwnProperty) {
351 LocalContext context; 447 LocalContext context;
352 v8::Isolate* isolate = context->GetIsolate(); 448 v8::Isolate* isolate = context->GetIsolate();
353 v8::HandleScope scope(isolate); 449 v8::HandleScope scope(isolate);
354 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate); 450 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate);
355 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); 451 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate();
356 instance_templ->SetHandler( 452 instance_templ->SetHandler(
357 v8::NamedPropertyHandlerConfiguration(InterceptorHasOwnPropertyGetter)); 453 v8::NamedPropertyHandlerConfiguration(InterceptorHasOwnPropertyGetter));
358 Local<Function> function = 454 Local<Function> function =
(...skipping 3626 matching lines...) Expand 10 before | Expand all | Expand 10 after
3985 ->Set(env.local(), v8_str("Fun"), 4081 ->Set(env.local(), v8_str("Fun"),
3986 fun_templ->GetFunction(env.local()).ToLocalChecked()) 4082 fun_templ->GetFunction(env.local()).ToLocalChecked())
3987 .FromJust()); 4083 .FromJust());
3988 4084
3989 CompileRun( 4085 CompileRun(
3990 "var f = new Fun();" 4086 "var f = new Fun();"
3991 "Number.prototype.__proto__ = f;" 4087 "Number.prototype.__proto__ = f;"
3992 "var a = 42;" 4088 "var a = 42;"
3993 "for (var i = 0; i<3; i++) { a.foo; }"); 4089 "for (var i = 0; i<3; i++) { a.foo; }");
3994 } 4090 }
OLDNEW
« no previous file with comments | « include/v8.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698