Index: test/cctest/test-api.cc |
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc |
index 8b618d4906125d77c88361235bedac41405f0226..d19ef61f17da3ebb1d2c736236a073ba073d0e07 100644 |
--- a/test/cctest/test-api.cc |
+++ b/test/cctest/test-api.cc |
@@ -1459,6 +1459,54 @@ THREADED_TEST(SwitchFromAccessorToInterceptor) { |
ExpectInt32("child.interceptor_age", 9999); |
} |
+THREADED_TEST(SwitchFromInterceptorToJSAccessor) { |
+ v8::HandleScope scope; |
+ 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.
|
+ AddInterceptor(child, InterceptorGetter, InterceptorSetter); |
+ LocalContext env; |
+ env->Global()->Set(v8_str("Child"), child->GetFunction()); |
+ CompileRun("var child = new Child;" |
+ "function setter(i) { this.accessor_age = i; };" |
+ "function getter() { return this.accessor_age; };" |
+ "function setAge(i) { child.age = i; };" |
+ "Object.defineProperty(child, 'age', { get:getter, set:setter });" |
+ "for(var i = 0; i <= 10000; i++) setAge(i);"); |
+ // All i < 10000 go to the interceptor. |
+ ExpectInt32("child.interceptor_age", 9999); |
+ // The last i goes to the JavaScript accessor. |
+ ExpectInt32("child.accessor_age", 10000); |
+ // The installed JavaScript getter is still intact. |
+ // This last part is a regression test for issue 1651 and relies on the fact |
+ // that both interceptor and accessor are being installed on the same object. |
+ ExpectInt32("child.age", 10000); |
+ ExpectBoolean("child.hasOwnProperty('age')", true); |
+ ExpectUndefined("Object.getOwnPropertyDescriptor(child, 'age').value"); |
+} |
+ |
+THREADED_TEST(SwitchFromJSAccessorToInterceptor) { |
+ v8::HandleScope scope; |
+ Handle<FunctionTemplate> child = FunctionTemplate::New(); |
+ AddInterceptor(child, InterceptorGetter, InterceptorSetter); |
+ LocalContext env; |
+ env->Global()->Set(v8_str("Child"), child->GetFunction()); |
+ CompileRun("var child = new Child;" |
+ "function setter(i) { this.accessor_age = i; };" |
+ "function getter() { return this.accessor_age; };" |
+ "function setAge(i) { child.age = i; };" |
+ "Object.defineProperty(child, 'age', { get:getter, set:setter });" |
+ "for(var i = 20000; i >= 9999; i--) setAge(i);"); |
+ // All i >= 10000 go to the accessor. |
+ ExpectInt32("child.accessor_age", 10000); |
+ // The last i goes to the interceptor. |
+ ExpectInt32("child.interceptor_age", 9999); |
+ // The installed JavaScript getter is still intact. |
+ // This last part is a regression test for issue 1651 and relies on the fact |
+ // that both interceptor and accessor are being installed on the same object. |
+ ExpectInt32("child.age", 10000); |
+ ExpectBoolean("child.hasOwnProperty('age')", true); |
+ ExpectUndefined("Object.getOwnPropertyDescriptor(child, 'age').value"); |
+} |
+ |
THREADED_TEST(SwitchFromInterceptorToProperty) { |
v8::HandleScope scope; |
Handle<FunctionTemplate> parent = FunctionTemplate::New(); |