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

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

Issue 2331223004: [api] Throw in defineProperty() when necessary. (Closed)
Patch Set: Fix formatting. 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
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 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 481
482 bool get_was_called = false; 482 bool get_was_called = false;
483 bool set_was_called = false; 483 bool set_was_called = false;
484 484
485 namespace { 485 namespace {
486 void GetterCallback(Local<Name> property, 486 void GetterCallback(Local<Name> property,
487 const v8::PropertyCallbackInfo<v8::Value>& info) { 487 const v8::PropertyCallbackInfo<v8::Value>& info) {
488 get_was_called = true; 488 get_was_called = true;
489 } 489 }
490 490
491 void SetterCallback(Local<Name> property, Local<Value> value,
492 const v8::PropertyCallbackInfo<v8::Value>& info) {
493 set_was_called = true;
494 }
495
496 } // namespace 491 } // namespace
497 492
498 // Check that get callback is called in defineProperty with accessor descriptor. 493 // Check that get callback is called in defineProperty with accessor descriptor.
499 THREADED_TEST(DefinerCallbackAccessorInterceptor) { 494 THREADED_TEST(DefinerCallbackAccessorInterceptor) {
500 v8::HandleScope scope(CcTest::isolate()); 495 v8::HandleScope scope(CcTest::isolate());
501 v8::Local<v8::FunctionTemplate> templ = 496 v8::Local<v8::FunctionTemplate> templ =
502 v8::FunctionTemplate::New(CcTest::isolate()); 497 v8::FunctionTemplate::New(CcTest::isolate());
503 templ->InstanceTemplate()->SetHandler( 498 templ->InstanceTemplate()->SetHandler(
504 v8::NamedPropertyHandlerConfiguration(GetterCallback, SetterCallback)); 499 v8::NamedPropertyHandlerConfiguration(GetterCallback));
505 LocalContext env; 500 LocalContext env;
506 env->Global() 501 env->Global()
507 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) 502 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local())
508 .ToLocalChecked() 503 .ToLocalChecked()
509 ->NewInstance(env.local()) 504 ->NewInstance(env.local())
510 .ToLocalChecked()) 505 .ToLocalChecked())
511 .FromJust(); 506 .FromJust();
512 507
513 CHECK_EQ(get_was_called, false); 508 CHECK_EQ(get_was_called, false);
514 CHECK_EQ(set_was_called, false);
515 509
516 v8_compile("Object.defineProperty(obj, 'x', {set: function() {return 17;}});") 510 v8_compile("Object.defineProperty(obj, 'x', {set: function() {return 17;}});")
517 ->Run(env.local()) 511 ->Run(env.local())
518 .ToLocalChecked(); 512 .ToLocalChecked();
519 CHECK_EQ(get_was_called, true); 513 CHECK_EQ(get_was_called, true);
520 CHECK_EQ(set_was_called, false);
521 } 514 }
522 515
523 bool get_was_called_in_order = false; 516 bool get_was_called_in_order = false;
524 bool define_was_called_in_order = false; 517 bool define_was_called_in_order = false;
525 518
526 namespace { 519 namespace {
527 520
528 void GetterCallbackOrder(Local<Name> property, 521 void GetterCallbackOrder(Local<Name> property,
529 const v8::PropertyCallbackInfo<v8::Value>& info) { 522 const v8::PropertyCallbackInfo<v8::Value>& info) {
530 get_was_called_in_order = true; 523 get_was_called_in_order = true;
531 CHECK_EQ(define_was_called_in_order, true); 524 CHECK_EQ(define_was_called_in_order, true);
532 info.GetReturnValue().Set(property); 525 info.GetReturnValue().Set(property);
533 } 526 }
534 527
535 void DefinerCallbackOrder(Local<Name> property, 528 void DefinerCallbackOrder(Local<Name> property,
536 const v8::PropertyDescriptor& desc, 529 const v8::PropertyDescriptor& desc,
537 const v8::PropertyCallbackInfo<v8::Value>& info) { 530 const v8::PropertyCallbackInfo<v8::Value>& info) {
538 CHECK_EQ(get_was_called_in_order, false); // Define called before get. 531 CHECK_EQ(get_was_called_in_order, false); // Define called before get.
539 define_was_called_in_order = true; 532 define_was_called_in_order = true;
540 } 533 }
541 534
542 } // namespace 535 } // namespace
543 536
544 // Check that definer callback is called before getter callback. 537 // Check that definer callback is called before getter callback.
545 THREADED_TEST(DefinerCallbackGetAndDefine) { 538 THREADED_TEST(DefinerCallbackGetAndDefine) {
546 v8::HandleScope scope(CcTest::isolate()); 539 v8::HandleScope scope(CcTest::isolate());
547 v8::Local<v8::FunctionTemplate> templ = 540 v8::Local<v8::FunctionTemplate> templ =
548 v8::FunctionTemplate::New(CcTest::isolate()); 541 v8::FunctionTemplate::New(CcTest::isolate());
549 templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration( 542 templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration(
550 GetterCallbackOrder, SetterCallback, 0, 0, 0, DefinerCallbackOrder)); 543 GetterCallbackOrder, 0, 0, 0, 0, DefinerCallbackOrder));
551 LocalContext env; 544 LocalContext env;
552 env->Global() 545 env->Global()
553 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) 546 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local())
554 .ToLocalChecked() 547 .ToLocalChecked()
555 ->NewInstance(env.local()) 548 ->NewInstance(env.local())
556 .ToLocalChecked()) 549 .ToLocalChecked())
557 .FromJust(); 550 .FromJust();
558 551
559 CHECK_EQ(get_was_called_in_order, false); 552 CHECK_EQ(get_was_called_in_order, false);
560 CHECK_EQ(define_was_called_in_order, false); 553 CHECK_EQ(define_was_called_in_order, false);
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after
1315 .ToLocalChecked() 1308 .ToLocalChecked()
1316 ->BooleanValue(env.local()) 1309 ->BooleanValue(env.local())
1317 .FromJust()); 1310 .FromJust());
1318 CHECK(v8_compile("delete obj.myProperty") 1311 CHECK(v8_compile("delete obj.myProperty")
1319 ->Run(env.local()) 1312 ->Run(env.local())
1320 .ToLocalChecked() 1313 .ToLocalChecked()
1321 ->BooleanValue(env.local()) 1314 ->BooleanValue(env.local())
1322 .FromJust()); 1315 .FromJust());
1323 } 1316 }
1324 1317
1318 // See https://bugs.chromium.org/p/chromium/issues/detail?id=645542
1319 THREADED_TEST(PropertySetterCallbackPresentDuringDefineProperty) {
1320 { // defineProperty with a data descriptor is OK in presence of named
1321 // setter callback.
1322 v8::HandleScope scope(CcTest::isolate());
1323 LocalContext env;
1324 v8::Local<v8::FunctionTemplate> templ =
1325 v8::FunctionTemplate::New(CcTest::isolate());
1326 templ->InstanceTemplate()->SetHandler(
1327 v8::NamedPropertyHandlerConfiguration(0, EmptyInterceptorSetter));
1328 env->Global()
1329 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local())
1330 .ToLocalChecked()
1331 ->NewInstance(env.local())
1332 .ToLocalChecked())
1333 .FromJust();
1334 const char* code =
1335 "Object.defineProperty(obj, 'x', {value: 42});"
1336 "obj.x;";
1337 CHECK_EQ(42, v8_compile(code)
1338 ->Run(env.local())
1339 .ToLocalChecked()
1340 ->Int32Value(env.local())
1341 .FromJust());
1342 }
1343
1344 { // defineProperty with a descriptor that is not a data descriptor should
1345 // throw if object has a
1346 // named setter callback.
1347 v8::HandleScope scope(CcTest::isolate());
1348 LocalContext env;
1349 v8::Local<v8::FunctionTemplate> templ =
1350 v8::FunctionTemplate::New(CcTest::isolate());
1351 templ->InstanceTemplate()->SetHandler(
1352 v8::NamedPropertyHandlerConfiguration(0, EmptyInterceptorSetter));
1353 env->Global()
1354 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local())
1355 .ToLocalChecked()
1356 ->NewInstance(env.local())
1357 .ToLocalChecked())
1358 .FromJust();
1359
1360 v8::TryCatch try_catch(env->GetIsolate());
1361 CompileRun("Object.defineProperty(obj, 'x', {get: function() {}});");
1362 CHECK(try_catch.HasCaught());
1363 }
1364
1365 { // defineProperty with a descriptor that is not a data descriptor, e.g.,
1366 // empty descriptor, should throw if object has a named setter callback.
1367 v8::HandleScope scope(CcTest::isolate());
1368 LocalContext env;
1369 v8::Local<v8::FunctionTemplate> templ =
1370 v8::FunctionTemplate::New(CcTest::isolate());
1371 templ->InstanceTemplate()->SetHandler(
1372 v8::NamedPropertyHandlerConfiguration(0, EmptyInterceptorSetter));
1373 env->Global()
1374 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local())
1375 .ToLocalChecked()
1376 ->NewInstance(env.local())
1377 .ToLocalChecked())
1378 .FromJust();
1379
1380 v8::TryCatch try_catch(env->GetIsolate());
1381 CompileRun("Object.defineProperty(obj, 'x', {});");
1382 CHECK(try_catch.HasCaught());
1383 }
1384 }
1385
1325 namespace { 1386 namespace {
1326 void NotInterceptingPropertyDefineCallback( 1387 void NotInterceptingPropertyDefineCallback(
1327 Local<Name> name, const v8::PropertyDescriptor& desc, 1388 Local<Name> name, const v8::PropertyDescriptor& desc,
1328 const v8::PropertyCallbackInfo<v8::Value>& info) { 1389 const v8::PropertyCallbackInfo<v8::Value>& info) {
1329 // Do not intercept by not calling info.GetReturnValue().Set(). 1390 // Do not intercept by not calling info.GetReturnValue().Set().
1330 } 1391 }
1331 1392
1332 void InterceptingPropertyDefineCallback( 1393 void InterceptingPropertyDefineCallback(
1333 Local<Name> name, const v8::PropertyDescriptor& desc, 1394 Local<Name> name, const v8::PropertyDescriptor& desc,
1334 const v8::PropertyCallbackInfo<v8::Value>& info) { 1395 const v8::PropertyCallbackInfo<v8::Value>& info) {
(...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after
2199 // All i >= 10000 go to the accessor. 2260 // All i >= 10000 go to the accessor.
2200 ExpectInt32("child.accessor_age", 10000); 2261 ExpectInt32("child.accessor_age", 10000);
2201 // The last i goes to the interceptor. 2262 // The last i goes to the interceptor.
2202 ExpectInt32("child.interceptor_age", 9999); 2263 ExpectInt32("child.interceptor_age", 9999);
2203 } 2264 }
2204 2265
2205 2266
2206 THREADED_TEST(SwitchFromInterceptorToJSAccessor) { 2267 THREADED_TEST(SwitchFromInterceptorToJSAccessor) {
2207 v8::HandleScope scope(CcTest::isolate()); 2268 v8::HandleScope scope(CcTest::isolate());
2208 Local<FunctionTemplate> templ = FunctionTemplate::New(CcTest::isolate()); 2269 Local<FunctionTemplate> templ = FunctionTemplate::New(CcTest::isolate());
2209 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); 2270 AddInterceptor(templ, InterceptorGetter, nullptr);
2210 LocalContext env; 2271 LocalContext env;
2211 env->Global() 2272 env->Global()
2212 ->Set(env.local(), v8_str("Obj"), 2273 ->Set(env.local(), v8_str("Obj"),
2213 templ->GetFunction(env.local()).ToLocalChecked()) 2274 templ->GetFunction(env.local()).ToLocalChecked())
2214 .FromJust(); 2275 .FromJust();
2215 CompileRun( 2276 CompileRun(
2216 "var obj = new Obj;" 2277 "var obj = new Obj;"
2217 "function setter(i) { this.accessor_age = i; };" 2278 "function setter(i) { this.accessor_age = i; };"
2218 "function getter() { return this.accessor_age; };" 2279 "function getter() { return this.accessor_age; };"
2219 "function setAge(i) { obj.age = i; };" 2280 "function setAge(i) { obj.age = i; };"
2220 "Object.defineProperty(obj, 'age', { get:getter, set:setter });" 2281 "Object.defineProperty(obj, 'age', { get:getter, set:setter });"
2221 "for(var i = 0; i <= 10000; i++) setAge(i);"); 2282 "for(var i = 0; i <= 10000; i++) setAge(i);");
2222 // All i < 10000 go to the interceptor.
2223 ExpectInt32("obj.interceptor_age", 9999);
2224 // The last i goes to the JavaScript accessor. 2283 // The last i goes to the JavaScript accessor.
2225 ExpectInt32("obj.accessor_age", 10000); 2284 ExpectInt32("obj.accessor_age", 10000);
2226 // The installed JavaScript getter is still intact. 2285 // The installed JavaScript getter is still intact.
2227 // This last part is a regression test for issue 1651 and relies on the fact 2286 // This last part is a regression test for issue 1651 and relies on the fact
2228 // that both interceptor and accessor are being installed on the same object. 2287 // that both interceptor and accessor are being installed on the same object.
2229 ExpectInt32("obj.age", 10000); 2288 ExpectInt32("obj.age", 10000);
2230 ExpectBoolean("obj.hasOwnProperty('age')", true); 2289 ExpectBoolean("obj.hasOwnProperty('age')", true);
2231 ExpectUndefined("Object.getOwnPropertyDescriptor(obj, 'age').value"); 2290 ExpectUndefined("Object.getOwnPropertyDescriptor(obj, 'age').value");
2232 } 2291 }
2233 2292
2234 2293
2235 THREADED_TEST(SwitchFromJSAccessorToInterceptor) { 2294 THREADED_TEST(SwitchFromJSAccessorToInterceptor) {
2236 v8::HandleScope scope(CcTest::isolate()); 2295 v8::HandleScope scope(CcTest::isolate());
2237 Local<FunctionTemplate> templ = FunctionTemplate::New(CcTest::isolate()); 2296 Local<FunctionTemplate> templ = FunctionTemplate::New(CcTest::isolate());
2238 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); 2297 AddInterceptor(templ, InterceptorGetter, nullptr);
2239 LocalContext env; 2298 LocalContext env;
2240 env->Global() 2299 env->Global()
2241 ->Set(env.local(), v8_str("Obj"), 2300 ->Set(env.local(), v8_str("Obj"),
2242 templ->GetFunction(env.local()).ToLocalChecked()) 2301 templ->GetFunction(env.local()).ToLocalChecked())
2243 .FromJust(); 2302 .FromJust();
2244 CompileRun( 2303 CompileRun(
2245 "var obj = new Obj;" 2304 "var obj = new Obj;"
2246 "function setter(i) { this.accessor_age = i; };" 2305 "function setter(i) { this.accessor_age = i; };"
2247 "function getter() { return this.accessor_age; };" 2306 "function getter() { return this.accessor_age; };"
2248 "function setAge(i) { obj.age = i; };" 2307 "function setAge(i) { obj.age = i; };"
2249 "Object.defineProperty(obj, 'age', { get:getter, set:setter });" 2308 "Object.defineProperty(obj, 'age', { get:getter, set:setter });"
2250 "for(var i = 20000; i >= 9999; i--) setAge(i);"); 2309 "for(var i = 20000; i >= 9999; i--) setAge(i);");
2251 // All i >= 10000 go to the accessor. 2310 ExpectInt32("obj.accessor_age", 9999);
2252 ExpectInt32("obj.accessor_age", 10000); 2311 ExpectInt32("obj.age", 9999);
2253 // The last i goes to the interceptor.
2254 ExpectInt32("obj.interceptor_age", 9999);
2255 // The installed JavaScript getter is still intact.
2256 // This last part is a regression test for issue 1651 and relies on the fact
2257 // that both interceptor and accessor are being installed on the same object.
2258 ExpectInt32("obj.age", 10000);
2259 ExpectBoolean("obj.hasOwnProperty('age')", true); 2312 ExpectBoolean("obj.hasOwnProperty('age')", true);
2260 ExpectUndefined("Object.getOwnPropertyDescriptor(obj, 'age').value"); 2313 ExpectUndefined("Object.getOwnPropertyDescriptor(obj, 'age').value");
2261 } 2314 }
2262 2315
2263 2316
2264 THREADED_TEST(SwitchFromInterceptorToProperty) { 2317 THREADED_TEST(SwitchFromInterceptorToProperty) {
2265 v8::HandleScope scope(CcTest::isolate()); 2318 v8::HandleScope scope(CcTest::isolate());
2266 Local<FunctionTemplate> parent = FunctionTemplate::New(CcTest::isolate()); 2319 Local<FunctionTemplate> parent = FunctionTemplate::New(CcTest::isolate());
2267 Local<FunctionTemplate> child = FunctionTemplate::New(CcTest::isolate()); 2320 Local<FunctionTemplate> child = FunctionTemplate::New(CcTest::isolate());
2268 child->Inherit(parent); 2321 child->Inherit(parent);
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
2484 2537
2485 static void IndexedPropertyGetter( 2538 static void IndexedPropertyGetter(
2486 uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) { 2539 uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) {
2487 ApiTestFuzzer::Fuzz(); 2540 ApiTestFuzzer::Fuzz();
2488 if (index == 37) { 2541 if (index == 37) {
2489 info.GetReturnValue().Set(v8_num(625)); 2542 info.GetReturnValue().Set(v8_num(625));
2490 } 2543 }
2491 } 2544 }
2492 2545
2493 2546
2494 static void IndexedPropertySetter(
2495 uint32_t index, Local<Value> value,
2496 const v8::PropertyCallbackInfo<v8::Value>& info) {
2497 ApiTestFuzzer::Fuzz();
2498 if (index == 39) {
2499 info.GetReturnValue().Set(value);
2500 }
2501 }
2502
2503
2504 THREADED_TEST(IndexedInterceptorWithIndexedAccessor) { 2547 THREADED_TEST(IndexedInterceptorWithIndexedAccessor) {
2505 v8::Isolate* isolate = CcTest::isolate(); 2548 v8::Isolate* isolate = CcTest::isolate();
2506 v8::HandleScope scope(isolate); 2549 v8::HandleScope scope(isolate);
2507 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 2550 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
2508 templ->SetHandler(v8::IndexedPropertyHandlerConfiguration( 2551 templ->SetHandler(
2509 IndexedPropertyGetter, IndexedPropertySetter)); 2552 v8::IndexedPropertyHandlerConfiguration(IndexedPropertyGetter, nullptr));
2510 LocalContext context; 2553 LocalContext context;
2511 context->Global() 2554 context->Global()
2512 ->Set(context.local(), v8_str("obj"), 2555 ->Set(context.local(), v8_str("obj"),
2513 templ->NewInstance(context.local()).ToLocalChecked()) 2556 templ->NewInstance(context.local()).ToLocalChecked())
2514 .FromJust(); 2557 .FromJust();
2515 Local<Script> getter_script = 2558 Local<Script> getter_script =
2516 v8_compile("obj.__defineGetter__(\"3\", function(){return 5;});obj[3];"); 2559 v8_compile("obj.__defineGetter__(\"3\", function(){return 5;});obj[3];");
2517 Local<Script> setter_script = v8_compile( 2560 Local<Script> setter_script = v8_compile(
2518 "obj.__defineSetter__(\"17\", function(val){this.foo = val;});" 2561 "obj.__defineSetter__(\"17\", function(val){this.foo = val;});"
2519 "obj[17] = 23;" 2562 "obj[17] = 23;"
2520 "obj.foo;"); 2563 "obj.foo;");
2521 Local<Script> interceptor_setter_script = v8_compile(
2522 "obj.__defineSetter__(\"39\", function(val){this.foo = \"hit\";});"
2523 "obj[39] = 47;"
2524 "obj.foo;"); // This setter should not run, due to the interceptor.
2525 Local<Script> interceptor_getter_script = v8_compile("obj[37];"); 2564 Local<Script> interceptor_getter_script = v8_compile("obj[37];");
2526 Local<Value> result = getter_script->Run(context.local()).ToLocalChecked(); 2565 Local<Value> result = getter_script->Run(context.local()).ToLocalChecked();
2527 CHECK(v8_num(5)->Equals(context.local(), result).FromJust()); 2566 CHECK(v8_num(5)->Equals(context.local(), result).FromJust());
2528 result = setter_script->Run(context.local()).ToLocalChecked(); 2567 result = setter_script->Run(context.local()).ToLocalChecked();
2529 CHECK(v8_num(23)->Equals(context.local(), result).FromJust()); 2568 CHECK(v8_num(23)->Equals(context.local(), result).FromJust());
2530 result = interceptor_setter_script->Run(context.local()).ToLocalChecked();
2531 CHECK(v8_num(23)->Equals(context.local(), result).FromJust());
2532 result = interceptor_getter_script->Run(context.local()).ToLocalChecked(); 2569 result = interceptor_getter_script->Run(context.local()).ToLocalChecked();
2533 CHECK(v8_num(625)->Equals(context.local(), result).FromJust()); 2570 CHECK(v8_num(625)->Equals(context.local(), result).FromJust());
2534 } 2571 }
2535 2572
2536 2573
2537 static void UnboxedDoubleIndexedPropertyGetter( 2574 static void UnboxedDoubleIndexedPropertyGetter(
2538 uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) { 2575 uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) {
2539 ApiTestFuzzer::Fuzz(); 2576 ApiTestFuzzer::Fuzz();
2540 if (index < 25) { 2577 if (index < 25) {
2541 info.GetReturnValue().Set(v8_num(index)); 2578 info.GetReturnValue().Set(v8_num(index));
(...skipping 1415 matching lines...) Expand 10 before | Expand all | Expand 10 after
3957 "%OptimizeFunctionOnNextCall(f);" 3994 "%OptimizeFunctionOnNextCall(f);"
3958 "f(o);"); 3995 "f(o);");
3959 ExpectBoolean("%GetOptimizationStatus(f) != 2", true); 3996 ExpectBoolean("%GetOptimizationStatus(f) != 2", true);
3960 } 3997 }
3961 3998
3962 3999
3963 THREADED_TEST(CrankshaftInterceptorSetter) { 4000 THREADED_TEST(CrankshaftInterceptorSetter) {
3964 i::FLAG_allow_natives_syntax = true; 4001 i::FLAG_allow_natives_syntax = true;
3965 v8::HandleScope scope(CcTest::isolate()); 4002 v8::HandleScope scope(CcTest::isolate());
3966 Local<FunctionTemplate> templ = FunctionTemplate::New(CcTest::isolate()); 4003 Local<FunctionTemplate> templ = FunctionTemplate::New(CcTest::isolate());
3967 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); 4004 AddInterceptor(templ, InterceptorGetter, nullptr);
3968 LocalContext env; 4005 LocalContext env;
3969 env->Global() 4006 env->Global()
3970 ->Set(env.local(), v8_str("Obj"), 4007 ->Set(env.local(), v8_str("Obj"),
3971 templ->GetFunction(env.local()).ToLocalChecked()) 4008 templ->GetFunction(env.local()).ToLocalChecked())
3972 .FromJust(); 4009 .FromJust();
3973 CompileRun( 4010 CompileRun(
3974 "var obj = new Obj;" 4011 "var obj = new Obj;"
3975 // Initialize fields to avoid transitions later. 4012 // Initialize fields to avoid transitions later.
3976 "obj.age = 0;" 4013 "obj.age = 0;"
3977 "obj.accessor_age = 42;" 4014 "obj.accessor_age = 42;"
3978 "function setter(i) { this.accessor_age = i; };" 4015 "function setter(i) { this.accessor_age = i; };"
3979 "function getter() { return this.accessor_age; };" 4016 "function getter() { return this.accessor_age; };"
3980 "function setAge(i) { obj.age = i; };" 4017 "function setAge(i) { obj.age = i; };"
3981 "Object.defineProperty(obj, 'age', { get:getter, set:setter });" 4018 "Object.defineProperty(obj, 'age', { get:getter, set:setter });"
3982 "setAge(1);" 4019 "setAge(1);"
3983 "setAge(2);" 4020 "setAge(2);"
3984 "setAge(3);" 4021 "setAge(3);"
3985 "%OptimizeFunctionOnNextCall(setAge);" 4022 "%OptimizeFunctionOnNextCall(setAge);"
3986 "setAge(4);"); 4023 "setAge(4);");
3987 // All stores went through the interceptor. 4024 ExpectUndefined("obj.interceptor_age");
3988 ExpectInt32("obj.interceptor_age", 4); 4025 ExpectInt32("obj.accessor_age", 4);
3989 ExpectInt32("obj.accessor_age", 42);
3990 } 4026 }
3991 4027
3992 4028
3993 THREADED_TEST(CrankshaftInterceptorGetter) { 4029 THREADED_TEST(CrankshaftInterceptorGetter) {
3994 i::FLAG_allow_natives_syntax = true; 4030 i::FLAG_allow_natives_syntax = true;
3995 v8::HandleScope scope(CcTest::isolate()); 4031 v8::HandleScope scope(CcTest::isolate());
3996 Local<FunctionTemplate> templ = FunctionTemplate::New(CcTest::isolate()); 4032 Local<FunctionTemplate> templ = FunctionTemplate::New(CcTest::isolate());
3997 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); 4033 AddInterceptor(templ, InterceptorGetter, InterceptorSetter);
3998 LocalContext env; 4034 LocalContext env;
3999 env->Global() 4035 env->Global()
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
4760 ->Set(env.local(), v8_str("Fun"), 4796 ->Set(env.local(), v8_str("Fun"),
4761 fun_templ->GetFunction(env.local()).ToLocalChecked()) 4797 fun_templ->GetFunction(env.local()).ToLocalChecked())
4762 .FromJust()); 4798 .FromJust());
4763 4799
4764 CompileRun( 4800 CompileRun(
4765 "var f = new Fun();" 4801 "var f = new Fun();"
4766 "Number.prototype.__proto__ = f;" 4802 "Number.prototype.__proto__ = f;"
4767 "var a = 42;" 4803 "var a = 42;"
4768 "for (var i = 0; i<3; i++) { a.foo; }"); 4804 "for (var i = 0; i<3; i++) { a.foo; }");
4769 } 4805 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698