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 1968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1979 | 1979 |
1980 // base1 and base2 cannot cross reference to each's prototype | 1980 // base1 and base2 cannot cross reference to each's prototype |
1981 CHECK(v8_compile("obj.v2")->Run()->IsUndefined()); | 1981 CHECK(v8_compile("obj.v2")->Run()->IsUndefined()); |
1982 CHECK(v8_compile("obj2.v1")->Run()->IsUndefined()); | 1982 CHECK(v8_compile("obj2.v1")->Run()->IsUndefined()); |
1983 } | 1983 } |
1984 | 1984 |
1985 | 1985 |
1986 int echo_named_call_count; | 1986 int echo_named_call_count; |
1987 | 1987 |
1988 | 1988 |
1989 static void EchoNamedProperty(Local<String> name, | 1989 static void EchoNamedProperty(Local<Name> name, |
1990 const v8::PropertyCallbackInfo<v8::Value>& info) { | 1990 const v8::PropertyCallbackInfo<v8::Value>& info) { |
1991 ApiTestFuzzer::Fuzz(); | 1991 ApiTestFuzzer::Fuzz(); |
1992 CHECK_EQ(v8_str("data"), info.Data()); | 1992 CHECK_EQ(v8_str("data"), info.Data()); |
1993 echo_named_call_count++; | 1993 echo_named_call_count++; |
1994 info.GetReturnValue().Set(name); | 1994 info.GetReturnValue().Set(name); |
1995 } | 1995 } |
1996 | 1996 |
1997 | 1997 |
1998 // Helper functions for Interceptor/Accessor interaction tests | 1998 // Helper functions for Interceptor/Accessor interaction tests |
1999 | 1999 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2034 Local<Symbol> sym = Local<Symbol>::Cast(name); | 2034 Local<Symbol> sym = Local<Symbol>::Cast(name); |
2035 if (sym->Name()->IsUndefined()) return; | 2035 if (sym->Name()->IsUndefined()) return; |
2036 info.GetReturnValue().Set(info.Data()); | 2036 info.GetReturnValue().Set(info.Data()); |
2037 } | 2037 } |
2038 | 2038 |
2039 static void ThrowingSymbolAccessorGetter( | 2039 static void ThrowingSymbolAccessorGetter( |
2040 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { | 2040 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
2041 info.GetReturnValue().Set(info.GetIsolate()->ThrowException(name)); | 2041 info.GetReturnValue().Set(info.GetIsolate()->ThrowException(name)); |
2042 } | 2042 } |
2043 | 2043 |
2044 void EmptyInterceptorGetter(Local<String> name, | |
2045 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
2046 } | |
2047 | 2044 |
2048 void EmptyInterceptorSetter(Local<String> name, | 2045 void EmptyInterceptorGetter(Local<Name> name, |
2049 Local<Value> value, | 2046 const v8::PropertyCallbackInfo<v8::Value>& info) {} |
2050 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
2051 } | |
2052 | 2047 |
2053 void InterceptorGetter(Local<String> name, | 2048 |
2054 const v8::PropertyCallbackInfo<v8::Value>& info) { | 2049 void EmptyInterceptorSetter(Local<Name> name, Local<Value> value, |
2055 // Intercept names that start with 'interceptor_'. | 2050 const v8::PropertyCallbackInfo<v8::Value>& info) {} |
| 2051 |
| 2052 |
| 2053 void EmptyGenericInterceptorGetter( |
| 2054 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) {} |
| 2055 |
| 2056 |
| 2057 void EmptyGenericInterceptorSetter( |
| 2058 Local<Name> name, Local<Value> value, |
| 2059 const v8::PropertyCallbackInfo<v8::Value>& info) {} |
| 2060 |
| 2061 |
| 2062 void StringInterceptorGetter( |
| 2063 Local<String> name, |
| 2064 const v8::PropertyCallbackInfo<v8::Value>& |
| 2065 info) { // Intercept names that start with 'interceptor_'. |
2056 String::Utf8Value utf8(name); | 2066 String::Utf8Value utf8(name); |
2057 char* name_str = *utf8; | 2067 char* name_str = *utf8; |
2058 char prefix[] = "interceptor_"; | 2068 char prefix[] = "interceptor_"; |
2059 int i; | 2069 int i; |
2060 for (i = 0; name_str[i] && prefix[i]; ++i) { | 2070 for (i = 0; name_str[i] && prefix[i]; ++i) { |
2061 if (name_str[i] != prefix[i]) return; | 2071 if (name_str[i] != prefix[i]) return; |
2062 } | 2072 } |
2063 Handle<Object> self = Handle<Object>::Cast(info.This()); | 2073 Handle<Object> self = Handle<Object>::Cast(info.This()); |
2064 info.GetReturnValue().Set(self->GetHiddenValue(v8_str(name_str + i))); | 2074 info.GetReturnValue().Set(self->GetHiddenValue(v8_str(name_str + i))); |
2065 } | 2075 } |
2066 | 2076 |
2067 void InterceptorSetter(Local<String> name, | 2077 |
2068 Local<Value> value, | 2078 void StringInterceptorSetter(Local<String> name, Local<Value> value, |
2069 const v8::PropertyCallbackInfo<v8::Value>& info) { | 2079 const v8::PropertyCallbackInfo<v8::Value>& info) { |
2070 // Intercept accesses that set certain integer values, for which the name does | 2080 // Intercept accesses that set certain integer values, for which the name does |
2071 // not start with 'accessor_'. | 2081 // not start with 'accessor_'. |
2072 String::Utf8Value utf8(name); | 2082 String::Utf8Value utf8(name); |
2073 char* name_str = *utf8; | 2083 char* name_str = *utf8; |
2074 char prefix[] = "accessor_"; | 2084 char prefix[] = "accessor_"; |
2075 int i; | 2085 int i; |
2076 for (i = 0; name_str[i] && prefix[i]; ++i) { | 2086 for (i = 0; name_str[i] && prefix[i]; ++i) { |
2077 if (name_str[i] != prefix[i]) break; | 2087 if (name_str[i] != prefix[i]) break; |
2078 } | 2088 } |
2079 if (!prefix[i]) return; | 2089 if (!prefix[i]) return; |
2080 | 2090 |
2081 if (value->IsInt32() && value->Int32Value() < 10000) { | 2091 if (value->IsInt32() && value->Int32Value() < 10000) { |
2082 Handle<Object> self = Handle<Object>::Cast(info.This()); | 2092 Handle<Object> self = Handle<Object>::Cast(info.This()); |
2083 self->SetHiddenValue(name, value); | 2093 self->SetHiddenValue(name, value); |
2084 info.GetReturnValue().Set(value); | 2094 info.GetReturnValue().Set(value); |
2085 } | 2095 } |
2086 } | 2096 } |
2087 | 2097 |
| 2098 void InterceptorGetter(Local<Name> generic_name, |
| 2099 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 2100 if (generic_name->IsSymbol()) return; |
| 2101 StringInterceptorGetter(Local<String>::Cast(generic_name), info); |
| 2102 } |
| 2103 |
| 2104 void InterceptorSetter(Local<Name> generic_name, Local<Value> value, |
| 2105 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 2106 if (generic_name->IsSymbol()) return; |
| 2107 StringInterceptorSetter(Local<String>::Cast(generic_name), value, info); |
| 2108 } |
| 2109 |
| 2110 void GenericInterceptorGetter(Local<Name> generic_name, |
| 2111 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 2112 Local<String> str; |
| 2113 if (generic_name->IsSymbol()) { |
| 2114 Local<Value> name = Local<Symbol>::Cast(generic_name)->Name(); |
| 2115 if (name->IsUndefined()) return; |
| 2116 str = String::Concat(v8_str("_sym_"), Local<String>::Cast(name)); |
| 2117 } else { |
| 2118 Local<String> name = Local<String>::Cast(generic_name); |
| 2119 String::Utf8Value utf8(name); |
| 2120 char* name_str = *utf8; |
| 2121 if (*name_str == '_') return; |
| 2122 str = String::Concat(v8_str("_str_"), name); |
| 2123 } |
| 2124 |
| 2125 Handle<Object> self = Handle<Object>::Cast(info.This()); |
| 2126 info.GetReturnValue().Set(self->Get(str)); |
| 2127 } |
| 2128 |
| 2129 void GenericInterceptorSetter(Local<Name> generic_name, Local<Value> value, |
| 2130 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 2131 Local<String> str; |
| 2132 if (generic_name->IsSymbol()) { |
| 2133 Local<Value> name = Local<Symbol>::Cast(generic_name)->Name(); |
| 2134 if (name->IsUndefined()) return; |
| 2135 str = String::Concat(v8_str("_sym_"), Local<String>::Cast(name)); |
| 2136 } else { |
| 2137 Local<String> name = Local<String>::Cast(generic_name); |
| 2138 String::Utf8Value utf8(name); |
| 2139 char* name_str = *utf8; |
| 2140 if (*name_str == '_') return; |
| 2141 str = String::Concat(v8_str("_str_"), name); |
| 2142 } |
| 2143 |
| 2144 Handle<Object> self = Handle<Object>::Cast(info.This()); |
| 2145 self->Set(str, value); |
| 2146 info.GetReturnValue().Set(value); |
| 2147 } |
| 2148 |
2088 void AddAccessor(Handle<FunctionTemplate> templ, | 2149 void AddAccessor(Handle<FunctionTemplate> templ, |
2089 Handle<String> name, | 2150 Handle<String> name, |
2090 v8::AccessorGetterCallback getter, | 2151 v8::AccessorGetterCallback getter, |
2091 v8::AccessorSetterCallback setter) { | 2152 v8::AccessorSetterCallback setter) { |
2092 templ->PrototypeTemplate()->SetAccessor(name, getter, setter); | 2153 templ->PrototypeTemplate()->SetAccessor(name, getter, setter); |
2093 } | 2154 } |
2094 | 2155 |
2095 void AddInterceptor(Handle<FunctionTemplate> templ, | 2156 void AddInterceptor(Handle<FunctionTemplate> templ, |
2096 v8::NamedPropertyGetterCallback getter, | 2157 v8::NamedPropertyGetterCallback getter, |
2097 v8::NamedPropertySetterCallback setter) { | 2158 v8::NamedPropertySetterCallback setter) { |
2098 templ->InstanceTemplate()->SetNamedPropertyHandler(getter, setter); | 2159 templ->InstanceTemplate()->SetNamedPropertyHandler(getter, setter); |
2099 } | 2160 } |
2100 | 2161 |
2101 | 2162 |
2102 void AddAccessor(Handle<FunctionTemplate> templ, | 2163 void AddAccessor(Handle<FunctionTemplate> templ, |
2103 Handle<Name> name, | 2164 Handle<Name> name, |
2104 v8::AccessorNameGetterCallback getter, | 2165 v8::AccessorNameGetterCallback getter, |
2105 v8::AccessorNameSetterCallback setter) { | 2166 v8::AccessorNameSetterCallback setter) { |
2106 templ->PrototypeTemplate()->SetAccessor(name, getter, setter); | 2167 templ->PrototypeTemplate()->SetAccessor(name, getter, setter); |
2107 } | 2168 } |
2108 | 2169 |
| 2170 void AddInterceptor(Handle<FunctionTemplate> templ, |
| 2171 v8::GenericNamedPropertyGetterCallback getter, |
| 2172 v8::GenericNamedPropertySetterCallback setter) { |
| 2173 templ->InstanceTemplate()->SetHandler( |
| 2174 v8::NamedPropertyHandlerConfiguration(getter, setter)); |
| 2175 } |
| 2176 |
2109 | 2177 |
2110 THREADED_TEST(EmptyInterceptorDoesNotShadowAccessors) { | 2178 THREADED_TEST(EmptyInterceptorDoesNotShadowAccessors) { |
2111 v8::HandleScope scope(CcTest::isolate()); | 2179 v8::HandleScope scope(CcTest::isolate()); |
2112 Handle<FunctionTemplate> parent = FunctionTemplate::New(CcTest::isolate()); | 2180 Handle<FunctionTemplate> parent = FunctionTemplate::New(CcTest::isolate()); |
2113 Handle<FunctionTemplate> child = FunctionTemplate::New(CcTest::isolate()); | 2181 Handle<FunctionTemplate> child = FunctionTemplate::New(CcTest::isolate()); |
2114 child->Inherit(parent); | 2182 child->Inherit(parent); |
2115 AddAccessor(parent, v8_str("age"), | 2183 AddAccessor(parent, v8_str("age"), |
2116 SimpleAccessorGetter, SimpleAccessorSetter); | 2184 SimpleAccessorGetter, SimpleAccessorSetter); |
2117 AddInterceptor(child, EmptyInterceptorGetter, EmptyInterceptorSetter); | 2185 AddInterceptor(child, EmptyInterceptorGetter, EmptyInterceptorSetter); |
2118 LocalContext env; | 2186 LocalContext env; |
2119 env->Global()->Set(v8_str("Child"), child->GetFunction()); | 2187 env->Global()->Set(v8_str("Child"), child->GetFunction()); |
2120 CompileRun("var child = new Child;" | 2188 CompileRun("var child = new Child;" |
2121 "child.age = 10;"); | 2189 "child.age = 10;"); |
2122 ExpectBoolean("child.hasOwnProperty('age')", false); | 2190 ExpectBoolean("child.hasOwnProperty('age')", false); |
2123 ExpectInt32("child.age", 10); | 2191 ExpectInt32("child.age", 10); |
2124 ExpectInt32("child.accessor_age", 10); | 2192 ExpectInt32("child.accessor_age", 10); |
2125 } | 2193 } |
2126 | 2194 |
2127 | 2195 |
| 2196 THREADED_TEST(LegacyInterceptorDoesNotSeeSymbols) { |
| 2197 LocalContext env; |
| 2198 v8::Isolate* isolate = CcTest::isolate(); |
| 2199 v8::HandleScope scope(isolate); |
| 2200 Handle<FunctionTemplate> parent = FunctionTemplate::New(isolate); |
| 2201 Handle<FunctionTemplate> child = FunctionTemplate::New(isolate); |
| 2202 v8::Local<v8::Symbol> age = v8::Symbol::New(isolate, v8_str("age")); |
| 2203 |
| 2204 child->Inherit(parent); |
| 2205 AddAccessor(parent, age, SymbolAccessorGetter, SymbolAccessorSetter); |
| 2206 AddInterceptor(child, StringInterceptorGetter, StringInterceptorSetter); |
| 2207 |
| 2208 env->Global()->Set(v8_str("Child"), child->GetFunction()); |
| 2209 env->Global()->Set(v8_str("age"), age); |
| 2210 CompileRun( |
| 2211 "var child = new Child;" |
| 2212 "child[age] = 10;"); |
| 2213 ExpectInt32("child[age]", 10); |
| 2214 ExpectBoolean("child.hasOwnProperty('age')", false); |
| 2215 ExpectBoolean("child.hasOwnProperty('accessor_age')", true); |
| 2216 } |
| 2217 |
| 2218 |
| 2219 THREADED_TEST(GenericInterceptorDoesSeeSymbols) { |
| 2220 LocalContext env; |
| 2221 v8::Isolate* isolate = CcTest::isolate(); |
| 2222 v8::HandleScope scope(isolate); |
| 2223 Handle<FunctionTemplate> parent = FunctionTemplate::New(isolate); |
| 2224 Handle<FunctionTemplate> child = FunctionTemplate::New(isolate); |
| 2225 v8::Local<v8::Symbol> age = v8::Symbol::New(isolate, v8_str("age")); |
| 2226 v8::Local<v8::Symbol> anon = v8::Symbol::New(isolate); |
| 2227 |
| 2228 child->Inherit(parent); |
| 2229 AddAccessor(parent, age, SymbolAccessorGetter, SymbolAccessorSetter); |
| 2230 AddInterceptor(child, GenericInterceptorGetter, GenericInterceptorSetter); |
| 2231 |
| 2232 env->Global()->Set(v8_str("Child"), child->GetFunction()); |
| 2233 env->Global()->Set(v8_str("age"), age); |
| 2234 env->Global()->Set(v8_str("anon"), anon); |
| 2235 CompileRun( |
| 2236 "var child = new Child;" |
| 2237 "child[age] = 10;"); |
| 2238 ExpectInt32("child[age]", 10); |
| 2239 ExpectInt32("child._sym_age", 10); |
| 2240 |
| 2241 // Check that it also sees strings. |
| 2242 CompileRun("child.foo = 47"); |
| 2243 ExpectInt32("child.foo", 47); |
| 2244 ExpectInt32("child._str_foo", 47); |
| 2245 |
| 2246 // Check that the interceptor can punt (in this case, on anonymous symbols). |
| 2247 CompileRun("child[anon] = 31337"); |
| 2248 ExpectInt32("child[anon]", 31337); |
| 2249 } |
| 2250 |
| 2251 |
2128 THREADED_TEST(ExecutableAccessorIsPreservedOnAttributeChange) { | 2252 THREADED_TEST(ExecutableAccessorIsPreservedOnAttributeChange) { |
2129 v8::Isolate* isolate = CcTest::isolate(); | 2253 v8::Isolate* isolate = CcTest::isolate(); |
2130 v8::HandleScope scope(isolate); | 2254 v8::HandleScope scope(isolate); |
2131 LocalContext env; | 2255 LocalContext env; |
2132 v8::Local<v8::Value> res = CompileRun("var a = []; a;"); | 2256 v8::Local<v8::Value> res = CompileRun("var a = []; a;"); |
2133 i::Handle<i::JSObject> a(v8::Utils::OpenHandle(v8::Object::Cast(*res))); | 2257 i::Handle<i::JSObject> a(v8::Utils::OpenHandle(v8::Object::Cast(*res))); |
2134 CHECK(a->map()->instance_descriptors()->IsFixedArray()); | 2258 CHECK(a->map()->instance_descriptors()->IsFixedArray()); |
2135 CHECK_GT(i::FixedArray::cast(a->map()->instance_descriptors())->length(), 0); | 2259 CHECK_GT(i::FixedArray::cast(a->map()->instance_descriptors())->length(), 0); |
2136 CompileRun("Object.defineProperty(a, 'length', { writable: false });"); | 2260 CompileRun("Object.defineProperty(a, 'length', { writable: false });"); |
2137 CHECK_EQ(i::FixedArray::cast(a->map()->instance_descriptors())->length(), 0); | 2261 CHECK_EQ(i::FixedArray::cast(a->map()->instance_descriptors())->length(), 0); |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2363 // The last i goes to the interceptor. | 2487 // The last i goes to the interceptor. |
2364 ExpectInt32("child.interceptor_age", 9999); | 2488 ExpectInt32("child.interceptor_age", 9999); |
2365 } | 2489 } |
2366 | 2490 |
2367 | 2491 |
2368 THREADED_TEST(NamedPropertyHandlerGetter) { | 2492 THREADED_TEST(NamedPropertyHandlerGetter) { |
2369 echo_named_call_count = 0; | 2493 echo_named_call_count = 0; |
2370 v8::HandleScope scope(CcTest::isolate()); | 2494 v8::HandleScope scope(CcTest::isolate()); |
2371 v8::Handle<v8::FunctionTemplate> templ = | 2495 v8::Handle<v8::FunctionTemplate> templ = |
2372 v8::FunctionTemplate::New(CcTest::isolate()); | 2496 v8::FunctionTemplate::New(CcTest::isolate()); |
2373 templ->InstanceTemplate()->SetNamedPropertyHandler(EchoNamedProperty, | 2497 templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration( |
2374 0, 0, 0, 0, | 2498 EchoNamedProperty, 0, 0, 0, 0, v8_str("data"))); |
2375 v8_str("data")); | |
2376 LocalContext env; | 2499 LocalContext env; |
2377 env->Global()->Set(v8_str("obj"), | 2500 env->Global()->Set(v8_str("obj"), |
2378 templ->GetFunction()->NewInstance()); | 2501 templ->GetFunction()->NewInstance()); |
2379 CHECK_EQ(echo_named_call_count, 0); | 2502 CHECK_EQ(echo_named_call_count, 0); |
2380 v8_compile("obj.x")->Run(); | 2503 v8_compile("obj.x")->Run(); |
2381 CHECK_EQ(echo_named_call_count, 1); | 2504 CHECK_EQ(echo_named_call_count, 1); |
2382 const char* code = "var str = 'oddle'; obj[str] + obj.poddle;"; | 2505 const char* code = "var str = 'oddle'; obj[str] + obj.poddle;"; |
2383 v8::Handle<Value> str = CompileRun(code); | 2506 v8::Handle<Value> str = CompileRun(code); |
2384 String::Utf8Value value(str); | 2507 String::Utf8Value value(str); |
2385 CHECK_EQ(*value, "oddlepoddle"); | 2508 CHECK_EQ(*value, "oddlepoddle"); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2422 | 2545 |
2423 static void CheckThisIndexedPropertyHandler( | 2546 static void CheckThisIndexedPropertyHandler( |
2424 uint32_t index, | 2547 uint32_t index, |
2425 const v8::PropertyCallbackInfo<v8::Value>& info) { | 2548 const v8::PropertyCallbackInfo<v8::Value>& info) { |
2426 CheckReturnValue(info, FUNCTION_ADDR(CheckThisIndexedPropertyHandler)); | 2549 CheckReturnValue(info, FUNCTION_ADDR(CheckThisIndexedPropertyHandler)); |
2427 ApiTestFuzzer::Fuzz(); | 2550 ApiTestFuzzer::Fuzz(); |
2428 CHECK(info.This()->Equals(bottom)); | 2551 CHECK(info.This()->Equals(bottom)); |
2429 } | 2552 } |
2430 | 2553 |
2431 static void CheckThisNamedPropertyHandler( | 2554 static void CheckThisNamedPropertyHandler( |
2432 Local<String> name, | 2555 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
2433 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
2434 CheckReturnValue(info, FUNCTION_ADDR(CheckThisNamedPropertyHandler)); | 2556 CheckReturnValue(info, FUNCTION_ADDR(CheckThisNamedPropertyHandler)); |
2435 ApiTestFuzzer::Fuzz(); | 2557 ApiTestFuzzer::Fuzz(); |
2436 CHECK(info.This()->Equals(bottom)); | 2558 CHECK(info.This()->Equals(bottom)); |
2437 } | 2559 } |
2438 | 2560 |
2439 void CheckThisIndexedPropertySetter( | 2561 void CheckThisIndexedPropertySetter( |
2440 uint32_t index, | 2562 uint32_t index, |
2441 Local<Value> value, | 2563 Local<Value> value, |
2442 const v8::PropertyCallbackInfo<v8::Value>& info) { | 2564 const v8::PropertyCallbackInfo<v8::Value>& info) { |
2443 CheckReturnValue(info, FUNCTION_ADDR(CheckThisIndexedPropertySetter)); | 2565 CheckReturnValue(info, FUNCTION_ADDR(CheckThisIndexedPropertySetter)); |
2444 ApiTestFuzzer::Fuzz(); | 2566 ApiTestFuzzer::Fuzz(); |
2445 CHECK(info.This()->Equals(bottom)); | 2567 CHECK(info.This()->Equals(bottom)); |
2446 } | 2568 } |
2447 | 2569 |
2448 | 2570 |
2449 void CheckThisNamedPropertySetter( | 2571 void CheckThisNamedPropertySetter( |
2450 Local<String> property, | 2572 Local<Name> property, Local<Value> value, |
2451 Local<Value> value, | |
2452 const v8::PropertyCallbackInfo<v8::Value>& info) { | 2573 const v8::PropertyCallbackInfo<v8::Value>& info) { |
2453 CheckReturnValue(info, FUNCTION_ADDR(CheckThisNamedPropertySetter)); | 2574 CheckReturnValue(info, FUNCTION_ADDR(CheckThisNamedPropertySetter)); |
2454 ApiTestFuzzer::Fuzz(); | 2575 ApiTestFuzzer::Fuzz(); |
2455 CHECK(info.This()->Equals(bottom)); | 2576 CHECK(info.This()->Equals(bottom)); |
2456 } | 2577 } |
2457 | 2578 |
2458 void CheckThisIndexedPropertyQuery( | 2579 void CheckThisIndexedPropertyQuery( |
2459 uint32_t index, | 2580 uint32_t index, |
2460 const v8::PropertyCallbackInfo<v8::Integer>& info) { | 2581 const v8::PropertyCallbackInfo<v8::Integer>& info) { |
2461 CheckReturnValue(info, FUNCTION_ADDR(CheckThisIndexedPropertyQuery)); | 2582 CheckReturnValue(info, FUNCTION_ADDR(CheckThisIndexedPropertyQuery)); |
2462 ApiTestFuzzer::Fuzz(); | 2583 ApiTestFuzzer::Fuzz(); |
2463 CHECK(info.This()->Equals(bottom)); | 2584 CHECK(info.This()->Equals(bottom)); |
2464 } | 2585 } |
2465 | 2586 |
2466 | 2587 |
2467 void CheckThisNamedPropertyQuery( | 2588 void CheckThisNamedPropertyQuery( |
2468 Local<String> property, | 2589 Local<Name> property, const v8::PropertyCallbackInfo<v8::Integer>& info) { |
2469 const v8::PropertyCallbackInfo<v8::Integer>& info) { | |
2470 CheckReturnValue(info, FUNCTION_ADDR(CheckThisNamedPropertyQuery)); | 2590 CheckReturnValue(info, FUNCTION_ADDR(CheckThisNamedPropertyQuery)); |
2471 ApiTestFuzzer::Fuzz(); | 2591 ApiTestFuzzer::Fuzz(); |
2472 CHECK(info.This()->Equals(bottom)); | 2592 CHECK(info.This()->Equals(bottom)); |
2473 } | 2593 } |
2474 | 2594 |
2475 | 2595 |
2476 void CheckThisIndexedPropertyDeleter( | 2596 void CheckThisIndexedPropertyDeleter( |
2477 uint32_t index, | 2597 uint32_t index, |
2478 const v8::PropertyCallbackInfo<v8::Boolean>& info) { | 2598 const v8::PropertyCallbackInfo<v8::Boolean>& info) { |
2479 CheckReturnValue(info, FUNCTION_ADDR(CheckThisIndexedPropertyDeleter)); | 2599 CheckReturnValue(info, FUNCTION_ADDR(CheckThisIndexedPropertyDeleter)); |
2480 ApiTestFuzzer::Fuzz(); | 2600 ApiTestFuzzer::Fuzz(); |
2481 CHECK(info.This()->Equals(bottom)); | 2601 CHECK(info.This()->Equals(bottom)); |
2482 } | 2602 } |
2483 | 2603 |
2484 | 2604 |
2485 void CheckThisNamedPropertyDeleter( | 2605 void CheckThisNamedPropertyDeleter( |
2486 Local<String> property, | 2606 Local<Name> property, const v8::PropertyCallbackInfo<v8::Boolean>& info) { |
2487 const v8::PropertyCallbackInfo<v8::Boolean>& info) { | |
2488 CheckReturnValue(info, FUNCTION_ADDR(CheckThisNamedPropertyDeleter)); | 2607 CheckReturnValue(info, FUNCTION_ADDR(CheckThisNamedPropertyDeleter)); |
2489 ApiTestFuzzer::Fuzz(); | 2608 ApiTestFuzzer::Fuzz(); |
2490 CHECK(info.This()->Equals(bottom)); | 2609 CHECK(info.This()->Equals(bottom)); |
2491 } | 2610 } |
2492 | 2611 |
2493 | 2612 |
2494 void CheckThisIndexedPropertyEnumerator( | 2613 void CheckThisIndexedPropertyEnumerator( |
2495 const v8::PropertyCallbackInfo<v8::Array>& info) { | 2614 const v8::PropertyCallbackInfo<v8::Array>& info) { |
2496 CheckReturnValue(info, FUNCTION_ADDR(CheckThisIndexedPropertyEnumerator)); | 2615 CheckReturnValue(info, FUNCTION_ADDR(CheckThisIndexedPropertyEnumerator)); |
2497 ApiTestFuzzer::Fuzz(); | 2616 ApiTestFuzzer::Fuzz(); |
(...skipping 16 matching lines...) Expand all Loading... |
2514 | 2633 |
2515 // Set up a prototype chain with three interceptors. | 2634 // Set up a prototype chain with three interceptors. |
2516 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); | 2635 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); |
2517 templ->InstanceTemplate()->SetIndexedPropertyHandler( | 2636 templ->InstanceTemplate()->SetIndexedPropertyHandler( |
2518 CheckThisIndexedPropertyHandler, | 2637 CheckThisIndexedPropertyHandler, |
2519 CheckThisIndexedPropertySetter, | 2638 CheckThisIndexedPropertySetter, |
2520 CheckThisIndexedPropertyQuery, | 2639 CheckThisIndexedPropertyQuery, |
2521 CheckThisIndexedPropertyDeleter, | 2640 CheckThisIndexedPropertyDeleter, |
2522 CheckThisIndexedPropertyEnumerator); | 2641 CheckThisIndexedPropertyEnumerator); |
2523 | 2642 |
2524 templ->InstanceTemplate()->SetNamedPropertyHandler( | 2643 templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration( |
2525 CheckThisNamedPropertyHandler, | 2644 CheckThisNamedPropertyHandler, CheckThisNamedPropertySetter, |
2526 CheckThisNamedPropertySetter, | 2645 CheckThisNamedPropertyQuery, CheckThisNamedPropertyDeleter, |
2527 CheckThisNamedPropertyQuery, | 2646 CheckThisNamedPropertyEnumerator)); |
2528 CheckThisNamedPropertyDeleter, | |
2529 CheckThisNamedPropertyEnumerator); | |
2530 | 2647 |
2531 bottom = templ->GetFunction()->NewInstance(); | 2648 bottom = templ->GetFunction()->NewInstance(); |
2532 Local<v8::Object> top = templ->GetFunction()->NewInstance(); | 2649 Local<v8::Object> top = templ->GetFunction()->NewInstance(); |
2533 Local<v8::Object> middle = templ->GetFunction()->NewInstance(); | 2650 Local<v8::Object> middle = templ->GetFunction()->NewInstance(); |
2534 | 2651 |
2535 bottom->SetPrototype(middle); | 2652 bottom->SetPrototype(middle); |
2536 middle->SetPrototype(top); | 2653 middle->SetPrototype(top); |
2537 env->Global()->Set(v8_str("obj"), bottom); | 2654 env->Global()->Set(v8_str("obj"), bottom); |
2538 | 2655 |
2539 // Indexed and named get. | 2656 // Indexed and named get. |
(...skipping 11 matching lines...) Expand all Loading... |
2551 // Indexed and named deleter. | 2668 // Indexed and named deleter. |
2552 CompileRun("delete obj[0]"); | 2669 CompileRun("delete obj[0]"); |
2553 CompileRun("delete obj.x"); | 2670 CompileRun("delete obj.x"); |
2554 | 2671 |
2555 // Enumerators. | 2672 // Enumerators. |
2556 CompileRun("for (var p in obj) ;"); | 2673 CompileRun("for (var p in obj) ;"); |
2557 } | 2674 } |
2558 | 2675 |
2559 | 2676 |
2560 static void PrePropertyHandlerGet( | 2677 static void PrePropertyHandlerGet( |
2561 Local<String> key, | 2678 Local<Name> key, const v8::PropertyCallbackInfo<v8::Value>& info) { |
2562 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
2563 ApiTestFuzzer::Fuzz(); | 2679 ApiTestFuzzer::Fuzz(); |
2564 if (v8_str("pre")->Equals(key)) { | 2680 if (v8_str("pre")->Equals(key)) { |
2565 info.GetReturnValue().Set(v8_str("PrePropertyHandler: pre")); | 2681 info.GetReturnValue().Set(v8_str("PrePropertyHandler: pre")); |
2566 } | 2682 } |
2567 } | 2683 } |
2568 | 2684 |
2569 | 2685 |
2570 static void PrePropertyHandlerQuery( | 2686 static void PrePropertyHandlerQuery( |
2571 Local<String> key, | 2687 Local<Name> key, const v8::PropertyCallbackInfo<v8::Integer>& info) { |
2572 const v8::PropertyCallbackInfo<v8::Integer>& info) { | |
2573 if (v8_str("pre")->Equals(key)) { | 2688 if (v8_str("pre")->Equals(key)) { |
2574 info.GetReturnValue().Set(static_cast<int32_t>(v8::None)); | 2689 info.GetReturnValue().Set(static_cast<int32_t>(v8::None)); |
2575 } | 2690 } |
2576 } | 2691 } |
2577 | 2692 |
2578 | 2693 |
2579 THREADED_TEST(PrePropertyHandler) { | 2694 THREADED_TEST(PrePropertyHandler) { |
2580 v8::Isolate* isolate = CcTest::isolate(); | 2695 v8::Isolate* isolate = CcTest::isolate(); |
2581 v8::HandleScope scope(isolate); | 2696 v8::HandleScope scope(isolate); |
2582 v8::Handle<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(isolate); | 2697 v8::Handle<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(isolate); |
2583 desc->InstanceTemplate()->SetNamedPropertyHandler(PrePropertyHandlerGet, | 2698 desc->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration( |
2584 0, | 2699 PrePropertyHandlerGet, 0, PrePropertyHandlerQuery)); |
2585 PrePropertyHandlerQuery); | |
2586 LocalContext env(NULL, desc->InstanceTemplate()); | 2700 LocalContext env(NULL, desc->InstanceTemplate()); |
2587 CompileRun("var pre = 'Object: pre'; var on = 'Object: on';"); | 2701 CompileRun("var pre = 'Object: pre'; var on = 'Object: on';"); |
2588 v8::Handle<Value> result_pre = CompileRun("pre"); | 2702 v8::Handle<Value> result_pre = CompileRun("pre"); |
2589 CHECK_EQ(v8_str("PrePropertyHandler: pre"), result_pre); | 2703 CHECK_EQ(v8_str("PrePropertyHandler: pre"), result_pre); |
2590 v8::Handle<Value> result_on = CompileRun("on"); | 2704 v8::Handle<Value> result_on = CompileRun("on"); |
2591 CHECK_EQ(v8_str("Object: on"), result_on); | 2705 CHECK_EQ(v8_str("Object: on"), result_on); |
2592 v8::Handle<Value> result_post = CompileRun("post"); | 2706 v8::Handle<Value> result_post = CompileRun("post"); |
2593 CHECK(result_post.IsEmpty()); | 2707 CHECK(result_post.IsEmpty()); |
2594 } | 2708 } |
2595 | 2709 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2648 call_recursively_script = v8_compile("callScriptRecursively()"); | 2762 call_recursively_script = v8_compile("callScriptRecursively()"); |
2649 call_recursively_script->Run(); | 2763 call_recursively_script->Run(); |
2650 call_recursively_script = v8::Handle<Script>(); | 2764 call_recursively_script = v8::Handle<Script>(); |
2651 | 2765 |
2652 env->Global()->Set(v8_str("depth"), v8::Integer::New(isolate, 0)); | 2766 env->Global()->Set(v8_str("depth"), v8::Integer::New(isolate, 0)); |
2653 CompileRun("callFunctionRecursively()"); | 2767 CompileRun("callFunctionRecursively()"); |
2654 } | 2768 } |
2655 | 2769 |
2656 | 2770 |
2657 static void ThrowingPropertyHandlerGet( | 2771 static void ThrowingPropertyHandlerGet( |
2658 Local<String> key, | 2772 Local<Name> key, const v8::PropertyCallbackInfo<v8::Value>& info) { |
2659 const v8::PropertyCallbackInfo<v8::Value>& info) { | 2773 // Since this interceptor is used on "with" objects, the runtime will look up |
| 2774 // @@unscopables. Punt. |
| 2775 if (key->IsSymbol()) return; |
2660 ApiTestFuzzer::Fuzz(); | 2776 ApiTestFuzzer::Fuzz(); |
2661 info.GetReturnValue().Set(info.GetIsolate()->ThrowException(key)); | 2777 info.GetReturnValue().Set(info.GetIsolate()->ThrowException(key)); |
2662 } | 2778 } |
2663 | 2779 |
2664 | 2780 |
2665 static void ThrowingPropertyHandlerSet( | 2781 static void ThrowingPropertyHandlerSet( |
2666 Local<String> key, | 2782 Local<Name> key, Local<Value>, |
2667 Local<Value>, | |
2668 const v8::PropertyCallbackInfo<v8::Value>& info) { | 2783 const v8::PropertyCallbackInfo<v8::Value>& info) { |
2669 info.GetIsolate()->ThrowException(key); | 2784 info.GetIsolate()->ThrowException(key); |
2670 info.GetReturnValue().SetUndefined(); // not the same as empty handle | 2785 info.GetReturnValue().SetUndefined(); // not the same as empty handle |
2671 } | 2786 } |
2672 | 2787 |
2673 | 2788 |
2674 THREADED_TEST(CallbackExceptionRegression) { | 2789 THREADED_TEST(CallbackExceptionRegression) { |
2675 v8::Isolate* isolate = CcTest::isolate(); | 2790 v8::Isolate* isolate = CcTest::isolate(); |
2676 v8::HandleScope scope(isolate); | 2791 v8::HandleScope scope(isolate); |
2677 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); | 2792 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
2678 obj->SetNamedPropertyHandler(ThrowingPropertyHandlerGet, | 2793 obj->SetHandler(v8::NamedPropertyHandlerConfiguration( |
2679 ThrowingPropertyHandlerSet); | 2794 ThrowingPropertyHandlerGet, ThrowingPropertyHandlerSet)); |
2680 LocalContext env; | 2795 LocalContext env; |
2681 env->Global()->Set(v8_str("obj"), obj->NewInstance()); | 2796 env->Global()->Set(v8_str("obj"), obj->NewInstance()); |
2682 v8::Handle<Value> otto = CompileRun( | 2797 v8::Handle<Value> otto = CompileRun( |
2683 "try { with (obj) { otto; } } catch (e) { e; }"); | 2798 "try { with (obj) { otto; } } catch (e) { e; }"); |
2684 CHECK_EQ(v8_str("otto"), otto); | 2799 CHECK_EQ(v8_str("otto"), otto); |
2685 v8::Handle<Value> netto = CompileRun( | 2800 v8::Handle<Value> netto = CompileRun( |
2686 "try { with (obj) { netto = 4; } } catch (e) { e; }"); | 2801 "try { with (obj) { netto = 4; } } catch (e) { e; }"); |
2687 CHECK_EQ(v8_str("netto"), netto); | 2802 CHECK_EQ(v8_str("netto"), netto); |
2688 } | 2803 } |
2689 | 2804 |
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3527 // If it did we would have full access to the hidden properties in | 3642 // If it did we would have full access to the hidden properties in |
3528 // the accessor. | 3643 // the accessor. |
3529 CHECK(obj->SetHiddenValue(key, v8::Integer::New(env->GetIsolate(), 42))); | 3644 CHECK(obj->SetHiddenValue(key, v8::Integer::New(env->GetIsolate(), 42))); |
3530 ExpectFalse("set_called"); | 3645 ExpectFalse("set_called"); |
3531 CHECK_EQ(42, obj->GetHiddenValue(key)->Int32Value()); | 3646 CHECK_EQ(42, obj->GetHiddenValue(key)->Int32Value()); |
3532 } | 3647 } |
3533 | 3648 |
3534 | 3649 |
3535 static bool interceptor_for_hidden_properties_called; | 3650 static bool interceptor_for_hidden_properties_called; |
3536 static void InterceptorForHiddenProperties( | 3651 static void InterceptorForHiddenProperties( |
3537 Local<String> name, const v8::PropertyCallbackInfo<v8::Value>& info) { | 3652 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
3538 interceptor_for_hidden_properties_called = true; | 3653 interceptor_for_hidden_properties_called = true; |
3539 } | 3654 } |
3540 | 3655 |
3541 | 3656 |
3542 THREADED_TEST(HiddenPropertiesWithInterceptors) { | 3657 THREADED_TEST(HiddenPropertiesWithInterceptors) { |
3543 LocalContext context; | 3658 LocalContext context; |
3544 v8::Isolate* isolate = context->GetIsolate(); | 3659 v8::Isolate* isolate = context->GetIsolate(); |
3545 v8::HandleScope scope(isolate); | 3660 v8::HandleScope scope(isolate); |
3546 | 3661 |
3547 interceptor_for_hidden_properties_called = false; | 3662 interceptor_for_hidden_properties_called = false; |
3548 | 3663 |
3549 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); | 3664 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); |
3550 | 3665 |
3551 // Associate an interceptor with an object and start setting hidden values. | 3666 // Associate an interceptor with an object and start setting hidden values. |
3552 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate); | 3667 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate); |
3553 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); | 3668 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); |
3554 instance_templ->SetNamedPropertyHandler(InterceptorForHiddenProperties); | 3669 instance_templ->SetHandler( |
| 3670 v8::NamedPropertyHandlerConfiguration(InterceptorForHiddenProperties)); |
3555 Local<v8::Function> function = fun_templ->GetFunction(); | 3671 Local<v8::Function> function = fun_templ->GetFunction(); |
3556 Local<v8::Object> obj = function->NewInstance(); | 3672 Local<v8::Object> obj = function->NewInstance(); |
3557 CHECK(obj->SetHiddenValue(key, v8::Integer::New(isolate, 2302))); | 3673 CHECK(obj->SetHiddenValue(key, v8::Integer::New(isolate, 2302))); |
3558 CHECK_EQ(2302, obj->GetHiddenValue(key)->Int32Value()); | 3674 CHECK_EQ(2302, obj->GetHiddenValue(key)->Int32Value()); |
3559 CHECK(!interceptor_for_hidden_properties_called); | 3675 CHECK(!interceptor_for_hidden_properties_called); |
3560 } | 3676 } |
3561 | 3677 |
3562 | 3678 |
3563 THREADED_TEST(External) { | 3679 THREADED_TEST(External) { |
3564 v8::HandleScope scope(CcTest::isolate()); | 3680 v8::HandleScope scope(CcTest::isolate()); |
(...skipping 2534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6099 v8_str("donut")); | 6215 v8_str("donut")); |
6100 LocalContext context; | 6216 LocalContext context; |
6101 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 6217 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
6102 Local<Script> script = v8_compile("obj.x = 4; obj.x"); | 6218 Local<Script> script = v8_compile("obj.x = 4; obj.x"); |
6103 for (int i = 0; i < 10; i++) { | 6219 for (int i = 0; i < 10; i++) { |
6104 script->Run(); | 6220 script->Run(); |
6105 } | 6221 } |
6106 } | 6222 } |
6107 | 6223 |
6108 | 6224 |
6109 static void XPropertyGetter(Local<String> property, | 6225 static void XPropertyGetter(Local<Name> property, |
6110 const v8::PropertyCallbackInfo<v8::Value>& info) { | 6226 const v8::PropertyCallbackInfo<v8::Value>& info) { |
6111 ApiTestFuzzer::Fuzz(); | 6227 ApiTestFuzzer::Fuzz(); |
6112 CHECK(info.Data()->IsUndefined()); | 6228 CHECK(info.Data()->IsUndefined()); |
6113 info.GetReturnValue().Set(property); | 6229 info.GetReturnValue().Set(property); |
6114 } | 6230 } |
6115 | 6231 |
6116 | 6232 |
6117 THREADED_TEST(NamedInterceptorPropertyRead) { | 6233 THREADED_TEST(NamedInterceptorPropertyRead) { |
6118 v8::Isolate* isolate = CcTest::isolate(); | 6234 v8::Isolate* isolate = CcTest::isolate(); |
6119 v8::HandleScope scope(isolate); | 6235 v8::HandleScope scope(isolate); |
6120 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 6236 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
6121 templ->SetNamedPropertyHandler(XPropertyGetter); | 6237 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(XPropertyGetter)); |
6122 LocalContext context; | 6238 LocalContext context; |
6123 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 6239 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
6124 Local<Script> script = v8_compile("obj.x"); | 6240 Local<Script> script = v8_compile("obj.x"); |
6125 for (int i = 0; i < 10; i++) { | 6241 for (int i = 0; i < 10; i++) { |
6126 Local<Value> result = script->Run(); | 6242 Local<Value> result = script->Run(); |
6127 CHECK_EQ(result, v8_str("x")); | 6243 CHECK_EQ(result, v8_str("x")); |
6128 } | 6244 } |
6129 } | 6245 } |
6130 | 6246 |
6131 | 6247 |
6132 THREADED_TEST(NamedInterceptorDictionaryIC) { | 6248 THREADED_TEST(NamedInterceptorDictionaryIC) { |
6133 v8::Isolate* isolate = CcTest::isolate(); | 6249 v8::Isolate* isolate = CcTest::isolate(); |
6134 v8::HandleScope scope(isolate); | 6250 v8::HandleScope scope(isolate); |
6135 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 6251 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
6136 templ->SetNamedPropertyHandler(XPropertyGetter); | 6252 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(XPropertyGetter)); |
6137 LocalContext context; | 6253 LocalContext context; |
6138 // Create an object with a named interceptor. | 6254 // Create an object with a named interceptor. |
6139 context->Global()->Set(v8_str("interceptor_obj"), templ->NewInstance()); | 6255 context->Global()->Set(v8_str("interceptor_obj"), templ->NewInstance()); |
6140 Local<Script> script = v8_compile("interceptor_obj.x"); | 6256 Local<Script> script = v8_compile("interceptor_obj.x"); |
6141 for (int i = 0; i < 10; i++) { | 6257 for (int i = 0; i < 10; i++) { |
6142 Local<Value> result = script->Run(); | 6258 Local<Value> result = script->Run(); |
6143 CHECK_EQ(result, v8_str("x")); | 6259 CHECK_EQ(result, v8_str("x")); |
6144 } | 6260 } |
6145 // Create a slow case object and a function accessing a property in | 6261 // Create a slow case object and a function accessing a property in |
6146 // that slow case object (with dictionary probing in generated | 6262 // that slow case object (with dictionary probing in generated |
(...skipping 13 matching lines...) Expand all Loading... |
6160 } | 6276 } |
6161 | 6277 |
6162 | 6278 |
6163 THREADED_TEST(NamedInterceptorDictionaryICMultipleContext) { | 6279 THREADED_TEST(NamedInterceptorDictionaryICMultipleContext) { |
6164 v8::Isolate* isolate = CcTest::isolate(); | 6280 v8::Isolate* isolate = CcTest::isolate(); |
6165 v8::HandleScope scope(isolate); | 6281 v8::HandleScope scope(isolate); |
6166 v8::Local<Context> context1 = Context::New(isolate); | 6282 v8::Local<Context> context1 = Context::New(isolate); |
6167 | 6283 |
6168 context1->Enter(); | 6284 context1->Enter(); |
6169 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 6285 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
6170 templ->SetNamedPropertyHandler(XPropertyGetter); | 6286 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(XPropertyGetter)); |
6171 // Create an object with a named interceptor. | 6287 // Create an object with a named interceptor. |
6172 v8::Local<v8::Object> object = templ->NewInstance(); | 6288 v8::Local<v8::Object> object = templ->NewInstance(); |
6173 context1->Global()->Set(v8_str("interceptor_obj"), object); | 6289 context1->Global()->Set(v8_str("interceptor_obj"), object); |
6174 | 6290 |
6175 // Force the object into the slow case. | 6291 // Force the object into the slow case. |
6176 CompileRun("interceptor_obj.y = 0;" | 6292 CompileRun("interceptor_obj.y = 0;" |
6177 "delete interceptor_obj.y;"); | 6293 "delete interceptor_obj.y;"); |
6178 context1->Exit(); | 6294 context1->Exit(); |
6179 | 6295 |
6180 { | 6296 { |
(...skipping 14 matching lines...) Expand all Loading... |
6195 | 6311 |
6196 // Return to the original context and force some object to the slow case | 6312 // Return to the original context and force some object to the slow case |
6197 // to cause the NormalizedMapCache to verify. | 6313 // to cause the NormalizedMapCache to verify. |
6198 context1->Enter(); | 6314 context1->Enter(); |
6199 CompileRun("var obj = { x : 0 }; delete obj.x;"); | 6315 CompileRun("var obj = { x : 0 }; delete obj.x;"); |
6200 context1->Exit(); | 6316 context1->Exit(); |
6201 } | 6317 } |
6202 | 6318 |
6203 | 6319 |
6204 static void SetXOnPrototypeGetter( | 6320 static void SetXOnPrototypeGetter( |
6205 Local<String> property, | 6321 Local<Name> property, const v8::PropertyCallbackInfo<v8::Value>& info) { |
6206 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
6207 // Set x on the prototype object and do not handle the get request. | 6322 // Set x on the prototype object and do not handle the get request. |
6208 v8::Handle<v8::Value> proto = info.Holder()->GetPrototype(); | 6323 v8::Handle<v8::Value> proto = info.Holder()->GetPrototype(); |
6209 proto.As<v8::Object>()->Set(v8_str("x"), | 6324 proto.As<v8::Object>()->Set(v8_str("x"), |
6210 v8::Integer::New(info.GetIsolate(), 23)); | 6325 v8::Integer::New(info.GetIsolate(), 23)); |
6211 } | 6326 } |
6212 | 6327 |
6213 | 6328 |
6214 // This is a regression test for http://crbug.com/20104. Map | 6329 // This is a regression test for http://crbug.com/20104. Map |
6215 // transitions should not interfere with post interceptor lookup. | 6330 // transitions should not interfere with post interceptor lookup. |
6216 THREADED_TEST(NamedInterceptorMapTransitionRead) { | 6331 THREADED_TEST(NamedInterceptorMapTransitionRead) { |
6217 v8::Isolate* isolate = CcTest::isolate(); | 6332 v8::Isolate* isolate = CcTest::isolate(); |
6218 v8::HandleScope scope(isolate); | 6333 v8::HandleScope scope(isolate); |
6219 Local<v8::FunctionTemplate> function_template = | 6334 Local<v8::FunctionTemplate> function_template = |
6220 v8::FunctionTemplate::New(isolate); | 6335 v8::FunctionTemplate::New(isolate); |
6221 Local<v8::ObjectTemplate> instance_template | 6336 Local<v8::ObjectTemplate> instance_template |
6222 = function_template->InstanceTemplate(); | 6337 = function_template->InstanceTemplate(); |
6223 instance_template->SetNamedPropertyHandler(SetXOnPrototypeGetter); | 6338 instance_template->SetHandler( |
| 6339 v8::NamedPropertyHandlerConfiguration(SetXOnPrototypeGetter)); |
6224 LocalContext context; | 6340 LocalContext context; |
6225 context->Global()->Set(v8_str("F"), function_template->GetFunction()); | 6341 context->Global()->Set(v8_str("F"), function_template->GetFunction()); |
6226 // Create an instance of F and introduce a map transition for x. | 6342 // Create an instance of F and introduce a map transition for x. |
6227 CompileRun("var o = new F(); o.x = 23;"); | 6343 CompileRun("var o = new F(); o.x = 23;"); |
6228 // Create an instance of F and invoke the getter. The result should be 23. | 6344 // Create an instance of F and invoke the getter. The result should be 23. |
6229 Local<Value> result = CompileRun("o = new F(); o.x"); | 6345 Local<Value> result = CompileRun("o = new F(); o.x"); |
6230 CHECK_EQ(result->Int32Value(), 23); | 6346 CHECK_EQ(result->Int32Value(), 23); |
6231 } | 6347 } |
6232 | 6348 |
6233 | 6349 |
(...skipping 1506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7740 v8::HandleScope scope(isolate); | 7856 v8::HandleScope scope(isolate); |
7741 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(isolate); | 7857 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(isolate); |
7742 global->Set(v8_str("f"), | 7858 global->Set(v8_str("f"), |
7743 v8::FunctionTemplate::New(isolate, ArgumentsTestCallback)); | 7859 v8::FunctionTemplate::New(isolate, ArgumentsTestCallback)); |
7744 LocalContext context(NULL, global); | 7860 LocalContext context(NULL, global); |
7745 args_fun = context->Global()->Get(v8_str("f")).As<Function>(); | 7861 args_fun = context->Global()->Get(v8_str("f")).As<Function>(); |
7746 v8_compile("f(1, 2, 3)")->Run(); | 7862 v8_compile("f(1, 2, 3)")->Run(); |
7747 } | 7863 } |
7748 | 7864 |
7749 | 7865 |
7750 static void NoBlockGetterX(Local<String> name, | 7866 static void NoBlockGetterX(Local<Name> name, |
7751 const v8::PropertyCallbackInfo<v8::Value>&) { | 7867 const v8::PropertyCallbackInfo<v8::Value>&) {} |
7752 } | |
7753 | 7868 |
7754 | 7869 |
7755 static void NoBlockGetterI(uint32_t index, | 7870 static void NoBlockGetterI(uint32_t index, |
7756 const v8::PropertyCallbackInfo<v8::Value>&) { | 7871 const v8::PropertyCallbackInfo<v8::Value>&) { |
7757 } | 7872 } |
7758 | 7873 |
7759 | 7874 |
7760 static void PDeleter(Local<String> name, | 7875 static void PDeleter(Local<Name> name, |
7761 const v8::PropertyCallbackInfo<v8::Boolean>& info) { | 7876 const v8::PropertyCallbackInfo<v8::Boolean>& info) { |
7762 if (!name->Equals(v8_str("foo"))) { | 7877 if (!name->Equals(v8_str("foo"))) { |
7763 return; // not intercepted | 7878 return; // not intercepted |
7764 } | 7879 } |
7765 | 7880 |
7766 info.GetReturnValue().Set(false); // intercepted, don't delete the property | 7881 info.GetReturnValue().Set(false); // intercepted, don't delete the property |
7767 } | 7882 } |
7768 | 7883 |
7769 | 7884 |
7770 static void IDeleter(uint32_t index, | 7885 static void IDeleter(uint32_t index, |
7771 const v8::PropertyCallbackInfo<v8::Boolean>& info) { | 7886 const v8::PropertyCallbackInfo<v8::Boolean>& info) { |
7772 if (index != 2) { | 7887 if (index != 2) { |
7773 return; // not intercepted | 7888 return; // not intercepted |
7774 } | 7889 } |
7775 | 7890 |
7776 info.GetReturnValue().Set(false); // intercepted, don't delete the property | 7891 info.GetReturnValue().Set(false); // intercepted, don't delete the property |
7777 } | 7892 } |
7778 | 7893 |
7779 | 7894 |
7780 THREADED_TEST(Deleter) { | 7895 THREADED_TEST(Deleter) { |
7781 v8::Isolate* isolate = CcTest::isolate(); | 7896 v8::Isolate* isolate = CcTest::isolate(); |
7782 v8::HandleScope scope(isolate); | 7897 v8::HandleScope scope(isolate); |
7783 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); | 7898 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
7784 obj->SetNamedPropertyHandler(NoBlockGetterX, NULL, NULL, PDeleter, NULL); | 7899 obj->SetHandler(v8::NamedPropertyHandlerConfiguration(NoBlockGetterX, NULL, |
| 7900 NULL, PDeleter, NULL)); |
7785 obj->SetIndexedPropertyHandler(NoBlockGetterI, NULL, NULL, IDeleter, NULL); | 7901 obj->SetIndexedPropertyHandler(NoBlockGetterI, NULL, NULL, IDeleter, NULL); |
7786 LocalContext context; | 7902 LocalContext context; |
7787 context->Global()->Set(v8_str("k"), obj->NewInstance()); | 7903 context->Global()->Set(v8_str("k"), obj->NewInstance()); |
7788 CompileRun( | 7904 CompileRun( |
7789 "k.foo = 'foo';" | 7905 "k.foo = 'foo';" |
7790 "k.bar = 'bar';" | 7906 "k.bar = 'bar';" |
7791 "k[2] = 2;" | 7907 "k[2] = 2;" |
7792 "k[4] = 4;"); | 7908 "k[4] = 4;"); |
7793 CHECK(v8_compile("delete k.foo")->Run()->IsFalse()); | 7909 CHECK(v8_compile("delete k.foo")->Run()->IsFalse()); |
7794 CHECK(v8_compile("delete k.bar")->Run()->IsTrue()); | 7910 CHECK(v8_compile("delete k.bar")->Run()->IsTrue()); |
7795 | 7911 |
7796 CHECK_EQ(v8_compile("k.foo")->Run(), v8_str("foo")); | 7912 CHECK_EQ(v8_compile("k.foo")->Run(), v8_str("foo")); |
7797 CHECK(v8_compile("k.bar")->Run()->IsUndefined()); | 7913 CHECK(v8_compile("k.bar")->Run()->IsUndefined()); |
7798 | 7914 |
7799 CHECK(v8_compile("delete k[2]")->Run()->IsFalse()); | 7915 CHECK(v8_compile("delete k[2]")->Run()->IsFalse()); |
7800 CHECK(v8_compile("delete k[4]")->Run()->IsTrue()); | 7916 CHECK(v8_compile("delete k[4]")->Run()->IsTrue()); |
7801 | 7917 |
7802 CHECK_EQ(v8_compile("k[2]")->Run(), v8_num(2)); | 7918 CHECK_EQ(v8_compile("k[2]")->Run(), v8_num(2)); |
7803 CHECK(v8_compile("k[4]")->Run()->IsUndefined()); | 7919 CHECK(v8_compile("k[4]")->Run()->IsUndefined()); |
7804 } | 7920 } |
7805 | 7921 |
7806 | 7922 |
7807 static void GetK(Local<String> name, | 7923 static void GetK(Local<Name> name, |
7808 const v8::PropertyCallbackInfo<v8::Value>& info) { | 7924 const v8::PropertyCallbackInfo<v8::Value>& info) { |
7809 ApiTestFuzzer::Fuzz(); | 7925 ApiTestFuzzer::Fuzz(); |
7810 if (name->Equals(v8_str("foo")) || | 7926 if (name->Equals(v8_str("foo")) || |
7811 name->Equals(v8_str("bar")) || | 7927 name->Equals(v8_str("bar")) || |
7812 name->Equals(v8_str("baz"))) { | 7928 name->Equals(v8_str("baz"))) { |
7813 info.GetReturnValue().SetUndefined(); | 7929 info.GetReturnValue().SetUndefined(); |
7814 } | 7930 } |
7815 } | 7931 } |
7816 | 7932 |
7817 | 7933 |
(...skipping 20 matching lines...) Expand all Loading... |
7838 result->Set(v8::Integer::New(info.GetIsolate(), 0), v8_str("0")); | 7954 result->Set(v8::Integer::New(info.GetIsolate(), 0), v8_str("0")); |
7839 result->Set(v8::Integer::New(info.GetIsolate(), 1), v8_str("1")); | 7955 result->Set(v8::Integer::New(info.GetIsolate(), 1), v8_str("1")); |
7840 info.GetReturnValue().Set(result); | 7956 info.GetReturnValue().Set(result); |
7841 } | 7957 } |
7842 | 7958 |
7843 | 7959 |
7844 THREADED_TEST(Enumerators) { | 7960 THREADED_TEST(Enumerators) { |
7845 v8::Isolate* isolate = CcTest::isolate(); | 7961 v8::Isolate* isolate = CcTest::isolate(); |
7846 v8::HandleScope scope(isolate); | 7962 v8::HandleScope scope(isolate); |
7847 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); | 7963 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
7848 obj->SetNamedPropertyHandler(GetK, NULL, NULL, NULL, NamedEnum); | 7964 obj->SetHandler( |
| 7965 v8::NamedPropertyHandlerConfiguration(GetK, NULL, NULL, NULL, NamedEnum)); |
7849 obj->SetIndexedPropertyHandler(IndexedGetK, NULL, NULL, NULL, IndexedEnum); | 7966 obj->SetIndexedPropertyHandler(IndexedGetK, NULL, NULL, NULL, IndexedEnum); |
7850 LocalContext context; | 7967 LocalContext context; |
7851 context->Global()->Set(v8_str("k"), obj->NewInstance()); | 7968 context->Global()->Set(v8_str("k"), obj->NewInstance()); |
7852 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( | 7969 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( |
7853 "k[10] = 0;" | 7970 "k[10] = 0;" |
7854 "k.a = 0;" | 7971 "k.a = 0;" |
7855 "k[5] = 0;" | 7972 "k[5] = 0;" |
7856 "k.b = 0;" | 7973 "k.b = 0;" |
7857 "k[4294967295] = 0;" | 7974 "k[4294967295] = 0;" |
7858 "k.c = 0;" | 7975 "k.c = 0;" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7931 "var o2 = { __proto__: o1 };" | 8048 "var o2 = { __proto__: o1 };" |
7932 "var o3 = { __proto__: o2 };" | 8049 "var o3 = { __proto__: o2 };" |
7933 "var o4 = { __proto__: o3 };" | 8050 "var o4 = { __proto__: o3 };" |
7934 "for (var i = 0; i < 10; i++) o4.p4;" | 8051 "for (var i = 0; i < 10; i++) o4.p4;" |
7935 "for (var i = 0; i < 10; i++) o3.p3;" | 8052 "for (var i = 0; i < 10; i++) o3.p3;" |
7936 "for (var i = 0; i < 10; i++) o2.p2;" | 8053 "for (var i = 0; i < 10; i++) o2.p2;" |
7937 "for (var i = 0; i < 10; i++) o1.p1;"); | 8054 "for (var i = 0; i < 10; i++) o1.p1;"); |
7938 } | 8055 } |
7939 | 8056 |
7940 | 8057 |
7941 static void PGetter2(Local<String> name, | 8058 static void PGetter2(Local<Name> name, |
7942 const v8::PropertyCallbackInfo<v8::Value>& info) { | 8059 const v8::PropertyCallbackInfo<v8::Value>& info) { |
7943 ApiTestFuzzer::Fuzz(); | 8060 ApiTestFuzzer::Fuzz(); |
7944 p_getter_count2++; | 8061 p_getter_count2++; |
7945 v8::Handle<v8::Object> global = | 8062 v8::Handle<v8::Object> global = |
7946 info.GetIsolate()->GetCurrentContext()->Global(); | 8063 info.GetIsolate()->GetCurrentContext()->Global(); |
7947 CHECK_EQ(info.Holder(), global->Get(v8_str("o1"))); | 8064 CHECK_EQ(info.Holder(), global->Get(v8_str("o1"))); |
7948 if (name->Equals(v8_str("p1"))) { | 8065 if (name->Equals(v8_str("p1"))) { |
7949 CHECK_EQ(info.This(), global->Get(v8_str("o1"))); | 8066 CHECK_EQ(info.This(), global->Get(v8_str("o1"))); |
7950 } else if (name->Equals(v8_str("p2"))) { | 8067 } else if (name->Equals(v8_str("p2"))) { |
7951 CHECK_EQ(info.This(), global->Get(v8_str("o2"))); | 8068 CHECK_EQ(info.This(), global->Get(v8_str("o2"))); |
(...skipping 16 matching lines...) Expand all Loading... |
7968 p_getter_count = 0; | 8085 p_getter_count = 0; |
7969 RunHolderTest(obj); | 8086 RunHolderTest(obj); |
7970 CHECK_EQ(40, p_getter_count); | 8087 CHECK_EQ(40, p_getter_count); |
7971 } | 8088 } |
7972 | 8089 |
7973 | 8090 |
7974 THREADED_TEST(PreInterceptorHolders) { | 8091 THREADED_TEST(PreInterceptorHolders) { |
7975 v8::Isolate* isolate = CcTest::isolate(); | 8092 v8::Isolate* isolate = CcTest::isolate(); |
7976 v8::HandleScope scope(isolate); | 8093 v8::HandleScope scope(isolate); |
7977 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); | 8094 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
7978 obj->SetNamedPropertyHandler(PGetter2); | 8095 obj->SetHandler(v8::NamedPropertyHandlerConfiguration(PGetter2)); |
7979 p_getter_count2 = 0; | 8096 p_getter_count2 = 0; |
7980 RunHolderTest(obj); | 8097 RunHolderTest(obj); |
7981 CHECK_EQ(40, p_getter_count2); | 8098 CHECK_EQ(40, p_getter_count2); |
7982 } | 8099 } |
7983 | 8100 |
7984 | 8101 |
7985 THREADED_TEST(ObjectInstantiation) { | 8102 THREADED_TEST(ObjectInstantiation) { |
7986 v8::Isolate* isolate = CcTest::isolate(); | 8103 v8::Isolate* isolate = CcTest::isolate(); |
7987 v8::HandleScope scope(isolate); | 8104 v8::HandleScope scope(isolate); |
7988 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 8105 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
(...skipping 1986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9975 const v8::PropertyCallbackInfo<v8::Array>& info) { | 10092 const v8::PropertyCallbackInfo<v8::Array>& info) { |
9976 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2); | 10093 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2); |
9977 result->Set(0, v8::Integer::New(info.GetIsolate(), 7)); | 10094 result->Set(0, v8::Integer::New(info.GetIsolate(), 7)); |
9978 result->Set(1, v8::Object::New(info.GetIsolate())); | 10095 result->Set(1, v8::Object::New(info.GetIsolate())); |
9979 info.GetReturnValue().Set(result); | 10096 info.GetReturnValue().Set(result); |
9980 } | 10097 } |
9981 | 10098 |
9982 | 10099 |
9983 static void NamedPropertyEnumerator( | 10100 static void NamedPropertyEnumerator( |
9984 const v8::PropertyCallbackInfo<v8::Array>& info) { | 10101 const v8::PropertyCallbackInfo<v8::Array>& info) { |
9985 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2); | 10102 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 3); |
9986 result->Set(0, v8_str("x")); | 10103 result->Set(0, v8_str("x")); |
9987 result->Set(1, v8::Object::New(info.GetIsolate())); | 10104 result->Set(1, v8::Object::New(info.GetIsolate())); |
| 10105 result->Set(2, v8::Symbol::GetIterator(info.GetIsolate())); |
9988 info.GetReturnValue().Set(result); | 10106 info.GetReturnValue().Set(result); |
9989 } | 10107 } |
9990 | 10108 |
9991 | 10109 |
9992 THREADED_TEST(GetOwnPropertyNamesWithInterceptor) { | 10110 THREADED_TEST(GetOwnPropertyNamesWithInterceptor) { |
9993 v8::Isolate* isolate = CcTest::isolate(); | 10111 v8::Isolate* isolate = CcTest::isolate(); |
9994 v8::HandleScope handle_scope(isolate); | 10112 v8::HandleScope handle_scope(isolate); |
9995 v8::Handle<v8::ObjectTemplate> obj_template = | 10113 v8::Handle<v8::ObjectTemplate> obj_template = |
9996 v8::ObjectTemplate::New(isolate); | 10114 v8::ObjectTemplate::New(isolate); |
9997 | 10115 |
9998 obj_template->Set(v8_str("7"), v8::Integer::New(CcTest::isolate(), 7)); | 10116 obj_template->Set(v8_str("7"), v8::Integer::New(CcTest::isolate(), 7)); |
9999 obj_template->Set(v8_str("x"), v8::Integer::New(CcTest::isolate(), 42)); | 10117 obj_template->Set(v8_str("x"), v8::Integer::New(CcTest::isolate(), 42)); |
10000 obj_template->SetIndexedPropertyHandler(NULL, NULL, NULL, NULL, | 10118 obj_template->SetIndexedPropertyHandler(NULL, NULL, NULL, NULL, |
10001 IndexedPropertyEnumerator); | 10119 IndexedPropertyEnumerator); |
10002 obj_template->SetNamedPropertyHandler(NULL, NULL, NULL, NULL, | 10120 // TODO(wingo): Types needed to disambiguate between deprecated and new |
10003 NamedPropertyEnumerator); | 10121 // SetHandler implementations. Go back to just passing NULL |
| 10122 // values once deprecated API is removed. |
| 10123 v8::GenericNamedPropertyGetterCallback getter = NULL; |
| 10124 obj_template->SetHandler(v8::NamedPropertyHandlerConfiguration( |
| 10125 getter, NULL, NULL, NULL, NamedPropertyEnumerator)); |
10004 | 10126 |
10005 LocalContext context; | 10127 LocalContext context; |
10006 v8::Handle<v8::Object> global = context->Global(); | 10128 v8::Handle<v8::Object> global = context->Global(); |
10007 global->Set(v8_str("object"), obj_template->NewInstance()); | 10129 global->Set(v8_str("object"), obj_template->NewInstance()); |
10008 | 10130 |
10009 v8::Handle<v8::Value> result = | 10131 v8::Handle<v8::Value> result = |
10010 CompileRun("Object.getOwnPropertyNames(object)"); | 10132 CompileRun("Object.getOwnPropertyNames(object)"); |
10011 CHECK(result->IsArray()); | 10133 CHECK(result->IsArray()); |
10012 v8::Handle<v8::Array> result_array = v8::Handle<v8::Array>::Cast(result); | 10134 v8::Handle<v8::Array> result_array = v8::Handle<v8::Array>::Cast(result); |
10013 CHECK_EQ(3, result_array->Length()); | 10135 CHECK_EQ(3, result_array->Length()); |
10014 CHECK(result_array->Get(0)->IsString()); | 10136 CHECK(result_array->Get(0)->IsString()); |
10015 CHECK(result_array->Get(1)->IsString()); | 10137 CHECK(result_array->Get(1)->IsString()); |
10016 CHECK(result_array->Get(2)->IsString()); | 10138 CHECK(result_array->Get(2)->IsString()); |
10017 CHECK_EQ(v8_str("7"), result_array->Get(0)); | 10139 CHECK_EQ(v8_str("7"), result_array->Get(0)); |
10018 CHECK_EQ(v8_str("[object Object]"), result_array->Get(1)); | 10140 CHECK_EQ(v8_str("[object Object]"), result_array->Get(1)); |
10019 CHECK_EQ(v8_str("x"), result_array->Get(2)); | 10141 CHECK_EQ(v8_str("x"), result_array->Get(2)); |
| 10142 |
| 10143 result = CompileRun("var ret; for (var k in object) array.push(k); ret"); |
| 10144 CHECK(result->IsArray()); |
| 10145 result_array = v8::Handle<v8::Array>::Cast(result); |
| 10146 CHECK_EQ(3, result_array->Length()); |
| 10147 CHECK(result_array->Get(0)->IsString()); |
| 10148 CHECK(result_array->Get(1)->IsString()); |
| 10149 CHECK(result_array->Get(2)->IsString()); |
| 10150 CHECK_EQ(v8_str("7"), result_array->Get(0)); |
| 10151 CHECK_EQ(v8_str("[object Object]"), result_array->Get(1)); |
| 10152 CHECK_EQ(v8_str("x"), result_array->Get(2)); |
| 10153 |
| 10154 result = CompileRun("Object.getOwnPropertySymbols(object)"); |
| 10155 CHECK(result->IsArray()); |
| 10156 result_array = v8::Handle<v8::Array>::Cast(result); |
| 10157 CHECK_EQ(1, result_array->Length()); |
| 10158 CHECK_EQ(result_array->Get(0), v8::Symbol::GetIterator(isolate)); |
10020 } | 10159 } |
10021 | 10160 |
10022 | 10161 |
10023 static void ConstTenGetter(Local<String> name, | 10162 static void ConstTenGetter(Local<String> name, |
10024 const v8::PropertyCallbackInfo<v8::Value>& info) { | 10163 const v8::PropertyCallbackInfo<v8::Value>& info) { |
10025 info.GetReturnValue().Set(v8_num(10)); | 10164 info.GetReturnValue().Set(v8_num(10)); |
10026 } | 10165 } |
10027 | 10166 |
10028 | 10167 |
10029 THREADED_TEST(CrossDomainAccessors) { | 10168 THREADED_TEST(CrossDomainAccessors) { |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10283 | 10422 |
10284 value = v8_compile("var p = 'as' + 'df';")->Run(); | 10423 value = v8_compile("var p = 'as' + 'df';")->Run(); |
10285 value = v8_compile("obj[p];")->Run(); | 10424 value = v8_compile("obj[p];")->Run(); |
10286 | 10425 |
10287 context1->Exit(); | 10426 context1->Exit(); |
10288 context0->Exit(); | 10427 context0->Exit(); |
10289 } | 10428 } |
10290 | 10429 |
10291 | 10430 |
10292 static void AccessControlNamedGetter( | 10431 static void AccessControlNamedGetter( |
10293 Local<String>, | 10432 Local<Name>, const v8::PropertyCallbackInfo<v8::Value>& info) { |
10294 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
10295 info.GetReturnValue().Set(42); | 10433 info.GetReturnValue().Set(42); |
10296 } | 10434 } |
10297 | 10435 |
10298 | 10436 |
10299 static void AccessControlNamedSetter( | 10437 static void AccessControlNamedSetter( |
10300 Local<String>, | 10438 Local<Name>, Local<Value> value, |
10301 Local<Value> value, | |
10302 const v8::PropertyCallbackInfo<v8::Value>& info) { | 10439 const v8::PropertyCallbackInfo<v8::Value>& info) { |
10303 info.GetReturnValue().Set(value); | 10440 info.GetReturnValue().Set(value); |
10304 } | 10441 } |
10305 | 10442 |
10306 | 10443 |
10307 static void AccessControlIndexedGetter( | 10444 static void AccessControlIndexedGetter( |
10308 uint32_t index, | 10445 uint32_t index, |
10309 const v8::PropertyCallbackInfo<v8::Value>& info) { | 10446 const v8::PropertyCallbackInfo<v8::Value>& info) { |
10310 info.GetReturnValue().Set(v8_num(42)); | 10447 info.GetReturnValue().Set(v8_num(42)); |
10311 } | 10448 } |
(...skipping 18 matching lines...) Expand all Loading... |
10330 v8::Local<Context> context0 = Context::New(isolate); | 10467 v8::Local<Context> context0 = Context::New(isolate); |
10331 context0->Enter(); | 10468 context0->Enter(); |
10332 | 10469 |
10333 // Create an object that requires access-check functions to be | 10470 // Create an object that requires access-check functions to be |
10334 // called for cross-domain access. The object also has interceptors | 10471 // called for cross-domain access. The object also has interceptors |
10335 // interceptor. | 10472 // interceptor. |
10336 v8::Handle<v8::ObjectTemplate> object_template = | 10473 v8::Handle<v8::ObjectTemplate> object_template = |
10337 v8::ObjectTemplate::New(isolate); | 10474 v8::ObjectTemplate::New(isolate); |
10338 object_template->SetAccessCheckCallbacks(NamedAccessCounter, | 10475 object_template->SetAccessCheckCallbacks(NamedAccessCounter, |
10339 IndexedAccessCounter); | 10476 IndexedAccessCounter); |
10340 object_template->SetNamedPropertyHandler(AccessControlNamedGetter, | 10477 object_template->SetHandler(v8::NamedPropertyHandlerConfiguration( |
10341 AccessControlNamedSetter); | 10478 AccessControlNamedGetter, AccessControlNamedSetter)); |
10342 object_template->SetIndexedPropertyHandler(AccessControlIndexedGetter, | 10479 object_template->SetIndexedPropertyHandler(AccessControlIndexedGetter, |
10343 AccessControlIndexedSetter); | 10480 AccessControlIndexedSetter); |
10344 Local<v8::Object> object = object_template->NewInstance(); | 10481 Local<v8::Object> object = object_template->NewInstance(); |
10345 | 10482 |
10346 v8::HandleScope scope1(isolate); | 10483 v8::HandleScope scope1(isolate); |
10347 | 10484 |
10348 // Create another environment. | 10485 // Create another environment. |
10349 v8::Local<Context> context1 = Context::New(isolate); | 10486 v8::Local<Context> context1 = Context::New(isolate); |
10350 context1->Enter(); | 10487 context1->Enter(); |
10351 | 10488 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10415 context->Global()->Set(v8_str("i"), o); | 10552 context->Global()->Set(v8_str("i"), o); |
10416 Local<Value> value = CompileRun("i.x"); | 10553 Local<Value> value = CompileRun("i.x"); |
10417 CHECK_EQ(42, value->Int32Value()); | 10554 CHECK_EQ(42, value->Int32Value()); |
10418 | 10555 |
10419 value = CompileRun("i.f()"); | 10556 value = CompileRun("i.f()"); |
10420 CHECK_EQ(12, value->Int32Value()); | 10557 CHECK_EQ(12, value->Int32Value()); |
10421 } | 10558 } |
10422 | 10559 |
10423 | 10560 |
10424 static void GlobalObjectInstancePropertiesGet( | 10561 static void GlobalObjectInstancePropertiesGet( |
10425 Local<String> key, | 10562 Local<Name> key, const v8::PropertyCallbackInfo<v8::Value>&) { |
10426 const v8::PropertyCallbackInfo<v8::Value>&) { | |
10427 ApiTestFuzzer::Fuzz(); | 10563 ApiTestFuzzer::Fuzz(); |
10428 } | 10564 } |
10429 | 10565 |
10430 | 10566 |
10431 THREADED_TEST(GlobalObjectInstanceProperties) { | 10567 THREADED_TEST(GlobalObjectInstanceProperties) { |
10432 v8::Isolate* isolate = CcTest::isolate(); | 10568 v8::Isolate* isolate = CcTest::isolate(); |
10433 v8::HandleScope handle_scope(isolate); | 10569 v8::HandleScope handle_scope(isolate); |
10434 | 10570 |
10435 Local<Value> global_object; | 10571 Local<Value> global_object; |
10436 | 10572 |
10437 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); | 10573 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); |
10438 t->InstanceTemplate()->SetNamedPropertyHandler( | 10574 t->InstanceTemplate()->SetHandler( |
10439 GlobalObjectInstancePropertiesGet); | 10575 v8::NamedPropertyHandlerConfiguration(GlobalObjectInstancePropertiesGet)); |
10440 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); | 10576 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); |
10441 instance_template->Set(v8_str("x"), v8_num(42)); | 10577 instance_template->Set(v8_str("x"), v8_num(42)); |
10442 instance_template->Set(v8_str("f"), | 10578 instance_template->Set(v8_str("f"), |
10443 v8::FunctionTemplate::New(isolate, | 10579 v8::FunctionTemplate::New(isolate, |
10444 InstanceFunctionCallback)); | 10580 InstanceFunctionCallback)); |
10445 | 10581 |
10446 // The script to check how Crankshaft compiles missing global function | 10582 // The script to check how Crankshaft compiles missing global function |
10447 // invocations. function g is not defined and should throw on call. | 10583 // invocations. function g is not defined and should throw on call. |
10448 const char* script = | 10584 const char* script = |
10449 "function wrapper(call) {" | 10585 "function wrapper(call) {" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10553 shadow_y_getter_call_count++; | 10689 shadow_y_getter_call_count++; |
10554 info.GetReturnValue().Set(v8_num(shadow_y)); | 10690 info.GetReturnValue().Set(v8_num(shadow_y)); |
10555 } | 10691 } |
10556 | 10692 |
10557 | 10693 |
10558 static void ShadowIndexedGet(uint32_t index, | 10694 static void ShadowIndexedGet(uint32_t index, |
10559 const v8::PropertyCallbackInfo<v8::Value>&) { | 10695 const v8::PropertyCallbackInfo<v8::Value>&) { |
10560 } | 10696 } |
10561 | 10697 |
10562 | 10698 |
10563 static void ShadowNamedGet(Local<String> key, | 10699 static void ShadowNamedGet(Local<Name> key, |
10564 const v8::PropertyCallbackInfo<v8::Value>&) { | 10700 const v8::PropertyCallbackInfo<v8::Value>&) {} |
10565 } | |
10566 | 10701 |
10567 | 10702 |
10568 THREADED_TEST(ShadowObject) { | 10703 THREADED_TEST(ShadowObject) { |
10569 shadow_y = shadow_y_setter_call_count = shadow_y_getter_call_count = 0; | 10704 shadow_y = shadow_y_setter_call_count = shadow_y_getter_call_count = 0; |
10570 v8::Isolate* isolate = CcTest::isolate(); | 10705 v8::Isolate* isolate = CcTest::isolate(); |
10571 v8::HandleScope handle_scope(isolate); | 10706 v8::HandleScope handle_scope(isolate); |
10572 | 10707 |
10573 Local<ObjectTemplate> global_template = v8::ObjectTemplate::New(isolate); | 10708 Local<ObjectTemplate> global_template = v8::ObjectTemplate::New(isolate); |
10574 LocalContext context(NULL, global_template); | 10709 LocalContext context(NULL, global_template); |
10575 | 10710 |
10576 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); | 10711 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); |
10577 t->InstanceTemplate()->SetNamedPropertyHandler(ShadowNamedGet); | 10712 t->InstanceTemplate()->SetHandler( |
| 10713 v8::NamedPropertyHandlerConfiguration(ShadowNamedGet)); |
10578 t->InstanceTemplate()->SetIndexedPropertyHandler(ShadowIndexedGet); | 10714 t->InstanceTemplate()->SetIndexedPropertyHandler(ShadowIndexedGet); |
10579 Local<ObjectTemplate> proto = t->PrototypeTemplate(); | 10715 Local<ObjectTemplate> proto = t->PrototypeTemplate(); |
10580 Local<ObjectTemplate> instance = t->InstanceTemplate(); | 10716 Local<ObjectTemplate> instance = t->InstanceTemplate(); |
10581 | 10717 |
10582 proto->Set(v8_str("f"), | 10718 proto->Set(v8_str("f"), |
10583 v8::FunctionTemplate::New(isolate, | 10719 v8::FunctionTemplate::New(isolate, |
10584 ShadowFunctionCallback, | 10720 ShadowFunctionCallback, |
10585 Local<Value>())); | 10721 Local<Value>())); |
10586 proto->Set(v8_str("x"), v8_num(12)); | 10722 proto->Set(v8_str("x"), v8_num(12)); |
10587 | 10723 |
(...skipping 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11676 } | 11812 } |
11677 } | 11813 } |
11678 CHECK_EQ(kIterations, v8::HandleScope::NumberOfHandles(isolate)); | 11814 CHECK_EQ(kIterations, v8::HandleScope::NumberOfHandles(isolate)); |
11679 } | 11815 } |
11680 CHECK_EQ(0, v8::HandleScope::NumberOfHandles(isolate)); | 11816 CHECK_EQ(0, v8::HandleScope::NumberOfHandles(isolate)); |
11681 CHECK_EQ(kNesting * kIterations, Recurse(isolate, kNesting, kIterations)); | 11817 CHECK_EQ(kNesting * kIterations, Recurse(isolate, kNesting, kIterations)); |
11682 } | 11818 } |
11683 | 11819 |
11684 | 11820 |
11685 static void InterceptorHasOwnPropertyGetter( | 11821 static void InterceptorHasOwnPropertyGetter( |
11686 Local<String> name, | 11822 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
11687 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
11688 ApiTestFuzzer::Fuzz(); | 11823 ApiTestFuzzer::Fuzz(); |
11689 } | 11824 } |
11690 | 11825 |
11691 | 11826 |
11692 THREADED_TEST(InterceptorHasOwnProperty) { | 11827 THREADED_TEST(InterceptorHasOwnProperty) { |
11693 LocalContext context; | 11828 LocalContext context; |
11694 v8::Isolate* isolate = context->GetIsolate(); | 11829 v8::Isolate* isolate = context->GetIsolate(); |
11695 v8::HandleScope scope(isolate); | 11830 v8::HandleScope scope(isolate); |
11696 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate); | 11831 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate); |
11697 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); | 11832 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); |
11698 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetter); | 11833 instance_templ->SetHandler( |
| 11834 v8::NamedPropertyHandlerConfiguration(InterceptorHasOwnPropertyGetter)); |
11699 Local<Function> function = fun_templ->GetFunction(); | 11835 Local<Function> function = fun_templ->GetFunction(); |
11700 context->Global()->Set(v8_str("constructor"), function); | 11836 context->Global()->Set(v8_str("constructor"), function); |
11701 v8::Handle<Value> value = CompileRun( | 11837 v8::Handle<Value> value = CompileRun( |
11702 "var o = new constructor();" | 11838 "var o = new constructor();" |
11703 "o.hasOwnProperty('ostehaps');"); | 11839 "o.hasOwnProperty('ostehaps');"); |
11704 CHECK_EQ(false, value->BooleanValue()); | 11840 CHECK_EQ(false, value->BooleanValue()); |
11705 value = CompileRun( | 11841 value = CompileRun( |
11706 "o.ostehaps = 42;" | 11842 "o.ostehaps = 42;" |
11707 "o.hasOwnProperty('ostehaps');"); | 11843 "o.hasOwnProperty('ostehaps');"); |
11708 CHECK_EQ(true, value->BooleanValue()); | 11844 CHECK_EQ(true, value->BooleanValue()); |
11709 value = CompileRun( | 11845 value = CompileRun( |
11710 "var p = new constructor();" | 11846 "var p = new constructor();" |
11711 "p.hasOwnProperty('ostehaps');"); | 11847 "p.hasOwnProperty('ostehaps');"); |
11712 CHECK_EQ(false, value->BooleanValue()); | 11848 CHECK_EQ(false, value->BooleanValue()); |
11713 } | 11849 } |
11714 | 11850 |
11715 | 11851 |
11716 static void InterceptorHasOwnPropertyGetterGC( | 11852 static void InterceptorHasOwnPropertyGetterGC( |
11717 Local<String> name, | 11853 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
11718 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
11719 ApiTestFuzzer::Fuzz(); | 11854 ApiTestFuzzer::Fuzz(); |
11720 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 11855 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
11721 } | 11856 } |
11722 | 11857 |
11723 | 11858 |
11724 THREADED_TEST(InterceptorHasOwnPropertyCausingGC) { | 11859 THREADED_TEST(InterceptorHasOwnPropertyCausingGC) { |
11725 LocalContext context; | 11860 LocalContext context; |
11726 v8::Isolate* isolate = context->GetIsolate(); | 11861 v8::Isolate* isolate = context->GetIsolate(); |
11727 v8::HandleScope scope(isolate); | 11862 v8::HandleScope scope(isolate); |
11728 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate); | 11863 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate); |
11729 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); | 11864 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); |
11730 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetterGC); | 11865 instance_templ->SetHandler( |
| 11866 v8::NamedPropertyHandlerConfiguration(InterceptorHasOwnPropertyGetterGC)); |
11731 Local<Function> function = fun_templ->GetFunction(); | 11867 Local<Function> function = fun_templ->GetFunction(); |
11732 context->Global()->Set(v8_str("constructor"), function); | 11868 context->Global()->Set(v8_str("constructor"), function); |
11733 // Let's first make some stuff so we can be sure to get a good GC. | 11869 // Let's first make some stuff so we can be sure to get a good GC. |
11734 CompileRun( | 11870 CompileRun( |
11735 "function makestr(size) {" | 11871 "function makestr(size) {" |
11736 " switch (size) {" | 11872 " switch (size) {" |
11737 " case 1: return 'f';" | 11873 " case 1: return 'f';" |
11738 " case 2: return 'fo';" | 11874 " case 2: return 'fo';" |
11739 " case 3: return 'foo';" | 11875 " case 3: return 'foo';" |
11740 " }" | 11876 " }" |
11741 " return makestr(size >> 1) + makestr((size + 1) >> 1);" | 11877 " return makestr(size >> 1) + makestr((size + 1) >> 1);" |
11742 "}" | 11878 "}" |
11743 "var x = makestr(12345);" | 11879 "var x = makestr(12345);" |
11744 "x = makestr(31415);" | 11880 "x = makestr(31415);" |
11745 "x = makestr(23456);"); | 11881 "x = makestr(23456);"); |
11746 v8::Handle<Value> value = CompileRun( | 11882 v8::Handle<Value> value = CompileRun( |
11747 "var o = new constructor();" | 11883 "var o = new constructor();" |
11748 "o.__proto__ = new String(x);" | 11884 "o.__proto__ = new String(x);" |
11749 "o.hasOwnProperty('ostehaps');"); | 11885 "o.hasOwnProperty('ostehaps');"); |
11750 CHECK_EQ(false, value->BooleanValue()); | 11886 CHECK_EQ(false, value->BooleanValue()); |
11751 } | 11887 } |
11752 | 11888 |
11753 | 11889 |
11754 typedef void (*NamedPropertyGetter)( | 11890 static void CheckInterceptorLoadIC( |
11755 Local<String> property, | 11891 v8::GenericNamedPropertyGetterCallback getter, const char* source, |
11756 const v8::PropertyCallbackInfo<v8::Value>& info); | 11892 int expected) { |
11757 | |
11758 | |
11759 static void CheckInterceptorLoadIC(NamedPropertyGetter getter, | |
11760 const char* source, | |
11761 int expected) { | |
11762 v8::Isolate* isolate = CcTest::isolate(); | 11893 v8::Isolate* isolate = CcTest::isolate(); |
11763 v8::HandleScope scope(isolate); | 11894 v8::HandleScope scope(isolate); |
11764 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 11895 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
11765 templ->SetNamedPropertyHandler(getter, 0, 0, 0, 0, v8_str("data")); | 11896 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(getter, 0, 0, 0, 0, |
| 11897 v8_str("data"))); |
11766 LocalContext context; | 11898 LocalContext context; |
11767 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 11899 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
11768 v8::Handle<Value> value = CompileRun(source); | 11900 v8::Handle<Value> value = CompileRun(source); |
11769 CHECK_EQ(expected, value->Int32Value()); | 11901 CHECK_EQ(expected, value->Int32Value()); |
11770 } | 11902 } |
11771 | 11903 |
11772 | 11904 |
11773 static void InterceptorLoadICGetter( | 11905 static void InterceptorLoadICGetter( |
11774 Local<String> name, | 11906 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
11775 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
11776 ApiTestFuzzer::Fuzz(); | 11907 ApiTestFuzzer::Fuzz(); |
11777 v8::Isolate* isolate = CcTest::isolate(); | 11908 v8::Isolate* isolate = CcTest::isolate(); |
11778 CHECK_EQ(isolate, info.GetIsolate()); | 11909 CHECK_EQ(isolate, info.GetIsolate()); |
11779 CHECK_EQ(v8_str("data"), info.Data()); | 11910 CHECK_EQ(v8_str("data"), info.Data()); |
11780 CHECK_EQ(v8_str("x"), name); | 11911 CHECK_EQ(v8_str("x"), name); |
11781 info.GetReturnValue().Set(v8::Integer::New(isolate, 42)); | 11912 info.GetReturnValue().Set(v8::Integer::New(isolate, 42)); |
11782 } | 11913 } |
11783 | 11914 |
11784 | 11915 |
11785 // This test should hit the load IC for the interceptor case. | 11916 // This test should hit the load IC for the interceptor case. |
11786 THREADED_TEST(InterceptorLoadIC) { | 11917 THREADED_TEST(InterceptorLoadIC) { |
11787 CheckInterceptorLoadIC(InterceptorLoadICGetter, | 11918 CheckInterceptorLoadIC(InterceptorLoadICGetter, |
11788 "var result = 0;" | 11919 "var result = 0;" |
11789 "for (var i = 0; i < 1000; i++) {" | 11920 "for (var i = 0; i < 1000; i++) {" |
11790 " result = o.x;" | 11921 " result = o.x;" |
11791 "}", | 11922 "}", |
11792 42); | 11923 42); |
11793 } | 11924 } |
11794 | 11925 |
11795 | 11926 |
11796 // Below go several tests which verify that JITing for various | 11927 // Below go several tests which verify that JITing for various |
11797 // configurations of interceptor and explicit fields works fine | 11928 // configurations of interceptor and explicit fields works fine |
11798 // (those cases are special cased to get better performance). | 11929 // (those cases are special cased to get better performance). |
11799 | 11930 |
11800 static void InterceptorLoadXICGetter( | 11931 static void InterceptorLoadXICGetter( |
11801 Local<String> name, | 11932 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
11802 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
11803 ApiTestFuzzer::Fuzz(); | 11933 ApiTestFuzzer::Fuzz(); |
11804 info.GetReturnValue().Set( | 11934 info.GetReturnValue().Set( |
11805 v8_str("x")->Equals(name) ? | 11935 v8_str("x")->Equals(name) ? |
11806 v8::Handle<v8::Value>(v8::Integer::New(info.GetIsolate(), 42)) : | 11936 v8::Handle<v8::Value>(v8::Integer::New(info.GetIsolate(), 42)) : |
11807 v8::Handle<v8::Value>()); | 11937 v8::Handle<v8::Value>()); |
11808 } | 11938 } |
11809 | 11939 |
11810 | 11940 |
11811 THREADED_TEST(InterceptorLoadICWithFieldOnHolder) { | 11941 THREADED_TEST(InterceptorLoadICWithFieldOnHolder) { |
11812 CheckInterceptorLoadIC(InterceptorLoadXICGetter, | 11942 CheckInterceptorLoadIC(InterceptorLoadXICGetter, |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11907 "for (var i = 0; i < 1000; i++) {" | 12037 "for (var i = 0; i < 1000; i++) {" |
11908 " result += o.y;" | 12038 " result += o.y;" |
11909 "}" | 12039 "}" |
11910 "result;", | 12040 "result;", |
11911 42 * 1000); | 12041 42 * 1000); |
11912 } | 12042 } |
11913 | 12043 |
11914 | 12044 |
11915 static int interceptor_load_not_handled_calls = 0; | 12045 static int interceptor_load_not_handled_calls = 0; |
11916 static void InterceptorLoadNotHandled( | 12046 static void InterceptorLoadNotHandled( |
11917 Local<String> name, | 12047 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
11918 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
11919 ++interceptor_load_not_handled_calls; | 12048 ++interceptor_load_not_handled_calls; |
11920 } | 12049 } |
11921 | 12050 |
11922 | 12051 |
11923 // Test how post-interceptor lookups are done in the non-cacheable | 12052 // Test how post-interceptor lookups are done in the non-cacheable |
11924 // case: the interceptor should not be invoked during this lookup. | 12053 // case: the interceptor should not be invoked during this lookup. |
11925 THREADED_TEST(InterceptorLoadICPostInterceptor) { | 12054 THREADED_TEST(InterceptorLoadICPostInterceptor) { |
11926 interceptor_load_not_handled_calls = 0; | 12055 interceptor_load_not_handled_calls = 0; |
11927 CheckInterceptorLoadIC(InterceptorLoadNotHandled, | 12056 CheckInterceptorLoadIC(InterceptorLoadNotHandled, |
11928 "receiver = new Object();" | 12057 "receiver = new Object();" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11969 Local<Value> value, | 12098 Local<Value> value, |
11970 const v8::PropertyCallbackInfo<void>& info) { | 12099 const v8::PropertyCallbackInfo<void>& info) { |
11971 Local<Object>::Cast(info.This())->ForceSet(name, value); | 12100 Local<Object>::Cast(info.This())->ForceSet(name, value); |
11972 } | 12101 } |
11973 | 12102 |
11974 | 12103 |
11975 THREADED_TEST(InterceptorLoadICWithCallbackOnHolder) { | 12104 THREADED_TEST(InterceptorLoadICWithCallbackOnHolder) { |
11976 v8::Isolate* isolate = CcTest::isolate(); | 12105 v8::Isolate* isolate = CcTest::isolate(); |
11977 v8::HandleScope scope(isolate); | 12106 v8::HandleScope scope(isolate); |
11978 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 12107 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
11979 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); | 12108 templ->SetHandler( |
| 12109 v8::NamedPropertyHandlerConfiguration(InterceptorLoadXICGetter)); |
11980 templ->SetAccessor(v8_str("y"), Return239Callback); | 12110 templ->SetAccessor(v8_str("y"), Return239Callback); |
11981 LocalContext context; | 12111 LocalContext context; |
11982 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 12112 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
11983 | 12113 |
11984 // Check the case when receiver and interceptor's holder | 12114 // Check the case when receiver and interceptor's holder |
11985 // are the same objects. | 12115 // are the same objects. |
11986 v8::Handle<Value> value = CompileRun( | 12116 v8::Handle<Value> value = CompileRun( |
11987 "var result = 0;" | 12117 "var result = 0;" |
11988 "for (var i = 0; i < 7; i++) {" | 12118 "for (var i = 0; i < 7; i++) {" |
11989 " result = o.y;" | 12119 " result = o.y;" |
11990 "}"); | 12120 "}"); |
11991 CHECK_EQ(239, value->Int32Value()); | 12121 CHECK_EQ(239, value->Int32Value()); |
11992 | 12122 |
11993 // Check the case when interceptor's holder is in proto chain | 12123 // Check the case when interceptor's holder is in proto chain |
11994 // of receiver. | 12124 // of receiver. |
11995 value = CompileRun( | 12125 value = CompileRun( |
11996 "r = { __proto__: o };" | 12126 "r = { __proto__: o };" |
11997 "var result = 0;" | 12127 "var result = 0;" |
11998 "for (var i = 0; i < 7; i++) {" | 12128 "for (var i = 0; i < 7; i++) {" |
11999 " result = r.y;" | 12129 " result = r.y;" |
12000 "}"); | 12130 "}"); |
12001 CHECK_EQ(239, value->Int32Value()); | 12131 CHECK_EQ(239, value->Int32Value()); |
12002 } | 12132 } |
12003 | 12133 |
12004 | 12134 |
12005 THREADED_TEST(InterceptorLoadICWithCallbackOnProto) { | 12135 THREADED_TEST(InterceptorLoadICWithCallbackOnProto) { |
12006 v8::Isolate* isolate = CcTest::isolate(); | 12136 v8::Isolate* isolate = CcTest::isolate(); |
12007 v8::HandleScope scope(isolate); | 12137 v8::HandleScope scope(isolate); |
12008 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); | 12138 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); |
12009 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); | 12139 templ_o->SetHandler( |
| 12140 v8::NamedPropertyHandlerConfiguration(InterceptorLoadXICGetter)); |
12010 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(isolate); | 12141 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(isolate); |
12011 templ_p->SetAccessor(v8_str("y"), Return239Callback); | 12142 templ_p->SetAccessor(v8_str("y"), Return239Callback); |
12012 | 12143 |
12013 LocalContext context; | 12144 LocalContext context; |
12014 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); | 12145 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); |
12015 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); | 12146 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); |
12016 | 12147 |
12017 // Check the case when receiver and interceptor's holder | 12148 // Check the case when receiver and interceptor's holder |
12018 // are the same objects. | 12149 // are the same objects. |
12019 v8::Handle<Value> value = CompileRun( | 12150 v8::Handle<Value> value = CompileRun( |
(...skipping 13 matching lines...) Expand all Loading... |
12033 " result = r.x + r.y;" | 12164 " result = r.x + r.y;" |
12034 "}"); | 12165 "}"); |
12035 CHECK_EQ(239 + 42, value->Int32Value()); | 12166 CHECK_EQ(239 + 42, value->Int32Value()); |
12036 } | 12167 } |
12037 | 12168 |
12038 | 12169 |
12039 THREADED_TEST(InterceptorLoadICForCallbackWithOverride) { | 12170 THREADED_TEST(InterceptorLoadICForCallbackWithOverride) { |
12040 v8::Isolate* isolate = CcTest::isolate(); | 12171 v8::Isolate* isolate = CcTest::isolate(); |
12041 v8::HandleScope scope(isolate); | 12172 v8::HandleScope scope(isolate); |
12042 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 12173 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12043 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); | 12174 templ->SetHandler( |
| 12175 v8::NamedPropertyHandlerConfiguration(InterceptorLoadXICGetter)); |
12044 templ->SetAccessor(v8_str("y"), Return239Callback); | 12176 templ->SetAccessor(v8_str("y"), Return239Callback); |
12045 | 12177 |
12046 LocalContext context; | 12178 LocalContext context; |
12047 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 12179 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
12048 | 12180 |
12049 v8::Handle<Value> value = CompileRun( | 12181 v8::Handle<Value> value = CompileRun( |
12050 "fst = new Object(); fst.__proto__ = o;" | 12182 "fst = new Object(); fst.__proto__ = o;" |
12051 "snd = new Object(); snd.__proto__ = fst;" | 12183 "snd = new Object(); snd.__proto__ = fst;" |
12052 "var result1 = 0;" | 12184 "var result1 = 0;" |
12053 "for (var i = 0; i < 7; i++) {" | 12185 "for (var i = 0; i < 7; i++) {" |
12054 " result1 = snd.x;" | 12186 " result1 = snd.x;" |
12055 "}" | 12187 "}" |
12056 "fst.x = 239;" | 12188 "fst.x = 239;" |
12057 "var result = 0;" | 12189 "var result = 0;" |
12058 "for (var i = 0; i < 7; i++) {" | 12190 "for (var i = 0; i < 7; i++) {" |
12059 " result = snd.x;" | 12191 " result = snd.x;" |
12060 "}" | 12192 "}" |
12061 "result + result1"); | 12193 "result + result1"); |
12062 CHECK_EQ(239 + 42, value->Int32Value()); | 12194 CHECK_EQ(239 + 42, value->Int32Value()); |
12063 } | 12195 } |
12064 | 12196 |
12065 | 12197 |
12066 // Test the case when we stored callback into | 12198 // Test the case when we stored callback into |
12067 // a stub, but interceptor produced value on its own. | 12199 // a stub, but interceptor produced value on its own. |
12068 THREADED_TEST(InterceptorLoadICCallbackNotNeeded) { | 12200 THREADED_TEST(InterceptorLoadICCallbackNotNeeded) { |
12069 v8::Isolate* isolate = CcTest::isolate(); | 12201 v8::Isolate* isolate = CcTest::isolate(); |
12070 v8::HandleScope scope(isolate); | 12202 v8::HandleScope scope(isolate); |
12071 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); | 12203 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); |
12072 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); | 12204 templ_o->SetHandler( |
| 12205 v8::NamedPropertyHandlerConfiguration(InterceptorLoadXICGetter)); |
12073 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(isolate); | 12206 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(isolate); |
12074 templ_p->SetAccessor(v8_str("y"), Return239Callback); | 12207 templ_p->SetAccessor(v8_str("y"), Return239Callback); |
12075 | 12208 |
12076 LocalContext context; | 12209 LocalContext context; |
12077 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); | 12210 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); |
12078 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); | 12211 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); |
12079 | 12212 |
12080 v8::Handle<Value> value = CompileRun( | 12213 v8::Handle<Value> value = CompileRun( |
12081 "o.__proto__ = p;" | 12214 "o.__proto__ = p;" |
12082 "for (var i = 0; i < 7; i++) {" | 12215 "for (var i = 0; i < 7; i++) {" |
12083 " o.x;" | 12216 " o.x;" |
12084 // Now it should be ICed and keep a reference to x defined on p | 12217 // Now it should be ICed and keep a reference to x defined on p |
12085 "}" | 12218 "}" |
12086 "var result = 0;" | 12219 "var result = 0;" |
12087 "for (var i = 0; i < 7; i++) {" | 12220 "for (var i = 0; i < 7; i++) {" |
12088 " result += o.x;" | 12221 " result += o.x;" |
12089 "}" | 12222 "}" |
12090 "result"); | 12223 "result"); |
12091 CHECK_EQ(42 * 7, value->Int32Value()); | 12224 CHECK_EQ(42 * 7, value->Int32Value()); |
12092 } | 12225 } |
12093 | 12226 |
12094 | 12227 |
12095 // Test the case when we stored callback into | 12228 // Test the case when we stored callback into |
12096 // a stub, but it got invalidated later on. | 12229 // a stub, but it got invalidated later on. |
12097 THREADED_TEST(InterceptorLoadICInvalidatedCallback) { | 12230 THREADED_TEST(InterceptorLoadICInvalidatedCallback) { |
12098 v8::Isolate* isolate = CcTest::isolate(); | 12231 v8::Isolate* isolate = CcTest::isolate(); |
12099 v8::HandleScope scope(isolate); | 12232 v8::HandleScope scope(isolate); |
12100 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); | 12233 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); |
12101 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); | 12234 templ_o->SetHandler( |
| 12235 v8::NamedPropertyHandlerConfiguration(InterceptorLoadXICGetter)); |
12102 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(isolate); | 12236 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(isolate); |
12103 templ_p->SetAccessor(v8_str("y"), Return239Callback, SetOnThis); | 12237 templ_p->SetAccessor(v8_str("y"), Return239Callback, SetOnThis); |
12104 | 12238 |
12105 LocalContext context; | 12239 LocalContext context; |
12106 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); | 12240 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); |
12107 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); | 12241 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); |
12108 | 12242 |
12109 v8::Handle<Value> value = CompileRun( | 12243 v8::Handle<Value> value = CompileRun( |
12110 "inbetween = new Object();" | 12244 "inbetween = new Object();" |
12111 "o.__proto__ = inbetween;" | 12245 "o.__proto__ = inbetween;" |
(...skipping 12 matching lines...) Expand all Loading... |
12124 } | 12258 } |
12125 | 12259 |
12126 | 12260 |
12127 // Test the case when we stored callback into | 12261 // Test the case when we stored callback into |
12128 // a stub, but it got invalidated later on due to override on | 12262 // a stub, but it got invalidated later on due to override on |
12129 // global object which is between interceptor and callbacks' holders. | 12263 // global object which is between interceptor and callbacks' holders. |
12130 THREADED_TEST(InterceptorLoadICInvalidatedCallbackViaGlobal) { | 12264 THREADED_TEST(InterceptorLoadICInvalidatedCallbackViaGlobal) { |
12131 v8::Isolate* isolate = CcTest::isolate(); | 12265 v8::Isolate* isolate = CcTest::isolate(); |
12132 v8::HandleScope scope(isolate); | 12266 v8::HandleScope scope(isolate); |
12133 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); | 12267 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); |
12134 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); | 12268 templ_o->SetHandler( |
| 12269 v8::NamedPropertyHandlerConfiguration(InterceptorLoadXICGetter)); |
12135 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(isolate); | 12270 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(isolate); |
12136 templ_p->SetAccessor(v8_str("y"), Return239Callback, SetOnThis); | 12271 templ_p->SetAccessor(v8_str("y"), Return239Callback, SetOnThis); |
12137 | 12272 |
12138 LocalContext context; | 12273 LocalContext context; |
12139 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); | 12274 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); |
12140 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); | 12275 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); |
12141 | 12276 |
12142 v8::Handle<Value> value = CompileRun( | 12277 v8::Handle<Value> value = CompileRun( |
12143 "o.__proto__ = this;" | 12278 "o.__proto__ = this;" |
12144 "this.__proto__ = p;" | 12279 "this.__proto__ = p;" |
12145 "for (var i = 0; i < 10; i++) {" | 12280 "for (var i = 0; i < 10; i++) {" |
12146 " if (o.y != 239) throw 'oops: ' + o.y;" | 12281 " if (o.y != 239) throw 'oops: ' + o.y;" |
12147 // Now it should be ICed and keep a reference to y defined on p | 12282 // Now it should be ICed and keep a reference to y defined on p |
12148 "}" | 12283 "}" |
12149 "this.y = 42;" | 12284 "this.y = 42;" |
12150 "var result = 0;" | 12285 "var result = 0;" |
12151 "for (var i = 0; i < 10; i++) {" | 12286 "for (var i = 0; i < 10; i++) {" |
12152 " result += o.y;" | 12287 " result += o.y;" |
12153 "}" | 12288 "}" |
12154 "result"); | 12289 "result"); |
12155 CHECK_EQ(42 * 10, value->Int32Value()); | 12290 CHECK_EQ(42 * 10, value->Int32Value()); |
12156 } | 12291 } |
12157 | 12292 |
12158 | 12293 |
12159 static void InterceptorLoadICGetter0( | 12294 static void InterceptorLoadICGetter0( |
12160 Local<String> name, | 12295 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
12161 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
12162 ApiTestFuzzer::Fuzz(); | 12296 ApiTestFuzzer::Fuzz(); |
12163 CHECK(v8_str("x")->Equals(name)); | 12297 CHECK(v8_str("x")->Equals(name)); |
12164 info.GetReturnValue().Set(v8::Integer::New(info.GetIsolate(), 0)); | 12298 info.GetReturnValue().Set(v8::Integer::New(info.GetIsolate(), 0)); |
12165 } | 12299 } |
12166 | 12300 |
12167 | 12301 |
12168 THREADED_TEST(InterceptorReturningZero) { | 12302 THREADED_TEST(InterceptorReturningZero) { |
12169 CheckInterceptorLoadIC(InterceptorLoadICGetter0, | 12303 CheckInterceptorLoadIC(InterceptorLoadICGetter0, |
12170 "o.x == undefined ? 1 : 0", | 12304 "o.x == undefined ? 1 : 0", |
12171 0); | 12305 0); |
12172 } | 12306 } |
12173 | 12307 |
12174 | 12308 |
12175 static void InterceptorStoreICSetter( | 12309 static void InterceptorStoreICSetter( |
12176 Local<String> key, | 12310 Local<Name> key, Local<Value> value, |
12177 Local<Value> value, | |
12178 const v8::PropertyCallbackInfo<v8::Value>& info) { | 12311 const v8::PropertyCallbackInfo<v8::Value>& info) { |
12179 CHECK(v8_str("x")->Equals(key)); | 12312 CHECK(v8_str("x")->Equals(key)); |
12180 CHECK_EQ(42, value->Int32Value()); | 12313 CHECK_EQ(42, value->Int32Value()); |
12181 info.GetReturnValue().Set(value); | 12314 info.GetReturnValue().Set(value); |
12182 } | 12315 } |
12183 | 12316 |
12184 | 12317 |
12185 // This test should hit the store IC for the interceptor case. | 12318 // This test should hit the store IC for the interceptor case. |
12186 THREADED_TEST(InterceptorStoreIC) { | 12319 THREADED_TEST(InterceptorStoreIC) { |
12187 v8::Isolate* isolate = CcTest::isolate(); | 12320 v8::Isolate* isolate = CcTest::isolate(); |
12188 v8::HandleScope scope(isolate); | 12321 v8::HandleScope scope(isolate); |
12189 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 12322 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12190 templ->SetNamedPropertyHandler(InterceptorLoadICGetter, | 12323 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
12191 InterceptorStoreICSetter, | 12324 InterceptorLoadICGetter, InterceptorStoreICSetter, 0, 0, 0, |
12192 0, 0, 0, v8_str("data")); | 12325 v8_str("data"))); |
12193 LocalContext context; | 12326 LocalContext context; |
12194 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 12327 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
12195 CompileRun( | 12328 CompileRun( |
12196 "for (var i = 0; i < 1000; i++) {" | 12329 "for (var i = 0; i < 1000; i++) {" |
12197 " o.x = 42;" | 12330 " o.x = 42;" |
12198 "}"); | 12331 "}"); |
12199 } | 12332 } |
12200 | 12333 |
12201 | 12334 |
12202 THREADED_TEST(InterceptorStoreICWithNoSetter) { | 12335 THREADED_TEST(InterceptorStoreICWithNoSetter) { |
12203 v8::Isolate* isolate = CcTest::isolate(); | 12336 v8::Isolate* isolate = CcTest::isolate(); |
12204 v8::HandleScope scope(isolate); | 12337 v8::HandleScope scope(isolate); |
12205 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 12338 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12206 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); | 12339 templ->SetHandler( |
| 12340 v8::NamedPropertyHandlerConfiguration(InterceptorLoadXICGetter)); |
12207 LocalContext context; | 12341 LocalContext context; |
12208 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 12342 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
12209 v8::Handle<Value> value = CompileRun( | 12343 v8::Handle<Value> value = CompileRun( |
12210 "for (var i = 0; i < 1000; i++) {" | 12344 "for (var i = 0; i < 1000; i++) {" |
12211 " o.y = 239;" | 12345 " o.y = 239;" |
12212 "}" | 12346 "}" |
12213 "42 + o.y"); | 12347 "42 + o.y"); |
12214 CHECK_EQ(239 + 42, value->Int32Value()); | 12348 CHECK_EQ(239 + 42, value->Int32Value()); |
12215 } | 12349 } |
12216 | 12350 |
12217 | 12351 |
12218 | 12352 |
12219 | 12353 |
12220 v8::Handle<Value> call_ic_function; | 12354 v8::Handle<Value> call_ic_function; |
12221 v8::Handle<Value> call_ic_function2; | 12355 v8::Handle<Value> call_ic_function2; |
12222 v8::Handle<Value> call_ic_function3; | 12356 v8::Handle<Value> call_ic_function3; |
12223 | 12357 |
12224 static void InterceptorCallICGetter( | 12358 static void InterceptorCallICGetter( |
12225 Local<String> name, | 12359 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
12226 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
12227 ApiTestFuzzer::Fuzz(); | 12360 ApiTestFuzzer::Fuzz(); |
12228 CHECK(v8_str("x")->Equals(name)); | 12361 CHECK(v8_str("x")->Equals(name)); |
12229 info.GetReturnValue().Set(call_ic_function); | 12362 info.GetReturnValue().Set(call_ic_function); |
12230 } | 12363 } |
12231 | 12364 |
12232 | 12365 |
12233 // This test should hit the call IC for the interceptor case. | 12366 // This test should hit the call IC for the interceptor case. |
12234 THREADED_TEST(InterceptorCallIC) { | 12367 THREADED_TEST(InterceptorCallIC) { |
12235 v8::Isolate* isolate = CcTest::isolate(); | 12368 v8::Isolate* isolate = CcTest::isolate(); |
12236 v8::HandleScope scope(isolate); | 12369 v8::HandleScope scope(isolate); |
12237 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 12370 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12238 templ->SetNamedPropertyHandler(InterceptorCallICGetter); | 12371 templ->SetHandler( |
| 12372 v8::NamedPropertyHandlerConfiguration(InterceptorCallICGetter)); |
12239 LocalContext context; | 12373 LocalContext context; |
12240 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 12374 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
12241 call_ic_function = | 12375 call_ic_function = |
12242 v8_compile("function f(x) { return x + 1; }; f")->Run(); | 12376 v8_compile("function f(x) { return x + 1; }; f")->Run(); |
12243 v8::Handle<Value> value = CompileRun( | 12377 v8::Handle<Value> value = CompileRun( |
12244 "var result = 0;" | 12378 "var result = 0;" |
12245 "for (var i = 0; i < 1000; i++) {" | 12379 "for (var i = 0; i < 1000; i++) {" |
12246 " result = o.x(41);" | 12380 " result = o.x(41);" |
12247 "}"); | 12381 "}"); |
12248 CHECK_EQ(42, value->Int32Value()); | 12382 CHECK_EQ(42, value->Int32Value()); |
12249 } | 12383 } |
12250 | 12384 |
12251 | 12385 |
12252 // This test checks that if interceptor doesn't provide | 12386 // This test checks that if interceptor doesn't provide |
12253 // a value, we can fetch regular value. | 12387 // a value, we can fetch regular value. |
12254 THREADED_TEST(InterceptorCallICSeesOthers) { | 12388 THREADED_TEST(InterceptorCallICSeesOthers) { |
12255 v8::Isolate* isolate = CcTest::isolate(); | 12389 v8::Isolate* isolate = CcTest::isolate(); |
12256 v8::HandleScope scope(isolate); | 12390 v8::HandleScope scope(isolate); |
12257 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 12391 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12258 templ->SetNamedPropertyHandler(NoBlockGetterX); | 12392 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(NoBlockGetterX)); |
12259 LocalContext context; | 12393 LocalContext context; |
12260 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 12394 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
12261 v8::Handle<Value> value = CompileRun( | 12395 v8::Handle<Value> value = CompileRun( |
12262 "o.x = function f(x) { return x + 1; };" | 12396 "o.x = function f(x) { return x + 1; };" |
12263 "var result = 0;" | 12397 "var result = 0;" |
12264 "for (var i = 0; i < 7; i++) {" | 12398 "for (var i = 0; i < 7; i++) {" |
12265 " result = o.x(41);" | 12399 " result = o.x(41);" |
12266 "}"); | 12400 "}"); |
12267 CHECK_EQ(42, value->Int32Value()); | 12401 CHECK_EQ(42, value->Int32Value()); |
12268 } | 12402 } |
12269 | 12403 |
12270 | 12404 |
12271 static v8::Handle<Value> call_ic_function4; | 12405 static v8::Handle<Value> call_ic_function4; |
12272 static void InterceptorCallICGetter4( | 12406 static void InterceptorCallICGetter4( |
12273 Local<String> name, | 12407 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
12274 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
12275 ApiTestFuzzer::Fuzz(); | 12408 ApiTestFuzzer::Fuzz(); |
12276 CHECK(v8_str("x")->Equals(name)); | 12409 CHECK(v8_str("x")->Equals(name)); |
12277 info.GetReturnValue().Set(call_ic_function4); | 12410 info.GetReturnValue().Set(call_ic_function4); |
12278 } | 12411 } |
12279 | 12412 |
12280 | 12413 |
12281 // This test checks that if interceptor provides a function, | 12414 // This test checks that if interceptor provides a function, |
12282 // even if we cached shadowed variant, interceptor's function | 12415 // even if we cached shadowed variant, interceptor's function |
12283 // is invoked | 12416 // is invoked |
12284 THREADED_TEST(InterceptorCallICCacheableNotNeeded) { | 12417 THREADED_TEST(InterceptorCallICCacheableNotNeeded) { |
12285 v8::Isolate* isolate = CcTest::isolate(); | 12418 v8::Isolate* isolate = CcTest::isolate(); |
12286 v8::HandleScope scope(isolate); | 12419 v8::HandleScope scope(isolate); |
12287 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 12420 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12288 templ->SetNamedPropertyHandler(InterceptorCallICGetter4); | 12421 templ->SetHandler( |
| 12422 v8::NamedPropertyHandlerConfiguration(InterceptorCallICGetter4)); |
12289 LocalContext context; | 12423 LocalContext context; |
12290 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 12424 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
12291 call_ic_function4 = | 12425 call_ic_function4 = |
12292 v8_compile("function f(x) { return x - 1; }; f")->Run(); | 12426 v8_compile("function f(x) { return x - 1; }; f")->Run(); |
12293 v8::Handle<Value> value = CompileRun( | 12427 v8::Handle<Value> value = CompileRun( |
12294 "Object.getPrototypeOf(o).x = function(x) { return x + 1; };" | 12428 "Object.getPrototypeOf(o).x = function(x) { return x + 1; };" |
12295 "var result = 0;" | 12429 "var result = 0;" |
12296 "for (var i = 0; i < 1000; i++) {" | 12430 "for (var i = 0; i < 1000; i++) {" |
12297 " result = o.x(42);" | 12431 " result = o.x(42);" |
12298 "}"); | 12432 "}"); |
12299 CHECK_EQ(41, value->Int32Value()); | 12433 CHECK_EQ(41, value->Int32Value()); |
12300 } | 12434 } |
12301 | 12435 |
12302 | 12436 |
12303 // Test the case when we stored cacheable lookup into | 12437 // Test the case when we stored cacheable lookup into |
12304 // a stub, but it got invalidated later on | 12438 // a stub, but it got invalidated later on |
12305 THREADED_TEST(InterceptorCallICInvalidatedCacheable) { | 12439 THREADED_TEST(InterceptorCallICInvalidatedCacheable) { |
12306 v8::Isolate* isolate = CcTest::isolate(); | 12440 v8::Isolate* isolate = CcTest::isolate(); |
12307 v8::HandleScope scope(isolate); | 12441 v8::HandleScope scope(isolate); |
12308 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 12442 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12309 templ->SetNamedPropertyHandler(NoBlockGetterX); | 12443 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(NoBlockGetterX)); |
12310 LocalContext context; | 12444 LocalContext context; |
12311 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 12445 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
12312 v8::Handle<Value> value = CompileRun( | 12446 v8::Handle<Value> value = CompileRun( |
12313 "proto1 = new Object();" | 12447 "proto1 = new Object();" |
12314 "proto2 = new Object();" | 12448 "proto2 = new Object();" |
12315 "o.__proto__ = proto1;" | 12449 "o.__proto__ = proto1;" |
12316 "proto1.__proto__ = proto2;" | 12450 "proto1.__proto__ = proto2;" |
12317 "proto2.y = function(x) { return x + 1; };" | 12451 "proto2.y = function(x) { return x + 1; };" |
12318 // Invoke it many times to compile a stub | 12452 // Invoke it many times to compile a stub |
12319 "for (var i = 0; i < 7; i++) {" | 12453 "for (var i = 0; i < 7; i++) {" |
12320 " o.y(42);" | 12454 " o.y(42);" |
12321 "}" | 12455 "}" |
12322 "proto1.y = function(x) { return x - 1; };" | 12456 "proto1.y = function(x) { return x - 1; };" |
12323 "var result = 0;" | 12457 "var result = 0;" |
12324 "for (var i = 0; i < 7; i++) {" | 12458 "for (var i = 0; i < 7; i++) {" |
12325 " result += o.y(42);" | 12459 " result += o.y(42);" |
12326 "}"); | 12460 "}"); |
12327 CHECK_EQ(41 * 7, value->Int32Value()); | 12461 CHECK_EQ(41 * 7, value->Int32Value()); |
12328 } | 12462 } |
12329 | 12463 |
12330 | 12464 |
12331 // This test checks that if interceptor doesn't provide a function, | 12465 // This test checks that if interceptor doesn't provide a function, |
12332 // cached constant function is used | 12466 // cached constant function is used |
12333 THREADED_TEST(InterceptorCallICConstantFunctionUsed) { | 12467 THREADED_TEST(InterceptorCallICConstantFunctionUsed) { |
12334 v8::Isolate* isolate = CcTest::isolate(); | 12468 v8::Isolate* isolate = CcTest::isolate(); |
12335 v8::HandleScope scope(isolate); | 12469 v8::HandleScope scope(isolate); |
12336 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 12470 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12337 templ->SetNamedPropertyHandler(NoBlockGetterX); | 12471 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(NoBlockGetterX)); |
12338 LocalContext context; | 12472 LocalContext context; |
12339 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 12473 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
12340 v8::Handle<Value> value = CompileRun( | 12474 v8::Handle<Value> value = CompileRun( |
12341 "function inc(x) { return x + 1; };" | 12475 "function inc(x) { return x + 1; };" |
12342 "inc(1);" | 12476 "inc(1);" |
12343 "o.x = inc;" | 12477 "o.x = inc;" |
12344 "var result = 0;" | 12478 "var result = 0;" |
12345 "for (var i = 0; i < 1000; i++) {" | 12479 "for (var i = 0; i < 1000; i++) {" |
12346 " result = o.x(42);" | 12480 " result = o.x(42);" |
12347 "}"); | 12481 "}"); |
12348 CHECK_EQ(43, value->Int32Value()); | 12482 CHECK_EQ(43, value->Int32Value()); |
12349 } | 12483 } |
12350 | 12484 |
12351 | 12485 |
12352 static v8::Handle<Value> call_ic_function5; | 12486 static v8::Handle<Value> call_ic_function5; |
12353 static void InterceptorCallICGetter5( | 12487 static void InterceptorCallICGetter5( |
12354 Local<String> name, | 12488 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
12355 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
12356 ApiTestFuzzer::Fuzz(); | 12489 ApiTestFuzzer::Fuzz(); |
12357 if (v8_str("x")->Equals(name)) | 12490 if (v8_str("x")->Equals(name)) |
12358 info.GetReturnValue().Set(call_ic_function5); | 12491 info.GetReturnValue().Set(call_ic_function5); |
12359 } | 12492 } |
12360 | 12493 |
12361 | 12494 |
12362 // This test checks that if interceptor provides a function, | 12495 // This test checks that if interceptor provides a function, |
12363 // even if we cached constant function, interceptor's function | 12496 // even if we cached constant function, interceptor's function |
12364 // is invoked | 12497 // is invoked |
12365 THREADED_TEST(InterceptorCallICConstantFunctionNotNeeded) { | 12498 THREADED_TEST(InterceptorCallICConstantFunctionNotNeeded) { |
12366 v8::Isolate* isolate = CcTest::isolate(); | 12499 v8::Isolate* isolate = CcTest::isolate(); |
12367 v8::HandleScope scope(isolate); | 12500 v8::HandleScope scope(isolate); |
12368 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 12501 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12369 templ->SetNamedPropertyHandler(InterceptorCallICGetter5); | 12502 templ->SetHandler( |
| 12503 v8::NamedPropertyHandlerConfiguration(InterceptorCallICGetter5)); |
12370 LocalContext context; | 12504 LocalContext context; |
12371 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 12505 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
12372 call_ic_function5 = | 12506 call_ic_function5 = |
12373 v8_compile("function f(x) { return x - 1; }; f")->Run(); | 12507 v8_compile("function f(x) { return x - 1; }; f")->Run(); |
12374 v8::Handle<Value> value = CompileRun( | 12508 v8::Handle<Value> value = CompileRun( |
12375 "function inc(x) { return x + 1; };" | 12509 "function inc(x) { return x + 1; };" |
12376 "inc(1);" | 12510 "inc(1);" |
12377 "o.x = inc;" | 12511 "o.x = inc;" |
12378 "var result = 0;" | 12512 "var result = 0;" |
12379 "for (var i = 0; i < 1000; i++) {" | 12513 "for (var i = 0; i < 1000; i++) {" |
12380 " result = o.x(42);" | 12514 " result = o.x(42);" |
12381 "}"); | 12515 "}"); |
12382 CHECK_EQ(41, value->Int32Value()); | 12516 CHECK_EQ(41, value->Int32Value()); |
12383 } | 12517 } |
12384 | 12518 |
12385 | 12519 |
12386 static v8::Handle<Value> call_ic_function6; | 12520 static v8::Handle<Value> call_ic_function6; |
12387 static void InterceptorCallICGetter6( | 12521 static void InterceptorCallICGetter6( |
12388 Local<String> name, | 12522 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
12389 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
12390 ApiTestFuzzer::Fuzz(); | 12523 ApiTestFuzzer::Fuzz(); |
12391 if (v8_str("x")->Equals(name)) | 12524 if (v8_str("x")->Equals(name)) |
12392 info.GetReturnValue().Set(call_ic_function6); | 12525 info.GetReturnValue().Set(call_ic_function6); |
12393 } | 12526 } |
12394 | 12527 |
12395 | 12528 |
12396 // Same test as above, except the code is wrapped in a function | 12529 // Same test as above, except the code is wrapped in a function |
12397 // to test the optimized compiler. | 12530 // to test the optimized compiler. |
12398 THREADED_TEST(InterceptorCallICConstantFunctionNotNeededWrapped) { | 12531 THREADED_TEST(InterceptorCallICConstantFunctionNotNeededWrapped) { |
12399 i::FLAG_allow_natives_syntax = true; | 12532 i::FLAG_allow_natives_syntax = true; |
12400 v8::Isolate* isolate = CcTest::isolate(); | 12533 v8::Isolate* isolate = CcTest::isolate(); |
12401 v8::HandleScope scope(isolate); | 12534 v8::HandleScope scope(isolate); |
12402 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 12535 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12403 templ->SetNamedPropertyHandler(InterceptorCallICGetter6); | 12536 templ->SetHandler( |
| 12537 v8::NamedPropertyHandlerConfiguration(InterceptorCallICGetter6)); |
12404 LocalContext context; | 12538 LocalContext context; |
12405 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 12539 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
12406 call_ic_function6 = | 12540 call_ic_function6 = |
12407 v8_compile("function f(x) { return x - 1; }; f")->Run(); | 12541 v8_compile("function f(x) { return x - 1; }; f")->Run(); |
12408 v8::Handle<Value> value = CompileRun( | 12542 v8::Handle<Value> value = CompileRun( |
12409 "function inc(x) { return x + 1; };" | 12543 "function inc(x) { return x + 1; };" |
12410 "inc(1);" | 12544 "inc(1);" |
12411 "o.x = inc;" | 12545 "o.x = inc;" |
12412 "function test() {" | 12546 "function test() {" |
12413 " var result = 0;" | 12547 " var result = 0;" |
(...skipping 10 matching lines...) Expand all Loading... |
12424 CHECK_EQ(41, value->Int32Value()); | 12558 CHECK_EQ(41, value->Int32Value()); |
12425 } | 12559 } |
12426 | 12560 |
12427 | 12561 |
12428 // Test the case when we stored constant function into | 12562 // Test the case when we stored constant function into |
12429 // a stub, but it got invalidated later on | 12563 // a stub, but it got invalidated later on |
12430 THREADED_TEST(InterceptorCallICInvalidatedConstantFunction) { | 12564 THREADED_TEST(InterceptorCallICInvalidatedConstantFunction) { |
12431 v8::Isolate* isolate = CcTest::isolate(); | 12565 v8::Isolate* isolate = CcTest::isolate(); |
12432 v8::HandleScope scope(isolate); | 12566 v8::HandleScope scope(isolate); |
12433 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 12567 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12434 templ->SetNamedPropertyHandler(NoBlockGetterX); | 12568 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(NoBlockGetterX)); |
12435 LocalContext context; | 12569 LocalContext context; |
12436 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 12570 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
12437 v8::Handle<Value> value = CompileRun( | 12571 v8::Handle<Value> value = CompileRun( |
12438 "function inc(x) { return x + 1; };" | 12572 "function inc(x) { return x + 1; };" |
12439 "inc(1);" | 12573 "inc(1);" |
12440 "proto1 = new Object();" | 12574 "proto1 = new Object();" |
12441 "proto2 = new Object();" | 12575 "proto2 = new Object();" |
12442 "o.__proto__ = proto1;" | 12576 "o.__proto__ = proto1;" |
12443 "proto1.__proto__ = proto2;" | 12577 "proto1.__proto__ = proto2;" |
12444 "proto2.y = inc;" | 12578 "proto2.y = inc;" |
(...skipping 10 matching lines...) Expand all Loading... |
12455 } | 12589 } |
12456 | 12590 |
12457 | 12591 |
12458 // Test the case when we stored constant function into | 12592 // Test the case when we stored constant function into |
12459 // a stub, but it got invalidated later on due to override on | 12593 // a stub, but it got invalidated later on due to override on |
12460 // global object which is between interceptor and constant function' holders. | 12594 // global object which is between interceptor and constant function' holders. |
12461 THREADED_TEST(InterceptorCallICInvalidatedConstantFunctionViaGlobal) { | 12595 THREADED_TEST(InterceptorCallICInvalidatedConstantFunctionViaGlobal) { |
12462 v8::Isolate* isolate = CcTest::isolate(); | 12596 v8::Isolate* isolate = CcTest::isolate(); |
12463 v8::HandleScope scope(isolate); | 12597 v8::HandleScope scope(isolate); |
12464 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 12598 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12465 templ->SetNamedPropertyHandler(NoBlockGetterX); | 12599 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(NoBlockGetterX)); |
12466 LocalContext context; | 12600 LocalContext context; |
12467 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 12601 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
12468 v8::Handle<Value> value = CompileRun( | 12602 v8::Handle<Value> value = CompileRun( |
12469 "function inc(x) { return x + 1; };" | 12603 "function inc(x) { return x + 1; };" |
12470 "inc(1);" | 12604 "inc(1);" |
12471 "o.__proto__ = this;" | 12605 "o.__proto__ = this;" |
12472 "this.__proto__.y = inc;" | 12606 "this.__proto__.y = inc;" |
12473 // Invoke it many times to compile a stub | 12607 // Invoke it many times to compile a stub |
12474 "for (var i = 0; i < 7; i++) {" | 12608 "for (var i = 0; i < 7; i++) {" |
12475 " if (o.y(42) != 43) throw 'oops: ' + o.y(42);" | 12609 " if (o.y(42) != 43) throw 'oops: ' + o.y(42);" |
12476 "}" | 12610 "}" |
12477 "this.y = function(x) { return x - 1; };" | 12611 "this.y = function(x) { return x - 1; };" |
12478 "var result = 0;" | 12612 "var result = 0;" |
12479 "for (var i = 0; i < 7; i++) {" | 12613 "for (var i = 0; i < 7; i++) {" |
12480 " result += o.y(42);" | 12614 " result += o.y(42);" |
12481 "}"); | 12615 "}"); |
12482 CHECK_EQ(41 * 7, value->Int32Value()); | 12616 CHECK_EQ(41 * 7, value->Int32Value()); |
12483 } | 12617 } |
12484 | 12618 |
12485 | 12619 |
12486 // Test the case when actual function to call sits on global object. | 12620 // Test the case when actual function to call sits on global object. |
12487 THREADED_TEST(InterceptorCallICCachedFromGlobal) { | 12621 THREADED_TEST(InterceptorCallICCachedFromGlobal) { |
12488 v8::Isolate* isolate = CcTest::isolate(); | 12622 v8::Isolate* isolate = CcTest::isolate(); |
12489 v8::HandleScope scope(isolate); | 12623 v8::HandleScope scope(isolate); |
12490 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); | 12624 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); |
12491 templ_o->SetNamedPropertyHandler(NoBlockGetterX); | 12625 templ_o->SetHandler(v8::NamedPropertyHandlerConfiguration(NoBlockGetterX)); |
12492 | 12626 |
12493 LocalContext context; | 12627 LocalContext context; |
12494 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); | 12628 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); |
12495 | 12629 |
12496 v8::Handle<Value> value = CompileRun( | 12630 v8::Handle<Value> value = CompileRun( |
12497 "try {" | 12631 "try {" |
12498 " o.__proto__ = this;" | 12632 " o.__proto__ = this;" |
12499 " for (var i = 0; i < 10; i++) {" | 12633 " for (var i = 0; i < 10; i++) {" |
12500 " var v = o.parseFloat('239');" | 12634 " var v = o.parseFloat('239');" |
12501 " if (v != 239) throw v;" | 12635 " if (v != 239) throw v;" |
12502 // Now it should be ICed and keep a reference to parseFloat. | 12636 // Now it should be ICed and keep a reference to parseFloat. |
12503 " }" | 12637 " }" |
12504 " var result = 0;" | 12638 " var result = 0;" |
12505 " for (var i = 0; i < 10; i++) {" | 12639 " for (var i = 0; i < 10; i++) {" |
12506 " result += o.parseFloat('239');" | 12640 " result += o.parseFloat('239');" |
12507 " }" | 12641 " }" |
12508 " result" | 12642 " result" |
12509 "} catch(e) {" | 12643 "} catch(e) {" |
12510 " e" | 12644 " e" |
12511 "};"); | 12645 "};"); |
12512 CHECK_EQ(239 * 10, value->Int32Value()); | 12646 CHECK_EQ(239 * 10, value->Int32Value()); |
12513 } | 12647 } |
12514 | 12648 |
12515 static void InterceptorCallICFastApi( | 12649 static void InterceptorCallICFastApi( |
12516 Local<String> name, | 12650 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
12517 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
12518 ApiTestFuzzer::Fuzz(); | 12651 ApiTestFuzzer::Fuzz(); |
12519 CheckReturnValue(info, FUNCTION_ADDR(InterceptorCallICFastApi)); | 12652 CheckReturnValue(info, FUNCTION_ADDR(InterceptorCallICFastApi)); |
12520 int* call_count = | 12653 int* call_count = |
12521 reinterpret_cast<int*>(v8::External::Cast(*info.Data())->Value()); | 12654 reinterpret_cast<int*>(v8::External::Cast(*info.Data())->Value()); |
12522 ++(*call_count); | 12655 ++(*call_count); |
12523 if ((*call_count) % 20 == 0) { | 12656 if ((*call_count) % 20 == 0) { |
12524 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 12657 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
12525 } | 12658 } |
12526 } | 12659 } |
12527 | 12660 |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12696 v8::Handle<v8::FunctionTemplate> fun_templ = | 12829 v8::Handle<v8::FunctionTemplate> fun_templ = |
12697 v8::FunctionTemplate::New(isolate); | 12830 v8::FunctionTemplate::New(isolate); |
12698 v8::Handle<v8::FunctionTemplate> method_templ = | 12831 v8::Handle<v8::FunctionTemplate> method_templ = |
12699 v8::FunctionTemplate::New(isolate, | 12832 v8::FunctionTemplate::New(isolate, |
12700 FastApiCallback_TrivialSignature, | 12833 FastApiCallback_TrivialSignature, |
12701 v8_str("method_data"), | 12834 v8_str("method_data"), |
12702 v8::Handle<v8::Signature>()); | 12835 v8::Handle<v8::Signature>()); |
12703 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 12836 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
12704 proto_templ->Set(v8_str("method"), method_templ); | 12837 proto_templ->Set(v8_str("method"), method_templ); |
12705 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 12838 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
12706 templ->SetNamedPropertyHandler( | 12839 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
12707 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, | 12840 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, |
12708 v8::External::New(isolate, &interceptor_call_count)); | 12841 v8::External::New(isolate, &interceptor_call_count))); |
12709 LocalContext context; | 12842 LocalContext context; |
12710 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 12843 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
12711 GenerateSomeGarbage(); | 12844 GenerateSomeGarbage(); |
12712 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 12845 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
12713 CompileRun( | 12846 CompileRun( |
12714 "var result = 0;" | 12847 "var result = 0;" |
12715 "for (var i = 0; i < 100; i++) {" | 12848 "for (var i = 0; i < 100; i++) {" |
12716 " result = o.method(41);" | 12849 " result = o.method(41);" |
12717 "}"); | 12850 "}"); |
12718 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); | 12851 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); |
12719 CHECK_EQ(100, interceptor_call_count); | 12852 CHECK_EQ(100, interceptor_call_count); |
12720 } | 12853 } |
12721 | 12854 |
12722 | 12855 |
12723 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature) { | 12856 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature) { |
12724 int interceptor_call_count = 0; | 12857 int interceptor_call_count = 0; |
12725 v8::Isolate* isolate = CcTest::isolate(); | 12858 v8::Isolate* isolate = CcTest::isolate(); |
12726 v8::HandleScope scope(isolate); | 12859 v8::HandleScope scope(isolate); |
12727 v8::Handle<v8::FunctionTemplate> fun_templ = | 12860 v8::Handle<v8::FunctionTemplate> fun_templ = |
12728 v8::FunctionTemplate::New(isolate); | 12861 v8::FunctionTemplate::New(isolate); |
12729 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( | 12862 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
12730 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), | 12863 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), |
12731 v8::Signature::New(isolate, fun_templ)); | 12864 v8::Signature::New(isolate, fun_templ)); |
12732 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 12865 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
12733 proto_templ->Set(v8_str("method"), method_templ); | 12866 proto_templ->Set(v8_str("method"), method_templ); |
12734 fun_templ->SetHiddenPrototype(true); | 12867 fun_templ->SetHiddenPrototype(true); |
12735 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 12868 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
12736 templ->SetNamedPropertyHandler( | 12869 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
12737 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, | 12870 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, |
12738 v8::External::New(isolate, &interceptor_call_count)); | 12871 v8::External::New(isolate, &interceptor_call_count))); |
12739 LocalContext context; | 12872 LocalContext context; |
12740 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 12873 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
12741 GenerateSomeGarbage(); | 12874 GenerateSomeGarbage(); |
12742 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 12875 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
12743 CompileRun( | 12876 CompileRun( |
12744 "o.foo = 17;" | 12877 "o.foo = 17;" |
12745 "var receiver = {};" | 12878 "var receiver = {};" |
12746 "receiver.__proto__ = o;" | 12879 "receiver.__proto__ = o;" |
12747 "var result = 0;" | 12880 "var result = 0;" |
12748 "for (var i = 0; i < 100; i++) {" | 12881 "for (var i = 0; i < 100; i++) {" |
(...skipping 10 matching lines...) Expand all Loading... |
12759 v8::HandleScope scope(isolate); | 12892 v8::HandleScope scope(isolate); |
12760 v8::Handle<v8::FunctionTemplate> fun_templ = | 12893 v8::Handle<v8::FunctionTemplate> fun_templ = |
12761 v8::FunctionTemplate::New(isolate); | 12894 v8::FunctionTemplate::New(isolate); |
12762 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( | 12895 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
12763 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), | 12896 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), |
12764 v8::Signature::New(isolate, fun_templ)); | 12897 v8::Signature::New(isolate, fun_templ)); |
12765 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 12898 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
12766 proto_templ->Set(v8_str("method"), method_templ); | 12899 proto_templ->Set(v8_str("method"), method_templ); |
12767 fun_templ->SetHiddenPrototype(true); | 12900 fun_templ->SetHiddenPrototype(true); |
12768 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 12901 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
12769 templ->SetNamedPropertyHandler( | 12902 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
12770 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, | 12903 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, |
12771 v8::External::New(isolate, &interceptor_call_count)); | 12904 v8::External::New(isolate, &interceptor_call_count))); |
12772 LocalContext context; | 12905 LocalContext context; |
12773 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 12906 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
12774 GenerateSomeGarbage(); | 12907 GenerateSomeGarbage(); |
12775 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 12908 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
12776 CompileRun( | 12909 CompileRun( |
12777 "o.foo = 17;" | 12910 "o.foo = 17;" |
12778 "var receiver = {};" | 12911 "var receiver = {};" |
12779 "receiver.__proto__ = o;" | 12912 "receiver.__proto__ = o;" |
12780 "var result = 0;" | 12913 "var result = 0;" |
12781 "var saved_result = 0;" | 12914 "var saved_result = 0;" |
(...skipping 16 matching lines...) Expand all Loading... |
12798 v8::HandleScope scope(isolate); | 12931 v8::HandleScope scope(isolate); |
12799 v8::Handle<v8::FunctionTemplate> fun_templ = | 12932 v8::Handle<v8::FunctionTemplate> fun_templ = |
12800 v8::FunctionTemplate::New(isolate); | 12933 v8::FunctionTemplate::New(isolate); |
12801 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( | 12934 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
12802 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), | 12935 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), |
12803 v8::Signature::New(isolate, fun_templ)); | 12936 v8::Signature::New(isolate, fun_templ)); |
12804 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 12937 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
12805 proto_templ->Set(v8_str("method"), method_templ); | 12938 proto_templ->Set(v8_str("method"), method_templ); |
12806 fun_templ->SetHiddenPrototype(true); | 12939 fun_templ->SetHiddenPrototype(true); |
12807 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 12940 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
12808 templ->SetNamedPropertyHandler( | 12941 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
12809 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, | 12942 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, |
12810 v8::External::New(isolate, &interceptor_call_count)); | 12943 v8::External::New(isolate, &interceptor_call_count))); |
12811 LocalContext context; | 12944 LocalContext context; |
12812 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 12945 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
12813 GenerateSomeGarbage(); | 12946 GenerateSomeGarbage(); |
12814 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 12947 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
12815 CompileRun( | 12948 CompileRun( |
12816 "o.foo = 17;" | 12949 "o.foo = 17;" |
12817 "var receiver = {};" | 12950 "var receiver = {};" |
12818 "receiver.__proto__ = o;" | 12951 "receiver.__proto__ = o;" |
12819 "var result = 0;" | 12952 "var result = 0;" |
12820 "var saved_result = 0;" | 12953 "var saved_result = 0;" |
(...skipping 16 matching lines...) Expand all Loading... |
12837 v8::HandleScope scope(isolate); | 12970 v8::HandleScope scope(isolate); |
12838 v8::Handle<v8::FunctionTemplate> fun_templ = | 12971 v8::Handle<v8::FunctionTemplate> fun_templ = |
12839 v8::FunctionTemplate::New(isolate); | 12972 v8::FunctionTemplate::New(isolate); |
12840 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( | 12973 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
12841 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), | 12974 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), |
12842 v8::Signature::New(isolate, fun_templ)); | 12975 v8::Signature::New(isolate, fun_templ)); |
12843 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 12976 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
12844 proto_templ->Set(v8_str("method"), method_templ); | 12977 proto_templ->Set(v8_str("method"), method_templ); |
12845 fun_templ->SetHiddenPrototype(true); | 12978 fun_templ->SetHiddenPrototype(true); |
12846 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 12979 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
12847 templ->SetNamedPropertyHandler( | 12980 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
12848 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, | 12981 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, |
12849 v8::External::New(isolate, &interceptor_call_count)); | 12982 v8::External::New(isolate, &interceptor_call_count))); |
12850 LocalContext context; | 12983 LocalContext context; |
12851 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 12984 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
12852 GenerateSomeGarbage(); | 12985 GenerateSomeGarbage(); |
12853 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 12986 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
12854 v8::TryCatch try_catch; | 12987 v8::TryCatch try_catch; |
12855 CompileRun( | 12988 CompileRun( |
12856 "o.foo = 17;" | 12989 "o.foo = 17;" |
12857 "var receiver = {};" | 12990 "var receiver = {};" |
12858 "receiver.__proto__ = o;" | 12991 "receiver.__proto__ = o;" |
12859 "var result = 0;" | 12992 "var result = 0;" |
(...skipping 20 matching lines...) Expand all Loading... |
12880 v8::HandleScope scope(isolate); | 13013 v8::HandleScope scope(isolate); |
12881 v8::Handle<v8::FunctionTemplate> fun_templ = | 13014 v8::Handle<v8::FunctionTemplate> fun_templ = |
12882 v8::FunctionTemplate::New(isolate); | 13015 v8::FunctionTemplate::New(isolate); |
12883 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( | 13016 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
12884 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), | 13017 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), |
12885 v8::Signature::New(isolate, fun_templ)); | 13018 v8::Signature::New(isolate, fun_templ)); |
12886 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 13019 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
12887 proto_templ->Set(v8_str("method"), method_templ); | 13020 proto_templ->Set(v8_str("method"), method_templ); |
12888 fun_templ->SetHiddenPrototype(true); | 13021 fun_templ->SetHiddenPrototype(true); |
12889 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 13022 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
12890 templ->SetNamedPropertyHandler( | 13023 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
12891 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, | 13024 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, |
12892 v8::External::New(isolate, &interceptor_call_count)); | 13025 v8::External::New(isolate, &interceptor_call_count))); |
12893 LocalContext context; | 13026 LocalContext context; |
12894 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 13027 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
12895 GenerateSomeGarbage(); | 13028 GenerateSomeGarbage(); |
12896 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 13029 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
12897 v8::TryCatch try_catch; | 13030 v8::TryCatch try_catch; |
12898 CompileRun( | 13031 CompileRun( |
12899 "o.foo = 17;" | 13032 "o.foo = 17;" |
12900 "var receiver = {};" | 13033 "var receiver = {};" |
12901 "receiver.__proto__ = o;" | 13034 "receiver.__proto__ = o;" |
12902 "var result = 0;" | 13035 "var result = 0;" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13082 CHECK(try_catch.HasCaught()); | 13215 CHECK(try_catch.HasCaught()); |
13083 CHECK_EQ(v8_str("TypeError: Illegal invocation"), | 13216 CHECK_EQ(v8_str("TypeError: Illegal invocation"), |
13084 try_catch.Exception()->ToString(isolate)); | 13217 try_catch.Exception()->ToString(isolate)); |
13085 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 13218 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); |
13086 } | 13219 } |
13087 | 13220 |
13088 | 13221 |
13089 v8::Handle<Value> keyed_call_ic_function; | 13222 v8::Handle<Value> keyed_call_ic_function; |
13090 | 13223 |
13091 static void InterceptorKeyedCallICGetter( | 13224 static void InterceptorKeyedCallICGetter( |
13092 Local<String> name, | 13225 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
13093 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
13094 ApiTestFuzzer::Fuzz(); | 13226 ApiTestFuzzer::Fuzz(); |
13095 if (v8_str("x")->Equals(name)) { | 13227 if (v8_str("x")->Equals(name)) { |
13096 info.GetReturnValue().Set(keyed_call_ic_function); | 13228 info.GetReturnValue().Set(keyed_call_ic_function); |
13097 } | 13229 } |
13098 } | 13230 } |
13099 | 13231 |
13100 | 13232 |
13101 // Test the case when we stored cacheable lookup into | 13233 // Test the case when we stored cacheable lookup into |
13102 // a stub, but the function name changed (to another cacheable function). | 13234 // a stub, but the function name changed (to another cacheable function). |
13103 THREADED_TEST(InterceptorKeyedCallICKeyChange1) { | 13235 THREADED_TEST(InterceptorKeyedCallICKeyChange1) { |
13104 v8::Isolate* isolate = CcTest::isolate(); | 13236 v8::Isolate* isolate = CcTest::isolate(); |
13105 v8::HandleScope scope(isolate); | 13237 v8::HandleScope scope(isolate); |
13106 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 13238 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
13107 templ->SetNamedPropertyHandler(NoBlockGetterX); | 13239 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(NoBlockGetterX)); |
13108 LocalContext context; | 13240 LocalContext context; |
13109 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 13241 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
13110 CompileRun( | 13242 CompileRun( |
13111 "proto = new Object();" | 13243 "proto = new Object();" |
13112 "proto.y = function(x) { return x + 1; };" | 13244 "proto.y = function(x) { return x + 1; };" |
13113 "proto.z = function(x) { return x - 1; };" | 13245 "proto.z = function(x) { return x - 1; };" |
13114 "o.__proto__ = proto;" | 13246 "o.__proto__ = proto;" |
13115 "var result = 0;" | 13247 "var result = 0;" |
13116 "var method = 'y';" | 13248 "var method = 'y';" |
13117 "for (var i = 0; i < 10; i++) {" | 13249 "for (var i = 0; i < 10; i++) {" |
13118 " if (i == 5) { method = 'z'; };" | 13250 " if (i == 5) { method = 'z'; };" |
13119 " result += o[method](41);" | 13251 " result += o[method](41);" |
13120 "}"); | 13252 "}"); |
13121 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); | 13253 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); |
13122 } | 13254 } |
13123 | 13255 |
13124 | 13256 |
13125 // Test the case when we stored cacheable lookup into | 13257 // Test the case when we stored cacheable lookup into |
13126 // a stub, but the function name changed (and the new function is present | 13258 // a stub, but the function name changed (and the new function is present |
13127 // both before and after the interceptor in the prototype chain). | 13259 // both before and after the interceptor in the prototype chain). |
13128 THREADED_TEST(InterceptorKeyedCallICKeyChange2) { | 13260 THREADED_TEST(InterceptorKeyedCallICKeyChange2) { |
13129 v8::Isolate* isolate = CcTest::isolate(); | 13261 v8::Isolate* isolate = CcTest::isolate(); |
13130 v8::HandleScope scope(isolate); | 13262 v8::HandleScope scope(isolate); |
13131 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 13263 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
13132 templ->SetNamedPropertyHandler(InterceptorKeyedCallICGetter); | 13264 templ->SetHandler( |
| 13265 v8::NamedPropertyHandlerConfiguration(InterceptorKeyedCallICGetter)); |
13133 LocalContext context; | 13266 LocalContext context; |
13134 context->Global()->Set(v8_str("proto1"), templ->NewInstance()); | 13267 context->Global()->Set(v8_str("proto1"), templ->NewInstance()); |
13135 keyed_call_ic_function = | 13268 keyed_call_ic_function = |
13136 v8_compile("function f(x) { return x - 1; }; f")->Run(); | 13269 v8_compile("function f(x) { return x - 1; }; f")->Run(); |
13137 CompileRun( | 13270 CompileRun( |
13138 "o = new Object();" | 13271 "o = new Object();" |
13139 "proto2 = new Object();" | 13272 "proto2 = new Object();" |
13140 "o.y = function(x) { return x + 1; };" | 13273 "o.y = function(x) { return x + 1; };" |
13141 "proto2.y = function(x) { return x + 2; };" | 13274 "proto2.y = function(x) { return x + 2; };" |
13142 "o.__proto__ = proto1;" | 13275 "o.__proto__ = proto1;" |
13143 "proto1.__proto__ = proto2;" | 13276 "proto1.__proto__ = proto2;" |
13144 "var result = 0;" | 13277 "var result = 0;" |
13145 "var method = 'x';" | 13278 "var method = 'x';" |
13146 "for (var i = 0; i < 10; i++) {" | 13279 "for (var i = 0; i < 10; i++) {" |
13147 " if (i == 5) { method = 'y'; };" | 13280 " if (i == 5) { method = 'y'; };" |
13148 " result += o[method](41);" | 13281 " result += o[method](41);" |
13149 "}"); | 13282 "}"); |
13150 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); | 13283 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); |
13151 } | 13284 } |
13152 | 13285 |
13153 | 13286 |
13154 // Same as InterceptorKeyedCallICKeyChange1 only the cacheable function sit | 13287 // Same as InterceptorKeyedCallICKeyChange1 only the cacheable function sit |
13155 // on the global object. | 13288 // on the global object. |
13156 THREADED_TEST(InterceptorKeyedCallICKeyChangeOnGlobal) { | 13289 THREADED_TEST(InterceptorKeyedCallICKeyChangeOnGlobal) { |
13157 v8::Isolate* isolate = CcTest::isolate(); | 13290 v8::Isolate* isolate = CcTest::isolate(); |
13158 v8::HandleScope scope(isolate); | 13291 v8::HandleScope scope(isolate); |
13159 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 13292 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
13160 templ->SetNamedPropertyHandler(NoBlockGetterX); | 13293 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(NoBlockGetterX)); |
13161 LocalContext context; | 13294 LocalContext context; |
13162 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 13295 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
13163 CompileRun( | 13296 CompileRun( |
13164 "function inc(x) { return x + 1; };" | 13297 "function inc(x) { return x + 1; };" |
13165 "inc(1);" | 13298 "inc(1);" |
13166 "function dec(x) { return x - 1; };" | 13299 "function dec(x) { return x - 1; };" |
13167 "dec(1);" | 13300 "dec(1);" |
13168 "o.__proto__ = this;" | 13301 "o.__proto__ = this;" |
13169 "this.__proto__.x = inc;" | 13302 "this.__proto__.x = inc;" |
13170 "this.__proto__.y = dec;" | 13303 "this.__proto__.y = dec;" |
13171 "var result = 0;" | 13304 "var result = 0;" |
13172 "var method = 'x';" | 13305 "var method = 'x';" |
13173 "for (var i = 0; i < 10; i++) {" | 13306 "for (var i = 0; i < 10; i++) {" |
13174 " if (i == 5) { method = 'y'; };" | 13307 " if (i == 5) { method = 'y'; };" |
13175 " result += o[method](41);" | 13308 " result += o[method](41);" |
13176 "}"); | 13309 "}"); |
13177 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); | 13310 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); |
13178 } | 13311 } |
13179 | 13312 |
13180 | 13313 |
13181 // Test the case when actual function to call sits on global object. | 13314 // Test the case when actual function to call sits on global object. |
13182 THREADED_TEST(InterceptorKeyedCallICFromGlobal) { | 13315 THREADED_TEST(InterceptorKeyedCallICFromGlobal) { |
13183 v8::Isolate* isolate = CcTest::isolate(); | 13316 v8::Isolate* isolate = CcTest::isolate(); |
13184 v8::HandleScope scope(isolate); | 13317 v8::HandleScope scope(isolate); |
13185 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); | 13318 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); |
13186 templ_o->SetNamedPropertyHandler(NoBlockGetterX); | 13319 templ_o->SetHandler(v8::NamedPropertyHandlerConfiguration(NoBlockGetterX)); |
13187 LocalContext context; | 13320 LocalContext context; |
13188 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); | 13321 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); |
13189 | 13322 |
13190 CompileRun( | 13323 CompileRun( |
13191 "function len(x) { return x.length; };" | 13324 "function len(x) { return x.length; };" |
13192 "o.__proto__ = this;" | 13325 "o.__proto__ = this;" |
13193 "var m = 'parseFloat';" | 13326 "var m = 'parseFloat';" |
13194 "var result = 0;" | 13327 "var result = 0;" |
13195 "for (var i = 0; i < 10; i++) {" | 13328 "for (var i = 0; i < 10; i++) {" |
13196 " if (i == 5) {" | 13329 " if (i == 5) {" |
13197 " m = 'len';" | 13330 " m = 'len';" |
13198 " saved_result = result;" | 13331 " saved_result = result;" |
13199 " };" | 13332 " };" |
13200 " result = o[m]('239');" | 13333 " result = o[m]('239');" |
13201 "}"); | 13334 "}"); |
13202 CHECK_EQ(3, context->Global()->Get(v8_str("result"))->Int32Value()); | 13335 CHECK_EQ(3, context->Global()->Get(v8_str("result"))->Int32Value()); |
13203 CHECK_EQ(239, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 13336 CHECK_EQ(239, context->Global()->Get(v8_str("saved_result"))->Int32Value()); |
13204 } | 13337 } |
13205 | 13338 |
13206 | 13339 |
13207 // Test the map transition before the interceptor. | 13340 // Test the map transition before the interceptor. |
13208 THREADED_TEST(InterceptorKeyedCallICMapChangeBefore) { | 13341 THREADED_TEST(InterceptorKeyedCallICMapChangeBefore) { |
13209 v8::Isolate* isolate = CcTest::isolate(); | 13342 v8::Isolate* isolate = CcTest::isolate(); |
13210 v8::HandleScope scope(isolate); | 13343 v8::HandleScope scope(isolate); |
13211 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); | 13344 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); |
13212 templ_o->SetNamedPropertyHandler(NoBlockGetterX); | 13345 templ_o->SetHandler(v8::NamedPropertyHandlerConfiguration(NoBlockGetterX)); |
13213 LocalContext context; | 13346 LocalContext context; |
13214 context->Global()->Set(v8_str("proto"), templ_o->NewInstance()); | 13347 context->Global()->Set(v8_str("proto"), templ_o->NewInstance()); |
13215 | 13348 |
13216 CompileRun( | 13349 CompileRun( |
13217 "var o = new Object();" | 13350 "var o = new Object();" |
13218 "o.__proto__ = proto;" | 13351 "o.__proto__ = proto;" |
13219 "o.method = function(x) { return x + 1; };" | 13352 "o.method = function(x) { return x + 1; };" |
13220 "var m = 'method';" | 13353 "var m = 'method';" |
13221 "var result = 0;" | 13354 "var result = 0;" |
13222 "for (var i = 0; i < 10; i++) {" | 13355 "for (var i = 0; i < 10; i++) {" |
13223 " if (i == 5) { o.method = function(x) { return x - 1; }; };" | 13356 " if (i == 5) { o.method = function(x) { return x - 1; }; };" |
13224 " result += o[m](41);" | 13357 " result += o[m](41);" |
13225 "}"); | 13358 "}"); |
13226 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); | 13359 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); |
13227 } | 13360 } |
13228 | 13361 |
13229 | 13362 |
13230 // Test the map transition after the interceptor. | 13363 // Test the map transition after the interceptor. |
13231 THREADED_TEST(InterceptorKeyedCallICMapChangeAfter) { | 13364 THREADED_TEST(InterceptorKeyedCallICMapChangeAfter) { |
13232 v8::Isolate* isolate = CcTest::isolate(); | 13365 v8::Isolate* isolate = CcTest::isolate(); |
13233 v8::HandleScope scope(isolate); | 13366 v8::HandleScope scope(isolate); |
13234 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); | 13367 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); |
13235 templ_o->SetNamedPropertyHandler(NoBlockGetterX); | 13368 templ_o->SetHandler(v8::NamedPropertyHandlerConfiguration(NoBlockGetterX)); |
13236 LocalContext context; | 13369 LocalContext context; |
13237 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); | 13370 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); |
13238 | 13371 |
13239 CompileRun( | 13372 CompileRun( |
13240 "var proto = new Object();" | 13373 "var proto = new Object();" |
13241 "o.__proto__ = proto;" | 13374 "o.__proto__ = proto;" |
13242 "proto.method = function(x) { return x + 1; };" | 13375 "proto.method = function(x) { return x + 1; };" |
13243 "var m = 'method';" | 13376 "var m = 'method';" |
13244 "var result = 0;" | 13377 "var result = 0;" |
13245 "for (var i = 0; i < 10; i++) {" | 13378 "for (var i = 0; i < 10; i++) {" |
13246 " if (i == 5) { proto.method = function(x) { return x - 1; }; };" | 13379 " if (i == 5) { proto.method = function(x) { return x - 1; }; };" |
13247 " result += o[m](41);" | 13380 " result += o[m](41);" |
13248 "}"); | 13381 "}"); |
13249 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); | 13382 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); |
13250 } | 13383 } |
13251 | 13384 |
13252 | 13385 |
13253 static int interceptor_call_count = 0; | 13386 static int interceptor_call_count = 0; |
13254 | 13387 |
13255 static void InterceptorICRefErrorGetter( | 13388 static void InterceptorICRefErrorGetter( |
13256 Local<String> name, | 13389 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
13257 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
13258 ApiTestFuzzer::Fuzz(); | 13390 ApiTestFuzzer::Fuzz(); |
13259 if (v8_str("x")->Equals(name) && interceptor_call_count++ < 20) { | 13391 if (v8_str("x")->Equals(name) && interceptor_call_count++ < 20) { |
13260 info.GetReturnValue().Set(call_ic_function2); | 13392 info.GetReturnValue().Set(call_ic_function2); |
13261 } | 13393 } |
13262 } | 13394 } |
13263 | 13395 |
13264 | 13396 |
13265 // This test should hit load and call ICs for the interceptor case. | 13397 // This test should hit load and call ICs for the interceptor case. |
13266 // Once in a while, the interceptor will reply that a property was not | 13398 // Once in a while, the interceptor will reply that a property was not |
13267 // found in which case we should get a reference error. | 13399 // found in which case we should get a reference error. |
13268 THREADED_TEST(InterceptorICReferenceErrors) { | 13400 THREADED_TEST(InterceptorICReferenceErrors) { |
13269 v8::Isolate* isolate = CcTest::isolate(); | 13401 v8::Isolate* isolate = CcTest::isolate(); |
13270 v8::HandleScope scope(isolate); | 13402 v8::HandleScope scope(isolate); |
13271 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 13403 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
13272 templ->SetNamedPropertyHandler(InterceptorICRefErrorGetter); | 13404 templ->SetHandler( |
| 13405 v8::NamedPropertyHandlerConfiguration(InterceptorICRefErrorGetter)); |
13273 LocalContext context(0, templ, v8::Handle<Value>()); | 13406 LocalContext context(0, templ, v8::Handle<Value>()); |
13274 call_ic_function2 = v8_compile("function h(x) { return x; }; h")->Run(); | 13407 call_ic_function2 = v8_compile("function h(x) { return x; }; h")->Run(); |
13275 v8::Handle<Value> value = CompileRun( | 13408 v8::Handle<Value> value = CompileRun( |
13276 "function f() {" | 13409 "function f() {" |
13277 " for (var i = 0; i < 1000; i++) {" | 13410 " for (var i = 0; i < 1000; i++) {" |
13278 " try { x; } catch(e) { return true; }" | 13411 " try { x; } catch(e) { return true; }" |
13279 " }" | 13412 " }" |
13280 " return false;" | 13413 " return false;" |
13281 "};" | 13414 "};" |
13282 "f();"); | 13415 "f();"); |
13283 CHECK_EQ(true, value->BooleanValue()); | 13416 CHECK_EQ(true, value->BooleanValue()); |
13284 interceptor_call_count = 0; | 13417 interceptor_call_count = 0; |
13285 value = CompileRun( | 13418 value = CompileRun( |
13286 "function g() {" | 13419 "function g() {" |
13287 " for (var i = 0; i < 1000; i++) {" | 13420 " for (var i = 0; i < 1000; i++) {" |
13288 " try { x(42); } catch(e) { return true; }" | 13421 " try { x(42); } catch(e) { return true; }" |
13289 " }" | 13422 " }" |
13290 " return false;" | 13423 " return false;" |
13291 "};" | 13424 "};" |
13292 "g();"); | 13425 "g();"); |
13293 CHECK_EQ(true, value->BooleanValue()); | 13426 CHECK_EQ(true, value->BooleanValue()); |
13294 } | 13427 } |
13295 | 13428 |
13296 | 13429 |
13297 static int interceptor_ic_exception_get_count = 0; | 13430 static int interceptor_ic_exception_get_count = 0; |
13298 | 13431 |
13299 static void InterceptorICExceptionGetter( | 13432 static void InterceptorICExceptionGetter( |
13300 Local<String> name, | 13433 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
13301 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
13302 ApiTestFuzzer::Fuzz(); | 13434 ApiTestFuzzer::Fuzz(); |
13303 if (v8_str("x")->Equals(name) && ++interceptor_ic_exception_get_count < 20) { | 13435 if (v8_str("x")->Equals(name) && ++interceptor_ic_exception_get_count < 20) { |
13304 info.GetReturnValue().Set(call_ic_function3); | 13436 info.GetReturnValue().Set(call_ic_function3); |
13305 } | 13437 } |
13306 if (interceptor_ic_exception_get_count == 20) { | 13438 if (interceptor_ic_exception_get_count == 20) { |
13307 info.GetIsolate()->ThrowException(v8_num(42)); | 13439 info.GetIsolate()->ThrowException(v8_num(42)); |
13308 return; | 13440 return; |
13309 } | 13441 } |
13310 } | 13442 } |
13311 | 13443 |
13312 | 13444 |
13313 // Test interceptor load/call IC where the interceptor throws an | 13445 // Test interceptor load/call IC where the interceptor throws an |
13314 // exception once in a while. | 13446 // exception once in a while. |
13315 THREADED_TEST(InterceptorICGetterExceptions) { | 13447 THREADED_TEST(InterceptorICGetterExceptions) { |
13316 interceptor_ic_exception_get_count = 0; | 13448 interceptor_ic_exception_get_count = 0; |
13317 v8::Isolate* isolate = CcTest::isolate(); | 13449 v8::Isolate* isolate = CcTest::isolate(); |
13318 v8::HandleScope scope(isolate); | 13450 v8::HandleScope scope(isolate); |
13319 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 13451 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
13320 templ->SetNamedPropertyHandler(InterceptorICExceptionGetter); | 13452 templ->SetHandler( |
| 13453 v8::NamedPropertyHandlerConfiguration(InterceptorICExceptionGetter)); |
13321 LocalContext context(0, templ, v8::Handle<Value>()); | 13454 LocalContext context(0, templ, v8::Handle<Value>()); |
13322 call_ic_function3 = v8_compile("function h(x) { return x; }; h")->Run(); | 13455 call_ic_function3 = v8_compile("function h(x) { return x; }; h")->Run(); |
13323 v8::Handle<Value> value = CompileRun( | 13456 v8::Handle<Value> value = CompileRun( |
13324 "function f() {" | 13457 "function f() {" |
13325 " for (var i = 0; i < 100; i++) {" | 13458 " for (var i = 0; i < 100; i++) {" |
13326 " try { x; } catch(e) { return true; }" | 13459 " try { x; } catch(e) { return true; }" |
13327 " }" | 13460 " }" |
13328 " return false;" | 13461 " return false;" |
13329 "};" | 13462 "};" |
13330 "f();"); | 13463 "f();"); |
13331 CHECK_EQ(true, value->BooleanValue()); | 13464 CHECK_EQ(true, value->BooleanValue()); |
13332 interceptor_ic_exception_get_count = 0; | 13465 interceptor_ic_exception_get_count = 0; |
13333 value = CompileRun( | 13466 value = CompileRun( |
13334 "function f() {" | 13467 "function f() {" |
13335 " for (var i = 0; i < 100; i++) {" | 13468 " for (var i = 0; i < 100; i++) {" |
13336 " try { x(42); } catch(e) { return true; }" | 13469 " try { x(42); } catch(e) { return true; }" |
13337 " }" | 13470 " }" |
13338 " return false;" | 13471 " return false;" |
13339 "};" | 13472 "};" |
13340 "f();"); | 13473 "f();"); |
13341 CHECK_EQ(true, value->BooleanValue()); | 13474 CHECK_EQ(true, value->BooleanValue()); |
13342 } | 13475 } |
13343 | 13476 |
13344 | 13477 |
13345 static int interceptor_ic_exception_set_count = 0; | 13478 static int interceptor_ic_exception_set_count = 0; |
13346 | 13479 |
13347 static void InterceptorICExceptionSetter( | 13480 static void InterceptorICExceptionSetter( |
13348 Local<String> key, | 13481 Local<Name> key, Local<Value> value, |
13349 Local<Value> value, | 13482 const v8::PropertyCallbackInfo<v8::Value>& info) { |
13350 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
13351 ApiTestFuzzer::Fuzz(); | 13483 ApiTestFuzzer::Fuzz(); |
13352 if (++interceptor_ic_exception_set_count > 20) { | 13484 if (++interceptor_ic_exception_set_count > 20) { |
13353 info.GetIsolate()->ThrowException(v8_num(42)); | 13485 info.GetIsolate()->ThrowException(v8_num(42)); |
13354 } | 13486 } |
13355 } | 13487 } |
13356 | 13488 |
13357 | 13489 |
13358 // Test interceptor store IC where the interceptor throws an exception | 13490 // Test interceptor store IC where the interceptor throws an exception |
13359 // once in a while. | 13491 // once in a while. |
13360 THREADED_TEST(InterceptorICSetterExceptions) { | 13492 THREADED_TEST(InterceptorICSetterExceptions) { |
13361 interceptor_ic_exception_set_count = 0; | 13493 interceptor_ic_exception_set_count = 0; |
13362 v8::Isolate* isolate = CcTest::isolate(); | 13494 v8::Isolate* isolate = CcTest::isolate(); |
13363 v8::HandleScope scope(isolate); | 13495 v8::HandleScope scope(isolate); |
13364 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 13496 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
13365 templ->SetNamedPropertyHandler(0, InterceptorICExceptionSetter); | 13497 templ->SetHandler( |
| 13498 v8::NamedPropertyHandlerConfiguration(0, InterceptorICExceptionSetter)); |
13366 LocalContext context(0, templ, v8::Handle<Value>()); | 13499 LocalContext context(0, templ, v8::Handle<Value>()); |
13367 v8::Handle<Value> value = CompileRun( | 13500 v8::Handle<Value> value = CompileRun( |
13368 "function f() {" | 13501 "function f() {" |
13369 " for (var i = 0; i < 100; i++) {" | 13502 " for (var i = 0; i < 100; i++) {" |
13370 " try { x = 42; } catch(e) { return true; }" | 13503 " try { x = 42; } catch(e) { return true; }" |
13371 " }" | 13504 " }" |
13372 " return false;" | 13505 " return false;" |
13373 "};" | 13506 "};" |
13374 "f();"); | 13507 "f();"); |
13375 CHECK_EQ(true, value->BooleanValue()); | 13508 CHECK_EQ(true, value->BooleanValue()); |
13376 } | 13509 } |
13377 | 13510 |
13378 | 13511 |
13379 // Test that we ignore null interceptors. | 13512 // Test that we ignore null interceptors. |
13380 THREADED_TEST(NullNamedInterceptor) { | 13513 THREADED_TEST(NullNamedInterceptor) { |
13381 v8::Isolate* isolate = CcTest::isolate(); | 13514 v8::Isolate* isolate = CcTest::isolate(); |
13382 v8::HandleScope scope(isolate); | 13515 v8::HandleScope scope(isolate); |
13383 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 13516 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
13384 templ->SetNamedPropertyHandler( | 13517 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
13385 static_cast<v8::NamedPropertyGetterCallback>(0)); | 13518 static_cast<v8::GenericNamedPropertyGetterCallback>(0))); |
13386 LocalContext context; | 13519 LocalContext context; |
13387 templ->Set(CcTest::isolate(), "x", v8_num(42)); | 13520 templ->Set(CcTest::isolate(), "x", v8_num(42)); |
13388 v8::Handle<v8::Object> obj = templ->NewInstance(); | 13521 v8::Handle<v8::Object> obj = templ->NewInstance(); |
13389 context->Global()->Set(v8_str("obj"), obj); | 13522 context->Global()->Set(v8_str("obj"), obj); |
13390 v8::Handle<Value> value = CompileRun("obj.x"); | 13523 v8::Handle<Value> value = CompileRun("obj.x"); |
13391 CHECK(value->IsInt32()); | 13524 CHECK(value->IsInt32()); |
13392 CHECK_EQ(42, value->Int32Value()); | 13525 CHECK_EQ(42, value->Int32Value()); |
13393 } | 13526 } |
13394 | 13527 |
13395 | 13528 |
(...skipping 11 matching lines...) Expand all Loading... |
13407 v8::Handle<Value> value = CompileRun("obj[42]"); | 13540 v8::Handle<Value> value = CompileRun("obj[42]"); |
13408 CHECK(value->IsInt32()); | 13541 CHECK(value->IsInt32()); |
13409 CHECK_EQ(42, value->Int32Value()); | 13542 CHECK_EQ(42, value->Int32Value()); |
13410 } | 13543 } |
13411 | 13544 |
13412 | 13545 |
13413 THREADED_TEST(NamedPropertyHandlerGetterAttributes) { | 13546 THREADED_TEST(NamedPropertyHandlerGetterAttributes) { |
13414 v8::Isolate* isolate = CcTest::isolate(); | 13547 v8::Isolate* isolate = CcTest::isolate(); |
13415 v8::HandleScope scope(isolate); | 13548 v8::HandleScope scope(isolate); |
13416 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); | 13549 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); |
13417 templ->InstanceTemplate()->SetNamedPropertyHandler(InterceptorLoadXICGetter); | 13550 templ->InstanceTemplate()->SetHandler( |
| 13551 v8::NamedPropertyHandlerConfiguration(InterceptorLoadXICGetter)); |
13418 LocalContext env; | 13552 LocalContext env; |
13419 env->Global()->Set(v8_str("obj"), | 13553 env->Global()->Set(v8_str("obj"), |
13420 templ->GetFunction()->NewInstance()); | 13554 templ->GetFunction()->NewInstance()); |
13421 ExpectTrue("obj.x === 42"); | 13555 ExpectTrue("obj.x === 42"); |
13422 ExpectTrue("!obj.propertyIsEnumerable('x')"); | 13556 ExpectTrue("!obj.propertyIsEnumerable('x')"); |
13423 } | 13557 } |
13424 | 13558 |
13425 | 13559 |
13426 static void ThrowingGetter(Local<String> name, | 13560 static void ThrowingGetter(Local<String> name, |
13427 const v8::PropertyCallbackInfo<v8::Value>& info) { | 13561 const v8::PropertyCallbackInfo<v8::Value>& info) { |
(...skipping 2447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15875 } | 16009 } |
15876 info.GetReturnValue().Set(3); | 16010 info.GetReturnValue().Set(3); |
15877 } | 16011 } |
15878 | 16012 |
15879 static void ForceSetSetter(v8::Local<v8::String> name, | 16013 static void ForceSetSetter(v8::Local<v8::String> name, |
15880 v8::Local<v8::Value> value, | 16014 v8::Local<v8::Value> value, |
15881 const v8::PropertyCallbackInfo<void>& info) { | 16015 const v8::PropertyCallbackInfo<void>& info) { |
15882 force_set_set_count++; | 16016 force_set_set_count++; |
15883 } | 16017 } |
15884 | 16018 |
| 16019 static void ForceSetInterceptGetter( |
| 16020 v8::Local<v8::Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 16021 CHECK(name->IsString()); |
| 16022 ForceSetGetter(Local<String>::Cast(name), info); |
| 16023 } |
| 16024 |
15885 static void ForceSetInterceptSetter( | 16025 static void ForceSetInterceptSetter( |
15886 v8::Local<v8::String> name, | 16026 v8::Local<v8::Name> name, v8::Local<v8::Value> value, |
15887 v8::Local<v8::Value> value, | |
15888 const v8::PropertyCallbackInfo<v8::Value>& info) { | 16027 const v8::PropertyCallbackInfo<v8::Value>& info) { |
15889 force_set_set_count++; | 16028 force_set_set_count++; |
15890 info.GetReturnValue().SetUndefined(); | 16029 info.GetReturnValue().SetUndefined(); |
15891 } | 16030 } |
15892 | 16031 |
15893 | 16032 |
15894 TEST(ForceSet) { | 16033 TEST(ForceSet) { |
15895 force_set_get_count = 0; | 16034 force_set_get_count = 0; |
15896 force_set_set_count = 0; | 16035 force_set_set_count = 0; |
15897 pass_on_get = false; | 16036 pass_on_get = false; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15937 | 16076 |
15938 | 16077 |
15939 TEST(ForceSetWithInterceptor) { | 16078 TEST(ForceSetWithInterceptor) { |
15940 force_set_get_count = 0; | 16079 force_set_get_count = 0; |
15941 force_set_set_count = 0; | 16080 force_set_set_count = 0; |
15942 pass_on_get = false; | 16081 pass_on_get = false; |
15943 | 16082 |
15944 v8::Isolate* isolate = CcTest::isolate(); | 16083 v8::Isolate* isolate = CcTest::isolate(); |
15945 v8::HandleScope scope(isolate); | 16084 v8::HandleScope scope(isolate); |
15946 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); | 16085 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); |
15947 templ->SetNamedPropertyHandler(ForceSetGetter, ForceSetInterceptSetter); | 16086 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
| 16087 ForceSetInterceptGetter, ForceSetInterceptSetter)); |
15948 LocalContext context(NULL, templ); | 16088 LocalContext context(NULL, templ); |
15949 v8::Handle<v8::Object> global = context->Global(); | 16089 v8::Handle<v8::Object> global = context->Global(); |
15950 | 16090 |
15951 v8::Handle<v8::String> some_property = | 16091 v8::Handle<v8::String> some_property = |
15952 v8::String::NewFromUtf8(isolate, "a"); | 16092 v8::String::NewFromUtf8(isolate, "a"); |
15953 CHECK_EQ(0, force_set_set_count); | 16093 CHECK_EQ(0, force_set_set_count); |
15954 CHECK_EQ(0, force_set_get_count); | 16094 CHECK_EQ(0, force_set_get_count); |
15955 CHECK_EQ(3, global->Get(some_property)->Int32Value()); | 16095 CHECK_EQ(3, global->Get(some_property)->Int32Value()); |
15956 // Setting the property shouldn't override it, just call the setter | 16096 // Setting the property shouldn't override it, just call the setter |
15957 // which in this case does nothing. | 16097 // which in this case does nothing. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16005 CHECK(global->ForceDelete(simple_property)); | 16145 CHECK(global->ForceDelete(simple_property)); |
16006 CHECK(global->Get(simple_property)->IsUndefined()); | 16146 CHECK(global->Get(simple_property)->IsUndefined()); |
16007 } | 16147 } |
16008 | 16148 |
16009 | 16149 |
16010 static int force_delete_interceptor_count = 0; | 16150 static int force_delete_interceptor_count = 0; |
16011 static bool pass_on_delete = false; | 16151 static bool pass_on_delete = false; |
16012 | 16152 |
16013 | 16153 |
16014 static void ForceDeleteDeleter( | 16154 static void ForceDeleteDeleter( |
16015 v8::Local<v8::String> name, | 16155 v8::Local<v8::Name> name, |
16016 const v8::PropertyCallbackInfo<v8::Boolean>& info) { | 16156 const v8::PropertyCallbackInfo<v8::Boolean>& info) { |
16017 force_delete_interceptor_count++; | 16157 force_delete_interceptor_count++; |
16018 if (pass_on_delete) return; | 16158 if (pass_on_delete) return; |
16019 info.GetReturnValue().Set(true); | 16159 info.GetReturnValue().Set(true); |
16020 } | 16160 } |
16021 | 16161 |
16022 | 16162 |
16023 THREADED_TEST(ForceDeleteWithInterceptor) { | 16163 THREADED_TEST(ForceDeleteWithInterceptor) { |
16024 force_delete_interceptor_count = 0; | 16164 force_delete_interceptor_count = 0; |
16025 pass_on_delete = false; | 16165 pass_on_delete = false; |
16026 | 16166 |
16027 v8::Isolate* isolate = CcTest::isolate(); | 16167 v8::Isolate* isolate = CcTest::isolate(); |
16028 v8::HandleScope scope(isolate); | 16168 v8::HandleScope scope(isolate); |
16029 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); | 16169 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); |
16030 templ->SetNamedPropertyHandler(0, 0, 0, ForceDeleteDeleter); | 16170 templ->SetHandler( |
| 16171 v8::NamedPropertyHandlerConfiguration(0, 0, 0, ForceDeleteDeleter)); |
16031 LocalContext context(NULL, templ); | 16172 LocalContext context(NULL, templ); |
16032 v8::Handle<v8::Object> global = context->Global(); | 16173 v8::Handle<v8::Object> global = context->Global(); |
16033 | 16174 |
16034 v8::Handle<v8::String> some_property = | 16175 v8::Handle<v8::String> some_property = |
16035 v8::String::NewFromUtf8(isolate, "a"); | 16176 v8::String::NewFromUtf8(isolate, "a"); |
16036 global->ForceSet(some_property, v8::Integer::New(isolate, 42), | 16177 global->ForceSet(some_property, v8::Integer::New(isolate, 42), |
16037 v8::DontDelete); | 16178 v8::DontDelete); |
16038 | 16179 |
16039 // Deleting a property should get intercepted and nothing should | 16180 // Deleting a property should get intercepted and nothing should |
16040 // happen. | 16181 // happen. |
(...skipping 3391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19432 static void SetterWhichSetsYOnThisTo23( | 19573 static void SetterWhichSetsYOnThisTo23( |
19433 Local<String> name, | 19574 Local<String> name, |
19434 Local<Value> value, | 19575 Local<Value> value, |
19435 const v8::PropertyCallbackInfo<void>& info) { | 19576 const v8::PropertyCallbackInfo<void>& info) { |
19436 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); | 19577 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); |
19437 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); | 19578 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); |
19438 Local<Object>::Cast(info.This())->Set(v8_str("y"), v8_num(23)); | 19579 Local<Object>::Cast(info.This())->Set(v8_str("y"), v8_num(23)); |
19439 } | 19580 } |
19440 | 19581 |
19441 | 19582 |
19442 void FooGetInterceptor(Local<String> name, | 19583 void FooGetInterceptor(Local<Name> name, |
19443 const v8::PropertyCallbackInfo<v8::Value>& info) { | 19584 const v8::PropertyCallbackInfo<v8::Value>& info) { |
19444 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); | 19585 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); |
19445 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); | 19586 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); |
19446 if (!name->Equals(v8_str("foo"))) return; | 19587 if (!name->Equals(v8_str("foo"))) return; |
19447 info.GetReturnValue().Set(v8_num(42)); | 19588 info.GetReturnValue().Set(v8_num(42)); |
19448 } | 19589 } |
19449 | 19590 |
19450 | 19591 |
19451 void FooSetInterceptor(Local<String> name, | 19592 void FooSetInterceptor(Local<Name> name, Local<Value> value, |
19452 Local<Value> value, | |
19453 const v8::PropertyCallbackInfo<v8::Value>& info) { | 19593 const v8::PropertyCallbackInfo<v8::Value>& info) { |
19454 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); | 19594 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); |
19455 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); | 19595 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); |
19456 if (!name->Equals(v8_str("foo"))) return; | 19596 if (!name->Equals(v8_str("foo"))) return; |
19457 Local<Object>::Cast(info.This())->Set(v8_str("y"), v8_num(23)); | 19597 Local<Object>::Cast(info.This())->Set(v8_str("y"), v8_num(23)); |
19458 info.GetReturnValue().Set(v8_num(23)); | 19598 info.GetReturnValue().Set(v8_num(23)); |
19459 } | 19599 } |
19460 | 19600 |
19461 | 19601 |
19462 TEST(SetterOnConstructorPrototype) { | 19602 TEST(SetterOnConstructorPrototype) { |
(...skipping 25 matching lines...) Expand all Loading... |
19488 script = v8_compile("new C2();"); | 19628 script = v8_compile("new C2();"); |
19489 for (int i = 0; i < 10; i++) { | 19629 for (int i = 0; i < 10; i++) { |
19490 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run()); | 19630 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run()); |
19491 CHECK_EQ(42, c2->Get(v8_str("x"))->Int32Value()); | 19631 CHECK_EQ(42, c2->Get(v8_str("x"))->Int32Value()); |
19492 CHECK_EQ(23, c2->Get(v8_str("y"))->Int32Value()); | 19632 CHECK_EQ(23, c2->Get(v8_str("y"))->Int32Value()); |
19493 } | 19633 } |
19494 } | 19634 } |
19495 | 19635 |
19496 | 19636 |
19497 static void NamedPropertyGetterWhichReturns42( | 19637 static void NamedPropertyGetterWhichReturns42( |
19498 Local<String> name, | 19638 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
19499 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
19500 info.GetReturnValue().Set(v8_num(42)); | 19639 info.GetReturnValue().Set(v8_num(42)); |
19501 } | 19640 } |
19502 | 19641 |
19503 | 19642 |
19504 static void NamedPropertySetterWhichSetsYOnThisTo23( | 19643 static void NamedPropertySetterWhichSetsYOnThisTo23( |
19505 Local<String> name, | 19644 Local<Name> name, Local<Value> value, |
19506 Local<Value> value, | |
19507 const v8::PropertyCallbackInfo<v8::Value>& info) { | 19645 const v8::PropertyCallbackInfo<v8::Value>& info) { |
19508 if (name->Equals(v8_str("x"))) { | 19646 if (name->Equals(v8_str("x"))) { |
19509 Local<Object>::Cast(info.This())->Set(v8_str("y"), v8_num(23)); | 19647 Local<Object>::Cast(info.This())->Set(v8_str("y"), v8_num(23)); |
19510 } | 19648 } |
19511 } | 19649 } |
19512 | 19650 |
19513 | 19651 |
19514 THREADED_TEST(InterceptorOnConstructorPrototype) { | 19652 THREADED_TEST(InterceptorOnConstructorPrototype) { |
19515 v8::Isolate* isolate = CcTest::isolate(); | 19653 v8::Isolate* isolate = CcTest::isolate(); |
19516 v8::HandleScope scope(isolate); | 19654 v8::HandleScope scope(isolate); |
19517 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 19655 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
19518 templ->SetNamedPropertyHandler(NamedPropertyGetterWhichReturns42, | 19656 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
19519 NamedPropertySetterWhichSetsYOnThisTo23); | 19657 NamedPropertyGetterWhichReturns42, |
| 19658 NamedPropertySetterWhichSetsYOnThisTo23)); |
19520 LocalContext context; | 19659 LocalContext context; |
19521 context->Global()->Set(v8_str("P"), templ->NewInstance()); | 19660 context->Global()->Set(v8_str("P"), templ->NewInstance()); |
19522 CompileRun("function C1() {" | 19661 CompileRun("function C1() {" |
19523 " this.x = 23;" | 19662 " this.x = 23;" |
19524 "};" | 19663 "};" |
19525 "C1.prototype = P;" | 19664 "C1.prototype = P;" |
19526 "function C2() {" | 19665 "function C2() {" |
19527 " this.x = 23" | 19666 " this.x = 23" |
19528 "};" | 19667 "};" |
19529 "C2.prototype = { };" | 19668 "C2.prototype = { };" |
(...skipping 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20801 CHECK(!globalProxy->StrictEquals(global)); | 20940 CHECK(!globalProxy->StrictEquals(global)); |
20802 CHECK(globalProxy->StrictEquals(globalProxy)); | 20941 CHECK(globalProxy->StrictEquals(globalProxy)); |
20803 | 20942 |
20804 CHECK(global->Equals(global)); | 20943 CHECK(global->Equals(global)); |
20805 CHECK(!global->Equals(globalProxy)); | 20944 CHECK(!global->Equals(globalProxy)); |
20806 CHECK(!globalProxy->Equals(global)); | 20945 CHECK(!globalProxy->Equals(global)); |
20807 CHECK(globalProxy->Equals(globalProxy)); | 20946 CHECK(globalProxy->Equals(globalProxy)); |
20808 } | 20947 } |
20809 | 20948 |
20810 | 20949 |
20811 static void Getter(v8::Local<v8::String> property, | 20950 static void Getter(v8::Local<v8::Name> property, |
20812 const v8::PropertyCallbackInfo<v8::Value>& info ) { | 20951 const v8::PropertyCallbackInfo<v8::Value>& info) { |
20813 info.GetReturnValue().Set(v8_str("42!")); | 20952 info.GetReturnValue().Set(v8_str("42!")); |
20814 } | 20953 } |
20815 | 20954 |
20816 | 20955 |
20817 static void Enumerator(const v8::PropertyCallbackInfo<v8::Array>& info) { | 20956 static void Enumerator(const v8::PropertyCallbackInfo<v8::Array>& info) { |
20818 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate()); | 20957 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate()); |
20819 result->Set(0, v8_str("universalAnswer")); | 20958 result->Set(0, v8_str("universalAnswer")); |
20820 info.GetReturnValue().Set(result); | 20959 info.GetReturnValue().Set(result); |
20821 } | 20960 } |
20822 | 20961 |
20823 | 20962 |
20824 TEST(NamedEnumeratorAndForIn) { | 20963 TEST(NamedEnumeratorAndForIn) { |
20825 LocalContext context; | 20964 LocalContext context; |
20826 v8::Isolate* isolate = context->GetIsolate(); | 20965 v8::Isolate* isolate = context->GetIsolate(); |
20827 v8::HandleScope handle_scope(isolate); | 20966 v8::HandleScope handle_scope(isolate); |
20828 v8::Context::Scope context_scope(context.local()); | 20967 v8::Context::Scope context_scope(context.local()); |
20829 | 20968 |
20830 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(isolate); | 20969 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(isolate); |
20831 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); | 20970 tmpl->SetHandler(v8::NamedPropertyHandlerConfiguration(Getter, NULL, NULL, |
| 20971 NULL, Enumerator)); |
20832 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); | 20972 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); |
20833 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( | 20973 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( |
20834 "var result = []; for (var k in o) result.push(k); result")); | 20974 "var result = []; for (var k in o) result.push(k); result")); |
20835 CHECK_EQ(1, result->Length()); | 20975 CHECK_EQ(1, result->Length()); |
20836 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); | 20976 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); |
20837 } | 20977 } |
20838 | 20978 |
20839 | 20979 |
20840 TEST(DefinePropertyPostDetach) { | 20980 TEST(DefinePropertyPostDetach) { |
20841 LocalContext context; | 20981 LocalContext context; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20966 | 21106 |
20967 | 21107 |
20968 void HasOwnPropertyIndexedPropertyGetter( | 21108 void HasOwnPropertyIndexedPropertyGetter( |
20969 uint32_t index, | 21109 uint32_t index, |
20970 const v8::PropertyCallbackInfo<v8::Value>& info) { | 21110 const v8::PropertyCallbackInfo<v8::Value>& info) { |
20971 if (index == 42) info.GetReturnValue().Set(v8_str("yes")); | 21111 if (index == 42) info.GetReturnValue().Set(v8_str("yes")); |
20972 } | 21112 } |
20973 | 21113 |
20974 | 21114 |
20975 void HasOwnPropertyNamedPropertyGetter( | 21115 void HasOwnPropertyNamedPropertyGetter( |
20976 Local<String> property, | 21116 Local<Name> property, const v8::PropertyCallbackInfo<v8::Value>& info) { |
20977 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
20978 if (property->Equals(v8_str("foo"))) info.GetReturnValue().Set(v8_str("yes")); | 21117 if (property->Equals(v8_str("foo"))) info.GetReturnValue().Set(v8_str("yes")); |
20979 } | 21118 } |
20980 | 21119 |
20981 | 21120 |
20982 void HasOwnPropertyIndexedPropertyQuery( | 21121 void HasOwnPropertyIndexedPropertyQuery( |
20983 uint32_t index, const v8::PropertyCallbackInfo<v8::Integer>& info) { | 21122 uint32_t index, const v8::PropertyCallbackInfo<v8::Integer>& info) { |
20984 if (index == 42) info.GetReturnValue().Set(1); | 21123 if (index == 42) info.GetReturnValue().Set(1); |
20985 } | 21124 } |
20986 | 21125 |
20987 | 21126 |
20988 void HasOwnPropertyNamedPropertyQuery( | 21127 void HasOwnPropertyNamedPropertyQuery( |
20989 Local<String> property, | 21128 Local<Name> property, const v8::PropertyCallbackInfo<v8::Integer>& info) { |
20990 const v8::PropertyCallbackInfo<v8::Integer>& info) { | |
20991 if (property->Equals(v8_str("foo"))) info.GetReturnValue().Set(1); | 21129 if (property->Equals(v8_str("foo"))) info.GetReturnValue().Set(1); |
20992 } | 21130 } |
20993 | 21131 |
20994 | 21132 |
20995 void HasOwnPropertyNamedPropertyQuery2( | 21133 void HasOwnPropertyNamedPropertyQuery2( |
20996 Local<String> property, | 21134 Local<Name> property, const v8::PropertyCallbackInfo<v8::Integer>& info) { |
20997 const v8::PropertyCallbackInfo<v8::Integer>& info) { | |
20998 if (property->Equals(v8_str("bar"))) info.GetReturnValue().Set(1); | 21135 if (property->Equals(v8_str("bar"))) info.GetReturnValue().Set(1); |
20999 } | 21136 } |
21000 | 21137 |
21001 | 21138 |
21002 void HasOwnPropertyAccessorGetter( | 21139 void HasOwnPropertyAccessorGetter( |
21003 Local<String> property, | 21140 Local<String> property, |
21004 const v8::PropertyCallbackInfo<v8::Value>& info) { | 21141 const v8::PropertyCallbackInfo<v8::Value>& info) { |
21005 info.GetReturnValue().Set(v8_str("yes")); | 21142 info.GetReturnValue().Set(v8_str("yes")); |
21006 } | 21143 } |
21007 | 21144 |
(...skipping 18 matching lines...) Expand all Loading... |
21026 Handle<Object> object = value->ToObject(isolate); | 21163 Handle<Object> object = value->ToObject(isolate); |
21027 CHECK(object->Has(v8_str("foo"))); | 21164 CHECK(object->Has(v8_str("foo"))); |
21028 CHECK(!object->HasOwnProperty(v8_str("foo"))); | 21165 CHECK(!object->HasOwnProperty(v8_str("foo"))); |
21029 CHECK(object->HasOwnProperty(v8_str("bar"))); | 21166 CHECK(object->HasOwnProperty(v8_str("bar"))); |
21030 CHECK(object->Has(v8_str("baz"))); | 21167 CHECK(object->Has(v8_str("baz"))); |
21031 CHECK(!object->HasOwnProperty(v8_str("baz"))); | 21168 CHECK(!object->HasOwnProperty(v8_str("baz"))); |
21032 CHECK(object->HasOwnProperty(v8_str("bla"))); | 21169 CHECK(object->HasOwnProperty(v8_str("bla"))); |
21033 } | 21170 } |
21034 { // Check named getter interceptors. | 21171 { // Check named getter interceptors. |
21035 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 21172 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
21036 templ->SetNamedPropertyHandler(HasOwnPropertyNamedPropertyGetter); | 21173 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
| 21174 HasOwnPropertyNamedPropertyGetter)); |
21037 Handle<Object> instance = templ->NewInstance(); | 21175 Handle<Object> instance = templ->NewInstance(); |
21038 CHECK(!instance->HasOwnProperty(v8_str("42"))); | 21176 CHECK(!instance->HasOwnProperty(v8_str("42"))); |
21039 CHECK(instance->HasOwnProperty(v8_str("foo"))); | 21177 CHECK(instance->HasOwnProperty(v8_str("foo"))); |
21040 CHECK(!instance->HasOwnProperty(v8_str("bar"))); | 21178 CHECK(!instance->HasOwnProperty(v8_str("bar"))); |
21041 } | 21179 } |
21042 { // Check indexed getter interceptors. | 21180 { // Check indexed getter interceptors. |
21043 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 21181 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
21044 templ->SetIndexedPropertyHandler(HasOwnPropertyIndexedPropertyGetter); | 21182 templ->SetIndexedPropertyHandler(HasOwnPropertyIndexedPropertyGetter); |
21045 Handle<Object> instance = templ->NewInstance(); | 21183 Handle<Object> instance = templ->NewInstance(); |
21046 CHECK(instance->HasOwnProperty(v8_str("42"))); | 21184 CHECK(instance->HasOwnProperty(v8_str("42"))); |
21047 CHECK(!instance->HasOwnProperty(v8_str("43"))); | 21185 CHECK(!instance->HasOwnProperty(v8_str("43"))); |
21048 CHECK(!instance->HasOwnProperty(v8_str("foo"))); | 21186 CHECK(!instance->HasOwnProperty(v8_str("foo"))); |
21049 } | 21187 } |
21050 { // Check named query interceptors. | 21188 { // Check named query interceptors. |
21051 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 21189 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
21052 templ->SetNamedPropertyHandler(0, 0, HasOwnPropertyNamedPropertyQuery); | 21190 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
| 21191 0, 0, HasOwnPropertyNamedPropertyQuery)); |
21053 Handle<Object> instance = templ->NewInstance(); | 21192 Handle<Object> instance = templ->NewInstance(); |
21054 CHECK(instance->HasOwnProperty(v8_str("foo"))); | 21193 CHECK(instance->HasOwnProperty(v8_str("foo"))); |
21055 CHECK(!instance->HasOwnProperty(v8_str("bar"))); | 21194 CHECK(!instance->HasOwnProperty(v8_str("bar"))); |
21056 } | 21195 } |
21057 { // Check indexed query interceptors. | 21196 { // Check indexed query interceptors. |
21058 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 21197 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
21059 templ->SetIndexedPropertyHandler(0, 0, HasOwnPropertyIndexedPropertyQuery); | 21198 templ->SetIndexedPropertyHandler(0, 0, HasOwnPropertyIndexedPropertyQuery); |
21060 Handle<Object> instance = templ->NewInstance(); | 21199 Handle<Object> instance = templ->NewInstance(); |
21061 CHECK(instance->HasOwnProperty(v8_str("42"))); | 21200 CHECK(instance->HasOwnProperty(v8_str("42"))); |
21062 CHECK(!instance->HasOwnProperty(v8_str("41"))); | 21201 CHECK(!instance->HasOwnProperty(v8_str("41"))); |
21063 } | 21202 } |
21064 { // Check callbacks. | 21203 { // Check callbacks. |
21065 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 21204 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
21066 templ->SetAccessor(v8_str("foo"), HasOwnPropertyAccessorGetter); | 21205 templ->SetAccessor(v8_str("foo"), HasOwnPropertyAccessorGetter); |
21067 Handle<Object> instance = templ->NewInstance(); | 21206 Handle<Object> instance = templ->NewInstance(); |
21068 CHECK(instance->HasOwnProperty(v8_str("foo"))); | 21207 CHECK(instance->HasOwnProperty(v8_str("foo"))); |
21069 CHECK(!instance->HasOwnProperty(v8_str("bar"))); | 21208 CHECK(!instance->HasOwnProperty(v8_str("bar"))); |
21070 } | 21209 } |
21071 { // Check that query wins on disagreement. | 21210 { // Check that query wins on disagreement. |
21072 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 21211 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
21073 templ->SetNamedPropertyHandler(HasOwnPropertyNamedPropertyGetter, | 21212 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
21074 0, | 21213 HasOwnPropertyNamedPropertyGetter, 0, |
21075 HasOwnPropertyNamedPropertyQuery2); | 21214 HasOwnPropertyNamedPropertyQuery2)); |
21076 Handle<Object> instance = templ->NewInstance(); | 21215 Handle<Object> instance = templ->NewInstance(); |
21077 CHECK(!instance->HasOwnProperty(v8_str("foo"))); | 21216 CHECK(!instance->HasOwnProperty(v8_str("foo"))); |
21078 CHECK(instance->HasOwnProperty(v8_str("bar"))); | 21217 CHECK(instance->HasOwnProperty(v8_str("bar"))); |
21079 } | 21218 } |
21080 } | 21219 } |
21081 | 21220 |
21082 | 21221 |
21083 TEST(IndexedInterceptorWithStringProto) { | 21222 TEST(IndexedInterceptorWithStringProto) { |
21084 v8::Isolate* isolate = CcTest::isolate(); | 21223 v8::Isolate* isolate = CcTest::isolate(); |
21085 v8::HandleScope scope(isolate); | 21224 v8::HandleScope scope(isolate); |
(...skipping 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22192 } | 22331 } |
22193 | 22332 |
22194 | 22333 |
22195 static void Helper137002(bool do_store, | 22334 static void Helper137002(bool do_store, |
22196 bool polymorphic, | 22335 bool polymorphic, |
22197 bool remove_accessor, | 22336 bool remove_accessor, |
22198 bool interceptor) { | 22337 bool interceptor) { |
22199 LocalContext context; | 22338 LocalContext context; |
22200 Local<ObjectTemplate> templ = ObjectTemplate::New(context->GetIsolate()); | 22339 Local<ObjectTemplate> templ = ObjectTemplate::New(context->GetIsolate()); |
22201 if (interceptor) { | 22340 if (interceptor) { |
22202 templ->SetNamedPropertyHandler(FooGetInterceptor, FooSetInterceptor); | 22341 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(FooGetInterceptor, |
| 22342 FooSetInterceptor)); |
22203 } else { | 22343 } else { |
22204 templ->SetAccessor(v8_str("foo"), | 22344 templ->SetAccessor(v8_str("foo"), |
22205 GetterWhichReturns42, | 22345 GetterWhichReturns42, |
22206 SetterWhichSetsYOnThisTo23); | 22346 SetterWhichSetsYOnThisTo23); |
22207 } | 22347 } |
22208 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 22348 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
22209 | 22349 |
22210 // Turn monomorphic on slow object with native accessor, then turn | 22350 // Turn monomorphic on slow object with native accessor, then turn |
22211 // polymorphic, finally optimize to create negative lookup and fail. | 22351 // polymorphic, finally optimize to create negative lookup and fail. |
22212 CompileRun(do_store ? | 22352 CompileRun(do_store ? |
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22966 | 23106 |
22967 class RequestInterruptTestWithMethodCallAndInterceptor | 23107 class RequestInterruptTestWithMethodCallAndInterceptor |
22968 : public RequestInterruptTestBaseWithSimpleInterrupt { | 23108 : public RequestInterruptTestBaseWithSimpleInterrupt { |
22969 public: | 23109 public: |
22970 virtual void TestBody() { | 23110 virtual void TestBody() { |
22971 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); | 23111 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); |
22972 v8::Local<v8::Template> proto = t->PrototypeTemplate(); | 23112 v8::Local<v8::Template> proto = t->PrototypeTemplate(); |
22973 proto->Set(v8_str("shouldContinue"), Function::New( | 23113 proto->Set(v8_str("shouldContinue"), Function::New( |
22974 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this))); | 23114 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this))); |
22975 v8::Local<v8::ObjectTemplate> instance_template = t->InstanceTemplate(); | 23115 v8::Local<v8::ObjectTemplate> instance_template = t->InstanceTemplate(); |
22976 instance_template->SetNamedPropertyHandler(EmptyInterceptor); | 23116 instance_template->SetHandler( |
| 23117 v8::NamedPropertyHandlerConfiguration(EmptyInterceptor)); |
22977 | 23118 |
22978 env_->Global()->Set(v8_str("Klass"), t->GetFunction()); | 23119 env_->Global()->Set(v8_str("Klass"), t->GetFunction()); |
22979 | 23120 |
22980 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }"); | 23121 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }"); |
22981 } | 23122 } |
22982 | 23123 |
22983 private: | 23124 private: |
22984 static void EmptyInterceptor( | 23125 static void EmptyInterceptor( |
22985 Local<String> property, | 23126 Local<Name> property, const v8::PropertyCallbackInfo<v8::Value>& info) {} |
22986 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
22987 } | |
22988 }; | 23127 }; |
22989 | 23128 |
22990 | 23129 |
22991 class RequestInterruptTestWithMathAbs | 23130 class RequestInterruptTestWithMathAbs |
22992 : public RequestInterruptTestBaseWithSimpleInterrupt { | 23131 : public RequestInterruptTestBaseWithSimpleInterrupt { |
22993 public: | 23132 public: |
22994 virtual void TestBody() { | 23133 virtual void TestBody() { |
22995 env_->Global()->Set(v8_str("WakeUpInterruptor"), Function::New( | 23134 env_->Global()->Set(v8_str("WakeUpInterruptor"), Function::New( |
22996 isolate_, | 23135 isolate_, |
22997 WakeUpInterruptorCallback, | 23136 WakeUpInterruptorCallback, |
(...skipping 1255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
24253 v8::HandleScope scope(CcTest::isolate()); | 24392 v8::HandleScope scope(CcTest::isolate()); |
24254 RandomLengthOneByteResource* r = | 24393 RandomLengthOneByteResource* r = |
24255 new RandomLengthOneByteResource(i::String::kMaxLength); | 24394 new RandomLengthOneByteResource(i::String::kMaxLength); |
24256 v8::Local<v8::String> str = v8::String::NewExternal(CcTest::isolate(), r); | 24395 v8::Local<v8::String> str = v8::String::NewExternal(CcTest::isolate(), r); |
24257 CHECK(!str.IsEmpty()); | 24396 CHECK(!str.IsEmpty()); |
24258 v8::TryCatch try_catch; | 24397 v8::TryCatch try_catch; |
24259 v8::Local<v8::String> result = v8::String::Concat(str, str); | 24398 v8::Local<v8::String> result = v8::String::Concat(str, str); |
24260 CHECK(result.IsEmpty()); | 24399 CHECK(result.IsEmpty()); |
24261 CHECK(!try_catch.HasCaught()); | 24400 CHECK(!try_catch.HasCaught()); |
24262 } | 24401 } |
OLD | NEW |