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 1422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1433 env->Global()->Set(v8_str("Child"), child->GetFunction()); | 1433 env->Global()->Set(v8_str("Child"), child->GetFunction()); |
1434 CompileRun("var child = new Child;" | 1434 CompileRun("var child = new Child;" |
1435 "function setAge(i){ child.age = i; };" | 1435 "function setAge(i){ child.age = i; };" |
1436 "for(var i = 0; i <= 10000; i++) setAge(i);"); | 1436 "for(var i = 0; i <= 10000; i++) setAge(i);"); |
1437 // All i < 10000 go to the interceptor. | 1437 // All i < 10000 go to the interceptor. |
1438 ExpectInt32("child.interceptor_age", 9999); | 1438 ExpectInt32("child.interceptor_age", 9999); |
1439 // The last i goes to the accessor. | 1439 // The last i goes to the accessor. |
1440 ExpectInt32("child.accessor_age", 10000); | 1440 ExpectInt32("child.accessor_age", 10000); |
1441 } | 1441 } |
1442 | 1442 |
1443 THREADED_TEST(SwitchFromAccessorToInterceptor) { | 1443 THREADED_TEST(SwitchFromAccessorToInterceptor) { |
rossberg
2011/12/21 15:58:42
Not your change, but could you add a variant of th
Michael Starzinger
2011/12/21 16:15:01
Done.
| |
1444 v8::HandleScope scope; | 1444 v8::HandleScope scope; |
1445 Handle<FunctionTemplate> parent = FunctionTemplate::New(); | 1445 Handle<FunctionTemplate> parent = FunctionTemplate::New(); |
1446 Handle<FunctionTemplate> child = FunctionTemplate::New(); | 1446 Handle<FunctionTemplate> child = FunctionTemplate::New(); |
1447 child->Inherit(parent); | 1447 child->Inherit(parent); |
1448 AddAccessor(parent, v8_str("age"), | 1448 AddAccessor(parent, v8_str("age"), |
1449 SimpleAccessorGetter, SimpleAccessorSetter); | 1449 SimpleAccessorGetter, SimpleAccessorSetter); |
1450 AddInterceptor(child, InterceptorGetter, InterceptorSetter); | 1450 AddInterceptor(child, InterceptorGetter, InterceptorSetter); |
1451 LocalContext env; | 1451 LocalContext env; |
1452 env->Global()->Set(v8_str("Child"), child->GetFunction()); | 1452 env->Global()->Set(v8_str("Child"), child->GetFunction()); |
1453 CompileRun("var child = new Child;" | 1453 CompileRun("var child = new Child;" |
1454 "function setAge(i){ child.age = i; };" | 1454 "function setAge(i){ child.age = i; };" |
1455 "for(var i = 20000; i >= 9999; i--) setAge(i);"); | 1455 "for(var i = 20000; i >= 9999; i--) setAge(i);"); |
1456 // All i >= 10000 go to the accessor. | 1456 // All i >= 10000 go to the accessor. |
1457 ExpectInt32("child.accessor_age", 10000); | 1457 ExpectInt32("child.accessor_age", 10000); |
1458 // The last i goes to the interceptor. | 1458 // The last i goes to the interceptor. |
1459 ExpectInt32("child.interceptor_age", 9999); | 1459 ExpectInt32("child.interceptor_age", 9999); |
1460 } | 1460 } |
1461 | 1461 |
1462 THREADED_TEST(SwitchFromInterceptorToJSAccessor) { | |
1463 v8::HandleScope scope; | |
1464 Handle<FunctionTemplate> child = FunctionTemplate::New(); | |
rossberg
2011/12/21 15:58:42
"child"? Where is the parent? ;)
Michael Starzinger
2011/12/21 16:15:01
Done. Renamed to "obj" instead.
| |
1465 AddInterceptor(child, InterceptorGetter, InterceptorSetter); | |
1466 LocalContext env; | |
1467 env->Global()->Set(v8_str("Child"), child->GetFunction()); | |
1468 CompileRun("var child = new Child;" | |
1469 "function setter(i) { this.accessor_age = i; };" | |
1470 "function getter() { return this.accessor_age; };" | |
1471 "function setAge(i) { child.age = i; };" | |
1472 "Object.defineProperty(child, 'age', { get:getter, set:setter });" | |
1473 "for(var i = 0; i <= 10000; i++) setAge(i);"); | |
1474 // All i < 10000 go to the interceptor. | |
1475 ExpectInt32("child.interceptor_age", 9999); | |
1476 // The last i goes to the JavaScript accessor. | |
1477 ExpectInt32("child.accessor_age", 10000); | |
1478 // The installed JavaScript getter is still intact. | |
1479 // This last part is a regression test for issue 1651 and relies on the fact | |
1480 // that both interceptor and accessor are being installed on the same object. | |
1481 ExpectInt32("child.age", 10000); | |
1482 ExpectBoolean("child.hasOwnProperty('age')", true); | |
1483 ExpectUndefined("Object.getOwnPropertyDescriptor(child, 'age').value"); | |
1484 } | |
1485 | |
1486 THREADED_TEST(SwitchFromJSAccessorToInterceptor) { | |
1487 v8::HandleScope scope; | |
1488 Handle<FunctionTemplate> child = FunctionTemplate::New(); | |
1489 AddInterceptor(child, InterceptorGetter, InterceptorSetter); | |
1490 LocalContext env; | |
1491 env->Global()->Set(v8_str("Child"), child->GetFunction()); | |
1492 CompileRun("var child = new Child;" | |
1493 "function setter(i) { this.accessor_age = i; };" | |
1494 "function getter() { return this.accessor_age; };" | |
1495 "function setAge(i) { child.age = i; };" | |
1496 "Object.defineProperty(child, 'age', { get:getter, set:setter });" | |
1497 "for(var i = 20000; i >= 9999; i--) setAge(i);"); | |
1498 // All i >= 10000 go to the accessor. | |
1499 ExpectInt32("child.accessor_age", 10000); | |
1500 // The last i goes to the interceptor. | |
1501 ExpectInt32("child.interceptor_age", 9999); | |
1502 // The installed JavaScript getter is still intact. | |
1503 // This last part is a regression test for issue 1651 and relies on the fact | |
1504 // that both interceptor and accessor are being installed on the same object. | |
1505 ExpectInt32("child.age", 10000); | |
1506 ExpectBoolean("child.hasOwnProperty('age')", true); | |
1507 ExpectUndefined("Object.getOwnPropertyDescriptor(child, 'age').value"); | |
1508 } | |
1509 | |
1462 THREADED_TEST(SwitchFromInterceptorToProperty) { | 1510 THREADED_TEST(SwitchFromInterceptorToProperty) { |
1463 v8::HandleScope scope; | 1511 v8::HandleScope scope; |
1464 Handle<FunctionTemplate> parent = FunctionTemplate::New(); | 1512 Handle<FunctionTemplate> parent = FunctionTemplate::New(); |
1465 Handle<FunctionTemplate> child = FunctionTemplate::New(); | 1513 Handle<FunctionTemplate> child = FunctionTemplate::New(); |
1466 child->Inherit(parent); | 1514 child->Inherit(parent); |
1467 AddInterceptor(child, InterceptorGetter, InterceptorSetter); | 1515 AddInterceptor(child, InterceptorGetter, InterceptorSetter); |
1468 LocalContext env; | 1516 LocalContext env; |
1469 env->Global()->Set(v8_str("Child"), child->GetFunction()); | 1517 env->Global()->Set(v8_str("Child"), child->GetFunction()); |
1470 CompileRun("var child = new Child;" | 1518 CompileRun("var child = new Child;" |
1471 "function setAge(i){ child.age = i; };" | 1519 "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]"))); | 15685 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]"))); |
15638 | 15686 |
15639 // TODO(1547): Make the following also return "i". | 15687 // TODO(1547): Make the following also return "i". |
15640 // Calling with environment record as base. | 15688 // Calling with environment record as base. |
15641 TestReceiver(o, context->Global(), "func()"); | 15689 TestReceiver(o, context->Global(), "func()"); |
15642 // Calling with no base. | 15690 // Calling with no base. |
15643 TestReceiver(o, context->Global(), "(1,func)()"); | 15691 TestReceiver(o, context->Global(), "(1,func)()"); |
15644 | 15692 |
15645 foreign_context.Dispose(); | 15693 foreign_context.Dispose(); |
15646 } | 15694 } |
OLD | NEW |