OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 1405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1416 ExpectBoolean("child.hasOwnProperty('name')", false); | 1416 ExpectBoolean("child.hasOwnProperty('name')", false); |
1417 ExpectString("child.name", "Alice"); | 1417 ExpectString("child.name", "Alice"); |
1418 CompileRun("child.name = 'Bob';"); | 1418 CompileRun("child.name = 'Bob';"); |
1419 ExpectString("child.name", "Bob"); | 1419 ExpectString("child.name", "Bob"); |
1420 ExpectBoolean("child.hasOwnProperty('name')", true); | 1420 ExpectBoolean("child.hasOwnProperty('name')", true); |
1421 ExpectString("parent.name", "Alice"); | 1421 ExpectString("parent.name", "Alice"); |
1422 } | 1422 } |
1423 | 1423 |
1424 THREADED_TEST(SwitchFromInterceptorToAccessor) { | 1424 THREADED_TEST(SwitchFromInterceptorToAccessor) { |
1425 v8::HandleScope scope; | 1425 v8::HandleScope scope; |
| 1426 Handle<FunctionTemplate> templ = FunctionTemplate::New(); |
| 1427 AddAccessor(templ, v8_str("age"), |
| 1428 SimpleAccessorGetter, SimpleAccessorSetter); |
| 1429 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); |
| 1430 LocalContext env; |
| 1431 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); |
| 1432 CompileRun("var obj = new Obj;" |
| 1433 "function setAge(i){ obj.age = i; };" |
| 1434 "for(var i = 0; i <= 10000; i++) setAge(i);"); |
| 1435 // All i < 10000 go to the interceptor. |
| 1436 ExpectInt32("obj.interceptor_age", 9999); |
| 1437 // The last i goes to the accessor. |
| 1438 ExpectInt32("obj.accessor_age", 10000); |
| 1439 } |
| 1440 |
| 1441 THREADED_TEST(SwitchFromAccessorToInterceptor) { |
| 1442 v8::HandleScope scope; |
| 1443 Handle<FunctionTemplate> templ = FunctionTemplate::New(); |
| 1444 AddAccessor(templ, v8_str("age"), |
| 1445 SimpleAccessorGetter, SimpleAccessorSetter); |
| 1446 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); |
| 1447 LocalContext env; |
| 1448 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); |
| 1449 CompileRun("var obj = new Obj;" |
| 1450 "function setAge(i){ obj.age = i; };" |
| 1451 "for(var i = 20000; i >= 9999; i--) setAge(i);"); |
| 1452 // All i >= 10000 go to the accessor. |
| 1453 ExpectInt32("obj.accessor_age", 10000); |
| 1454 // The last i goes to the interceptor. |
| 1455 ExpectInt32("obj.interceptor_age", 9999); |
| 1456 } |
| 1457 |
| 1458 THREADED_TEST(SwitchFromInterceptorToAccessorWithInheritance) { |
| 1459 v8::HandleScope scope; |
1426 Handle<FunctionTemplate> parent = FunctionTemplate::New(); | 1460 Handle<FunctionTemplate> parent = FunctionTemplate::New(); |
1427 Handle<FunctionTemplate> child = FunctionTemplate::New(); | 1461 Handle<FunctionTemplate> child = FunctionTemplate::New(); |
1428 child->Inherit(parent); | 1462 child->Inherit(parent); |
1429 AddAccessor(parent, v8_str("age"), | 1463 AddAccessor(parent, v8_str("age"), |
1430 SimpleAccessorGetter, SimpleAccessorSetter); | 1464 SimpleAccessorGetter, SimpleAccessorSetter); |
1431 AddInterceptor(child, InterceptorGetter, InterceptorSetter); | 1465 AddInterceptor(child, InterceptorGetter, InterceptorSetter); |
1432 LocalContext env; | 1466 LocalContext env; |
1433 env->Global()->Set(v8_str("Child"), child->GetFunction()); | 1467 env->Global()->Set(v8_str("Child"), child->GetFunction()); |
1434 CompileRun("var child = new Child;" | 1468 CompileRun("var child = new Child;" |
1435 "function setAge(i){ child.age = i; };" | 1469 "function setAge(i){ child.age = i; };" |
1436 "for(var i = 0; i <= 10000; i++) setAge(i);"); | 1470 "for(var i = 0; i <= 10000; i++) setAge(i);"); |
1437 // All i < 10000 go to the interceptor. | 1471 // All i < 10000 go to the interceptor. |
1438 ExpectInt32("child.interceptor_age", 9999); | 1472 ExpectInt32("child.interceptor_age", 9999); |
1439 // The last i goes to the accessor. | 1473 // The last i goes to the accessor. |
1440 ExpectInt32("child.accessor_age", 10000); | 1474 ExpectInt32("child.accessor_age", 10000); |
1441 } | 1475 } |
1442 | 1476 |
1443 THREADED_TEST(SwitchFromAccessorToInterceptor) { | 1477 THREADED_TEST(SwitchFromAccessorToInterceptorWithInheritance) { |
1444 v8::HandleScope scope; | 1478 v8::HandleScope scope; |
1445 Handle<FunctionTemplate> parent = FunctionTemplate::New(); | 1479 Handle<FunctionTemplate> parent = FunctionTemplate::New(); |
1446 Handle<FunctionTemplate> child = FunctionTemplate::New(); | 1480 Handle<FunctionTemplate> child = FunctionTemplate::New(); |
1447 child->Inherit(parent); | 1481 child->Inherit(parent); |
1448 AddAccessor(parent, v8_str("age"), | 1482 AddAccessor(parent, v8_str("age"), |
1449 SimpleAccessorGetter, SimpleAccessorSetter); | 1483 SimpleAccessorGetter, SimpleAccessorSetter); |
1450 AddInterceptor(child, InterceptorGetter, InterceptorSetter); | 1484 AddInterceptor(child, InterceptorGetter, InterceptorSetter); |
1451 LocalContext env; | 1485 LocalContext env; |
1452 env->Global()->Set(v8_str("Child"), child->GetFunction()); | 1486 env->Global()->Set(v8_str("Child"), child->GetFunction()); |
1453 CompileRun("var child = new Child;" | 1487 CompileRun("var child = new Child;" |
1454 "function setAge(i){ child.age = i; };" | 1488 "function setAge(i){ child.age = i; };" |
1455 "for(var i = 20000; i >= 9999; i--) setAge(i);"); | 1489 "for(var i = 20000; i >= 9999; i--) setAge(i);"); |
1456 // All i >= 10000 go to the accessor. | 1490 // All i >= 10000 go to the accessor. |
1457 ExpectInt32("child.accessor_age", 10000); | 1491 ExpectInt32("child.accessor_age", 10000); |
1458 // The last i goes to the interceptor. | 1492 // The last i goes to the interceptor. |
1459 ExpectInt32("child.interceptor_age", 9999); | 1493 ExpectInt32("child.interceptor_age", 9999); |
1460 } | 1494 } |
1461 | 1495 |
| 1496 THREADED_TEST(SwitchFromInterceptorToJSAccessor) { |
| 1497 v8::HandleScope scope; |
| 1498 Handle<FunctionTemplate> templ = FunctionTemplate::New(); |
| 1499 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); |
| 1500 LocalContext env; |
| 1501 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); |
| 1502 CompileRun("var obj = new Obj;" |
| 1503 "function setter(i) { this.accessor_age = i; };" |
| 1504 "function getter() { return this.accessor_age; };" |
| 1505 "function setAge(i) { obj.age = i; };" |
| 1506 "Object.defineProperty(obj, 'age', { get:getter, set:setter });" |
| 1507 "for(var i = 0; i <= 10000; i++) setAge(i);"); |
| 1508 // All i < 10000 go to the interceptor. |
| 1509 ExpectInt32("obj.interceptor_age", 9999); |
| 1510 // The last i goes to the JavaScript accessor. |
| 1511 ExpectInt32("obj.accessor_age", 10000); |
| 1512 // The installed JavaScript getter is still intact. |
| 1513 // This last part is a regression test for issue 1651 and relies on the fact |
| 1514 // that both interceptor and accessor are being installed on the same object. |
| 1515 ExpectInt32("obj.age", 10000); |
| 1516 ExpectBoolean("obj.hasOwnProperty('age')", true); |
| 1517 ExpectUndefined("Object.getOwnPropertyDescriptor(obj, 'age').value"); |
| 1518 } |
| 1519 |
| 1520 THREADED_TEST(SwitchFromJSAccessorToInterceptor) { |
| 1521 v8::HandleScope scope; |
| 1522 Handle<FunctionTemplate> templ = FunctionTemplate::New(); |
| 1523 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); |
| 1524 LocalContext env; |
| 1525 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); |
| 1526 CompileRun("var obj = new Obj;" |
| 1527 "function setter(i) { this.accessor_age = i; };" |
| 1528 "function getter() { return this.accessor_age; };" |
| 1529 "function setAge(i) { obj.age = i; };" |
| 1530 "Object.defineProperty(obj, 'age', { get:getter, set:setter });" |
| 1531 "for(var i = 20000; i >= 9999; i--) setAge(i);"); |
| 1532 // All i >= 10000 go to the accessor. |
| 1533 ExpectInt32("obj.accessor_age", 10000); |
| 1534 // The last i goes to the interceptor. |
| 1535 ExpectInt32("obj.interceptor_age", 9999); |
| 1536 // The installed JavaScript getter is still intact. |
| 1537 // This last part is a regression test for issue 1651 and relies on the fact |
| 1538 // that both interceptor and accessor are being installed on the same object. |
| 1539 ExpectInt32("obj.age", 10000); |
| 1540 ExpectBoolean("obj.hasOwnProperty('age')", true); |
| 1541 ExpectUndefined("Object.getOwnPropertyDescriptor(obj, 'age').value"); |
| 1542 } |
| 1543 |
1462 THREADED_TEST(SwitchFromInterceptorToProperty) { | 1544 THREADED_TEST(SwitchFromInterceptorToProperty) { |
1463 v8::HandleScope scope; | 1545 v8::HandleScope scope; |
1464 Handle<FunctionTemplate> parent = FunctionTemplate::New(); | 1546 Handle<FunctionTemplate> parent = FunctionTemplate::New(); |
1465 Handle<FunctionTemplate> child = FunctionTemplate::New(); | 1547 Handle<FunctionTemplate> child = FunctionTemplate::New(); |
1466 child->Inherit(parent); | 1548 child->Inherit(parent); |
1467 AddInterceptor(child, InterceptorGetter, InterceptorSetter); | 1549 AddInterceptor(child, InterceptorGetter, InterceptorSetter); |
1468 LocalContext env; | 1550 LocalContext env; |
1469 env->Global()->Set(v8_str("Child"), child->GetFunction()); | 1551 env->Global()->Set(v8_str("Child"), child->GetFunction()); |
1470 CompileRun("var child = new Child;" | 1552 CompileRun("var child = new Child;" |
1471 "function setAge(i){ child.age = i; };" | 1553 "function setAge(i){ child.age = i; };" |
(...skipping 14165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15637 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]"))); | 15719 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]"))); |
15638 | 15720 |
15639 // TODO(1547): Make the following also return "i". | 15721 // TODO(1547): Make the following also return "i". |
15640 // Calling with environment record as base. | 15722 // Calling with environment record as base. |
15641 TestReceiver(o, context->Global(), "func()"); | 15723 TestReceiver(o, context->Global(), "func()"); |
15642 // Calling with no base. | 15724 // Calling with no base. |
15643 TestReceiver(o, context->Global(), "(1,func)()"); | 15725 TestReceiver(o, context->Global(), "(1,func)()"); |
15644 | 15726 |
15645 foreign_context.Dispose(); | 15727 foreign_context.Dispose(); |
15646 } | 15728 } |
OLD | NEW |