| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1917 Handle<Object> self = Handle<Object>::Cast(info.This()); | 1917 Handle<Object> self = Handle<Object>::Cast(info.This()); |
| 1918 self->SetHiddenValue(name, value); | 1918 self->SetHiddenValue(name, value); |
| 1919 info.GetReturnValue().Set(value); | 1919 info.GetReturnValue().Set(value); |
| 1920 } | 1920 } |
| 1921 } | 1921 } |
| 1922 | 1922 |
| 1923 void AddAccessor(Handle<FunctionTemplate> templ, | 1923 void AddAccessor(Handle<FunctionTemplate> templ, |
| 1924 Handle<String> name, | 1924 Handle<String> name, |
| 1925 v8::AccessorGetterCallback getter, | 1925 v8::AccessorGetterCallback getter, |
| 1926 v8::AccessorSetterCallback setter) { | 1926 v8::AccessorSetterCallback setter) { |
| 1927 templ->InstanceTemplate()->SetAccessor(name, getter, setter); | 1927 templ->PrototypeTemplate()->SetAccessor(name, getter, setter); |
| 1928 } | 1928 } |
| 1929 | 1929 |
| 1930 void AddInterceptor(Handle<FunctionTemplate> templ, | 1930 void AddInterceptor(Handle<FunctionTemplate> templ, |
| 1931 v8::NamedPropertyGetterCallback getter, | 1931 v8::NamedPropertyGetterCallback getter, |
| 1932 v8::NamedPropertySetterCallback setter) { | 1932 v8::NamedPropertySetterCallback setter) { |
| 1933 templ->InstanceTemplate()->SetNamedPropertyHandler(getter, setter); | 1933 templ->InstanceTemplate()->SetNamedPropertyHandler(getter, setter); |
| 1934 } | 1934 } |
| 1935 | 1935 |
| 1936 | 1936 |
| 1937 THREADED_TEST(EmptyInterceptorDoesNotShadowAccessors) { | 1937 THREADED_TEST(EmptyInterceptorDoesNotShadowAccessors) { |
| 1938 v8::HandleScope scope(CcTest::isolate()); | 1938 v8::HandleScope scope(CcTest::isolate()); |
| 1939 Handle<FunctionTemplate> parent = FunctionTemplate::New(CcTest::isolate()); | 1939 Handle<FunctionTemplate> parent = FunctionTemplate::New(CcTest::isolate()); |
| 1940 parent->SetHiddenPrototype(true); | |
| 1941 Handle<FunctionTemplate> child = FunctionTemplate::New(CcTest::isolate()); | 1940 Handle<FunctionTemplate> child = FunctionTemplate::New(CcTest::isolate()); |
| 1942 child->Inherit(parent); | 1941 child->Inherit(parent); |
| 1943 AddAccessor(parent, v8_str("age"), | 1942 AddAccessor(parent, v8_str("age"), |
| 1944 SimpleAccessorGetter, SimpleAccessorSetter); | 1943 SimpleAccessorGetter, SimpleAccessorSetter); |
| 1945 AddInterceptor(child, EmptyInterceptorGetter, EmptyInterceptorSetter); | 1944 AddInterceptor(child, EmptyInterceptorGetter, EmptyInterceptorSetter); |
| 1946 LocalContext env; | 1945 LocalContext env; |
| 1947 env->Global()->Set(v8_str("Child"), child->GetFunction()); | 1946 env->Global()->Set(v8_str("Child"), child->GetFunction()); |
| 1948 CompileRun("var child = new Child;" | 1947 CompileRun("var child = new Child;" |
| 1949 "child.age = 10;"); | 1948 "child.age = 10;"); |
| 1950 ExpectBoolean("child.hasOwnProperty('age')", true); | 1949 ExpectBoolean("child.hasOwnProperty('age')", false); |
| 1951 ExpectInt32("child.age", 10); | 1950 ExpectInt32("child.age", 10); |
| 1952 ExpectInt32("child.accessor_age", 10); | 1951 ExpectInt32("child.accessor_age", 10); |
| 1953 } | 1952 } |
| 1954 | 1953 |
| 1955 | 1954 |
| 1956 THREADED_TEST(ExecutableAccessorIsPreservedOnAttributeChange) { | 1955 THREADED_TEST(ExecutableAccessorIsPreservedOnAttributeChange) { |
| 1957 v8::Isolate* isolate = CcTest::isolate(); | 1956 v8::Isolate* isolate = CcTest::isolate(); |
| 1958 v8::HandleScope scope(isolate); | 1957 v8::HandleScope scope(isolate); |
| 1959 LocalContext env; | 1958 LocalContext env; |
| 1960 v8::Local<v8::Value> res = CompileRun("var a = []; a;"); | 1959 v8::Local<v8::Value> res = CompileRun("var a = []; a;"); |
| (...skipping 8018 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9979 | 9978 |
| 9980 THREADED_TEST(ShadowObject) { | 9979 THREADED_TEST(ShadowObject) { |
| 9981 shadow_y = shadow_y_setter_call_count = shadow_y_getter_call_count = 0; | 9980 shadow_y = shadow_y_setter_call_count = shadow_y_getter_call_count = 0; |
| 9982 v8::Isolate* isolate = CcTest::isolate(); | 9981 v8::Isolate* isolate = CcTest::isolate(); |
| 9983 v8::HandleScope handle_scope(isolate); | 9982 v8::HandleScope handle_scope(isolate); |
| 9984 | 9983 |
| 9985 Local<ObjectTemplate> global_template = v8::ObjectTemplate::New(isolate); | 9984 Local<ObjectTemplate> global_template = v8::ObjectTemplate::New(isolate); |
| 9986 LocalContext context(NULL, global_template); | 9985 LocalContext context(NULL, global_template); |
| 9987 | 9986 |
| 9988 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); | 9987 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); |
| 9989 t->SetHiddenPrototype(true); | 9988 t->InstanceTemplate()->SetNamedPropertyHandler(ShadowNamedGet); |
| 9990 Local<v8::FunctionTemplate> pt = v8::FunctionTemplate::New(isolate); | 9989 t->InstanceTemplate()->SetIndexedPropertyHandler(ShadowIndexedGet); |
| 9991 t->Inherit(pt); | 9990 Local<ObjectTemplate> proto = t->PrototypeTemplate(); |
| 9992 Local<ObjectTemplate> proto = pt->PrototypeTemplate(); | |
| 9993 Local<ObjectTemplate> instance = t->InstanceTemplate(); | 9991 Local<ObjectTemplate> instance = t->InstanceTemplate(); |
| 9994 instance->SetNamedPropertyHandler(ShadowNamedGet); | |
| 9995 instance->SetIndexedPropertyHandler(ShadowIndexedGet); | |
| 9996 | 9992 |
| 9997 proto->Set(v8_str("f"), | 9993 proto->Set(v8_str("f"), |
| 9998 v8::FunctionTemplate::New(isolate, | 9994 v8::FunctionTemplate::New(isolate, |
| 9999 ShadowFunctionCallback, | 9995 ShadowFunctionCallback, |
| 10000 Local<Value>())); | 9996 Local<Value>())); |
| 10001 proto->Set(v8_str("x"), v8_num(12)); | 9997 proto->Set(v8_str("x"), v8_num(12)); |
| 10002 | 9998 |
| 10003 instance->SetAccessor(v8_str("y"), ShadowYGetter, ShadowYSetter); | 9999 instance->SetAccessor(v8_str("y"), ShadowYGetter, ShadowYSetter); |
| 10004 | 10000 |
| 10005 Local<Value> o = t->GetFunction()->NewInstance(); | 10001 Local<Value> o = t->GetFunction()->NewInstance(); |
| (...skipping 8526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 18532 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); | 18528 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); |
| 18533 if (!name->Equals(v8_str("foo"))) return; | 18529 if (!name->Equals(v8_str("foo"))) return; |
| 18534 Local<Object>::Cast(info.This())->Set(v8_str("y"), v8_num(23)); | 18530 Local<Object>::Cast(info.This())->Set(v8_str("y"), v8_num(23)); |
| 18535 info.GetReturnValue().Set(v8_num(23)); | 18531 info.GetReturnValue().Set(v8_num(23)); |
| 18536 } | 18532 } |
| 18537 | 18533 |
| 18538 | 18534 |
| 18539 TEST(SetterOnConstructorPrototype) { | 18535 TEST(SetterOnConstructorPrototype) { |
| 18540 v8::Isolate* isolate = CcTest::isolate(); | 18536 v8::Isolate* isolate = CcTest::isolate(); |
| 18541 v8::HandleScope scope(isolate); | 18537 v8::HandleScope scope(isolate); |
| 18542 Local<FunctionTemplate> templ = FunctionTemplate::New(isolate); | 18538 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
| 18543 templ->SetHiddenPrototype(true); | 18539 templ->SetAccessor(v8_str("x"), GetterWhichReturns42, |
| 18544 templ->InstanceTemplate()->SetAccessor(v8_str("x"), GetterWhichReturns42, | 18540 SetterWhichSetsYOnThisTo23); |
| 18545 SetterWhichSetsYOnThisTo23); | |
| 18546 LocalContext context; | 18541 LocalContext context; |
| 18547 context->Global()->Set(v8_str("P"), templ->InstanceTemplate()->NewInstance()); | 18542 context->Global()->Set(v8_str("P"), templ->NewInstance()); |
| 18548 CompileRun("function C1() {" | 18543 CompileRun("function C1() {" |
| 18549 " this.x = 23;" | 18544 " this.x = 23;" |
| 18550 "};" | 18545 "};" |
| 18551 "C1.prototype = P;" | 18546 "C1.prototype = P;" |
| 18552 "function C2() {" | 18547 "function C2() {" |
| 18553 " this.x = 23" | 18548 " this.x = 23" |
| 18554 "};" | 18549 "};" |
| 18555 "C2.prototype = { };" | 18550 "C2.prototype = { };" |
| 18556 "C2.prototype.__proto__ = P;"); | 18551 "C2.prototype.__proto__ = P;"); |
| 18557 | 18552 |
| 18558 v8::Local<v8::Script> script; | 18553 v8::Local<v8::Script> script; |
| 18559 script = v8_compile("new C1();"); | 18554 script = v8_compile("new C1();"); |
| 18560 for (int i = 0; i < 10; i++) { | 18555 for (int i = 0; i < 10; i++) { |
| 18561 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); | 18556 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); |
| 18562 CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value()); | 18557 CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value()); |
| 18563 CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value()); | 18558 CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value()); |
| 18564 } | 18559 } |
| 18565 | 18560 |
| 18566 script = v8_compile("new C2();"); | 18561 script = v8_compile("new C2();"); |
| 18567 for (int i = 0; i < 10; i++) { | 18562 for (int i = 0; i < 10; i++) { |
| 18568 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run()); | 18563 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run()); |
| 18569 CHECK_EQ(23, c2->Get(v8_str("x"))->Int32Value()); | 18564 CHECK_EQ(42, c2->Get(v8_str("x"))->Int32Value()); |
| 18565 CHECK_EQ(23, c2->Get(v8_str("y"))->Int32Value()); |
| 18570 } | 18566 } |
| 18571 } | 18567 } |
| 18572 | 18568 |
| 18573 | 18569 |
| 18574 static void NamedPropertyGetterWhichReturns42( | 18570 static void NamedPropertyGetterWhichReturns42( |
| 18575 Local<String> name, | 18571 Local<String> name, |
| 18576 const v8::PropertyCallbackInfo<v8::Value>& info) { | 18572 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 18577 info.GetReturnValue().Set(v8_num(42)); | 18573 info.GetReturnValue().Set(v8_num(42)); |
| 18578 } | 18574 } |
| 18579 | 18575 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 18645 script = v8_compile("new C1();"); | 18641 script = v8_compile("new C1();"); |
| 18646 // Allow enough iterations for the inobject slack tracking logic | 18642 // Allow enough iterations for the inobject slack tracking logic |
| 18647 // to finalize instance size and install the fast construct stub. | 18643 // to finalize instance size and install the fast construct stub. |
| 18648 for (int i = 0; i < 256; i++) { | 18644 for (int i = 0; i < 256; i++) { |
| 18649 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); | 18645 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); |
| 18650 CHECK_EQ(23, c1->Get(v8_str("x"))->Int32Value()); | 18646 CHECK_EQ(23, c1->Get(v8_str("x"))->Int32Value()); |
| 18651 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value()); | 18647 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value()); |
| 18652 } | 18648 } |
| 18653 | 18649 |
| 18654 // Use an API object with accessors as prototype. | 18650 // Use an API object with accessors as prototype. |
| 18655 Local<FunctionTemplate> templ = FunctionTemplate::New(isolate); | 18651 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
| 18656 templ->SetHiddenPrototype(true); | 18652 templ->SetAccessor(v8_str("x"), GetterWhichReturns42, |
| 18657 templ->InstanceTemplate()->SetAccessor(v8_str("x"), GetterWhichReturns42, | 18653 SetterWhichSetsYOnThisTo23); |
| 18658 SetterWhichSetsYOnThisTo23); | 18654 context->Global()->Set(v8_str("P"), templ->NewInstance()); |
| 18659 context->Global()->Set(v8_str("P"), templ->InstanceTemplate()->NewInstance()); | |
| 18660 | 18655 |
| 18661 // This compile will get the code from the compilation cache. | 18656 // This compile will get the code from the compilation cache. |
| 18662 CompileRun(source); | 18657 CompileRun(source); |
| 18663 | 18658 |
| 18664 script = v8_compile("new C1();"); | 18659 script = v8_compile("new C1();"); |
| 18665 for (int i = 0; i < 10; i++) { | 18660 for (int i = 0; i < 10; i++) { |
| 18666 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); | 18661 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); |
| 18667 CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value()); | 18662 CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value()); |
| 18668 CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value()); | 18663 CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value()); |
| 18669 } | 18664 } |
| (...skipping 2394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 21064 static void InstanceCheckedSetter(Local<String> name, | 21059 static void InstanceCheckedSetter(Local<String> name, |
| 21065 Local<Value> value, | 21060 Local<Value> value, |
| 21066 const v8::PropertyCallbackInfo<void>& info) { | 21061 const v8::PropertyCallbackInfo<void>& info) { |
| 21067 CHECK_EQ(name, v8_str("foo")); | 21062 CHECK_EQ(name, v8_str("foo")); |
| 21068 CHECK_EQ(value, v8_num(23)); | 21063 CHECK_EQ(value, v8_num(23)); |
| 21069 instance_checked_setter_count++; | 21064 instance_checked_setter_count++; |
| 21070 } | 21065 } |
| 21071 | 21066 |
| 21072 | 21067 |
| 21073 static void CheckInstanceCheckedResult(int getters, int setters, | 21068 static void CheckInstanceCheckedResult(int getters, int setters, |
| 21074 bool expects_callbacks, bool is_setter, | 21069 bool expects_callbacks, |
| 21075 TryCatch* try_catch) { | 21070 TryCatch* try_catch) { |
| 21076 if (expects_callbacks) { | 21071 if (expects_callbacks) { |
| 21077 CHECK(!try_catch->HasCaught()); | 21072 CHECK(!try_catch->HasCaught()); |
| 21078 CHECK_EQ(getters, instance_checked_getter_count); | 21073 CHECK_EQ(getters, instance_checked_getter_count); |
| 21079 CHECK_EQ(setters, instance_checked_setter_count); | 21074 CHECK_EQ(setters, instance_checked_setter_count); |
| 21080 } else { | 21075 } else { |
| 21081 CHECK((is_setter && !try_catch->HasCaught()) || | 21076 CHECK(try_catch->HasCaught()); |
| 21082 (!is_setter && try_catch->HasCaught())); | |
| 21083 CHECK_EQ(0, instance_checked_getter_count); | 21077 CHECK_EQ(0, instance_checked_getter_count); |
| 21084 CHECK_EQ(0, instance_checked_setter_count); | 21078 CHECK_EQ(0, instance_checked_setter_count); |
| 21085 } | 21079 } |
| 21086 try_catch->Reset(); | 21080 try_catch->Reset(); |
| 21087 } | 21081 } |
| 21088 | 21082 |
| 21089 | 21083 |
| 21090 static void CheckInstanceCheckedAccessors(bool expects_callbacks) { | 21084 static void CheckInstanceCheckedAccessors(bool expects_callbacks) { |
| 21091 instance_checked_getter_count = 0; | 21085 instance_checked_getter_count = 0; |
| 21092 instance_checked_setter_count = 0; | 21086 instance_checked_setter_count = 0; |
| 21093 TryCatch try_catch; | 21087 TryCatch try_catch; |
| 21094 | 21088 |
| 21095 // Test path through generic runtime code. | 21089 // Test path through generic runtime code. |
| 21096 CompileRun("obj.foo"); | 21090 CompileRun("obj.foo"); |
| 21097 CheckInstanceCheckedResult(1, 0, expects_callbacks, false, &try_catch); | 21091 CheckInstanceCheckedResult(1, 0, expects_callbacks, &try_catch); |
| 21098 CompileRun("obj.foo = 23"); | 21092 CompileRun("obj.foo = 23"); |
| 21099 CheckInstanceCheckedResult(1, 1, expects_callbacks, true, &try_catch); | 21093 CheckInstanceCheckedResult(1, 1, expects_callbacks, &try_catch); |
| 21100 if (!expects_callbacks) CompileRun("delete obj.foo"); | |
| 21101 | 21094 |
| 21102 // Test path through generated LoadIC and StoredIC. | 21095 // Test path through generated LoadIC and StoredIC. |
| 21103 CompileRun("function test_get(o) { o.foo; }" | 21096 CompileRun("function test_get(o) { o.foo; }" |
| 21104 "test_get(obj);"); | 21097 "test_get(obj);"); |
| 21105 CheckInstanceCheckedResult(2, 1, expects_callbacks, false, &try_catch); | 21098 CheckInstanceCheckedResult(2, 1, expects_callbacks, &try_catch); |
| 21106 CompileRun("test_get(obj);"); | 21099 CompileRun("test_get(obj);"); |
| 21107 CheckInstanceCheckedResult(3, 1, expects_callbacks, false, &try_catch); | 21100 CheckInstanceCheckedResult(3, 1, expects_callbacks, &try_catch); |
| 21108 CompileRun("test_get(obj);"); | 21101 CompileRun("test_get(obj);"); |
| 21109 CheckInstanceCheckedResult(4, 1, expects_callbacks, false, &try_catch); | 21102 CheckInstanceCheckedResult(4, 1, expects_callbacks, &try_catch); |
| 21110 CompileRun("function test_set(o) { o.foo = 23; }" | 21103 CompileRun("function test_set(o) { o.foo = 23; }" |
| 21111 "test_set(obj);"); | 21104 "test_set(obj);"); |
| 21112 CheckInstanceCheckedResult(4, 2, expects_callbacks, true, &try_catch); | 21105 CheckInstanceCheckedResult(4, 2, expects_callbacks, &try_catch); |
| 21113 if (!expects_callbacks) CompileRun("delete obj.foo"); | |
| 21114 CompileRun("test_set(obj);"); | 21106 CompileRun("test_set(obj);"); |
| 21115 CheckInstanceCheckedResult(4, 3, expects_callbacks, true, &try_catch); | 21107 CheckInstanceCheckedResult(4, 3, expects_callbacks, &try_catch); |
| 21116 if (!expects_callbacks) CompileRun("delete obj.foo"); | |
| 21117 CompileRun("test_set(obj);"); | 21108 CompileRun("test_set(obj);"); |
| 21118 CheckInstanceCheckedResult(4, 4, expects_callbacks, true, &try_catch); | 21109 CheckInstanceCheckedResult(4, 4, expects_callbacks, &try_catch); |
| 21119 if (!expects_callbacks) CompileRun("delete obj.foo"); | |
| 21120 | 21110 |
| 21121 // Test path through optimized code. | 21111 // Test path through optimized code. |
| 21122 CompileRun("%OptimizeFunctionOnNextCall(test_get);" | 21112 CompileRun("%OptimizeFunctionOnNextCall(test_get);" |
| 21123 "test_get(obj);"); | 21113 "test_get(obj);"); |
| 21124 CheckInstanceCheckedResult(5, 4, expects_callbacks, false, &try_catch); | 21114 CheckInstanceCheckedResult(5, 4, expects_callbacks, &try_catch); |
| 21125 CompileRun("%OptimizeFunctionOnNextCall(test_set);" | 21115 CompileRun("%OptimizeFunctionOnNextCall(test_set);" |
| 21126 "test_set(obj);"); | 21116 "test_set(obj);"); |
| 21127 if (!expects_callbacks) CompileRun("delete obj.foo"); | 21117 CheckInstanceCheckedResult(5, 5, expects_callbacks, &try_catch); |
| 21128 CheckInstanceCheckedResult(5, 5, expects_callbacks, true, &try_catch); | |
| 21129 | 21118 |
| 21130 // Cleanup so that closures start out fresh in next check. | 21119 // Cleanup so that closures start out fresh in next check. |
| 21131 CompileRun("%DeoptimizeFunction(test_get);" | 21120 CompileRun("%DeoptimizeFunction(test_get);" |
| 21132 "%ClearFunctionTypeFeedback(test_get);" | 21121 "%ClearFunctionTypeFeedback(test_get);" |
| 21133 "%DeoptimizeFunction(test_set);" | 21122 "%DeoptimizeFunction(test_set);" |
| 21134 "%ClearFunctionTypeFeedback(test_set);"); | 21123 "%ClearFunctionTypeFeedback(test_set);"); |
| 21135 } | 21124 } |
| 21136 | 21125 |
| 21137 | 21126 |
| 21138 THREADED_TEST(InstanceCheckOnInstanceAccessor) { | 21127 THREADED_TEST(InstanceCheckOnInstanceAccessor) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 21190 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj")))); | 21179 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj")))); |
| 21191 CheckInstanceCheckedAccessors(false); | 21180 CheckInstanceCheckedAccessors(false); |
| 21192 } | 21181 } |
| 21193 | 21182 |
| 21194 | 21183 |
| 21195 THREADED_TEST(InstanceCheckOnPrototypeAccessor) { | 21184 THREADED_TEST(InstanceCheckOnPrototypeAccessor) { |
| 21196 v8::internal::FLAG_allow_natives_syntax = true; | 21185 v8::internal::FLAG_allow_natives_syntax = true; |
| 21197 LocalContext context; | 21186 LocalContext context; |
| 21198 v8::HandleScope scope(context->GetIsolate()); | 21187 v8::HandleScope scope(context->GetIsolate()); |
| 21199 | 21188 |
| 21200 Local<FunctionTemplate> proto_templ = | |
| 21201 FunctionTemplate::New(context->GetIsolate()); | |
| 21202 proto_templ->SetHiddenPrototype(true); | |
| 21203 Local<ObjectTemplate> proto = proto_templ->InstanceTemplate(); | |
| 21204 proto->SetAccessor( | |
| 21205 v8_str("foo"), InstanceCheckedGetter, InstanceCheckedSetter, | |
| 21206 Handle<Value>(), v8::DEFAULT, v8::None, | |
| 21207 v8::AccessorSignature::New(context->GetIsolate(), proto_templ)); | |
| 21208 Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate()); | 21189 Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate()); |
| 21209 templ->Inherit(proto_templ); | 21190 Local<ObjectTemplate> proto = templ->PrototypeTemplate(); |
| 21191 proto->SetAccessor(v8_str("foo"), InstanceCheckedGetter, |
| 21192 InstanceCheckedSetter, Handle<Value>(), v8::DEFAULT, |
| 21193 v8::None, |
| 21194 v8::AccessorSignature::New(context->GetIsolate(), templ)); |
| 21210 context->Global()->Set(v8_str("f"), templ->GetFunction()); | 21195 context->Global()->Set(v8_str("f"), templ->GetFunction()); |
| 21211 | 21196 |
| 21212 printf("Testing positive ...\n"); | 21197 printf("Testing positive ...\n"); |
| 21213 CompileRun("var obj = new f();"); | 21198 CompileRun("var obj = new f();"); |
| 21214 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); | 21199 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); |
| 21215 CheckInstanceCheckedAccessors(true); | 21200 CheckInstanceCheckedAccessors(true); |
| 21216 | 21201 |
| 21217 printf("Testing negative ...\n"); | 21202 printf("Testing negative ...\n"); |
| 21218 CompileRun("var obj = {};" | 21203 CompileRun("var obj = {};" |
| 21219 "obj.__proto__ = new f();"); | 21204 "obj.__proto__ = new f();"); |
| (...skipping 1684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 22904 desc = x->GetOwnPropertyDescriptor(v8_str("p1")); | 22889 desc = x->GetOwnPropertyDescriptor(v8_str("p1")); |
| 22905 Local<Function> set = | 22890 Local<Function> set = |
| 22906 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("set"))); | 22891 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("set"))); |
| 22907 Local<Function> get = | 22892 Local<Function> get = |
| 22908 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("get"))); | 22893 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("get"))); |
| 22909 CHECK_EQ(v8_num(13), get->Call(x, 0, NULL)); | 22894 CHECK_EQ(v8_num(13), get->Call(x, 0, NULL)); |
| 22910 Handle<Value> args[] = { v8_num(14) }; | 22895 Handle<Value> args[] = { v8_num(14) }; |
| 22911 set->Call(x, 1, args); | 22896 set->Call(x, 1, args); |
| 22912 CHECK_EQ(v8_num(14), get->Call(x, 0, NULL)); | 22897 CHECK_EQ(v8_num(14), get->Call(x, 0, NULL)); |
| 22913 } | 22898 } |
| OLD | NEW |