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 1977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9966 "};" | 10083 "};" |
9967 "var m = f.toMethod(prohibited);" | 10084 "var m = f.toMethod(prohibited);" |
9968 "m();"); | 10085 "m();"); |
9969 CHECK(try_catch.HasCaught()); | 10086 CHECK(try_catch.HasCaught()); |
9970 } | 10087 } |
9971 } | 10088 } |
9972 | 10089 |
9973 | 10090 |
9974 static void IndexedPropertyEnumerator( | 10091 static void IndexedPropertyEnumerator( |
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(), 1); |
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())); | |
9979 info.GetReturnValue().Set(result); | 10095 info.GetReturnValue().Set(result); |
9980 } | 10096 } |
9981 | 10097 |
9982 | 10098 |
9983 static void NamedPropertyEnumerator( | 10099 static void NamedPropertyEnumerator( |
9984 const v8::PropertyCallbackInfo<v8::Array>& info) { | 10100 const v8::PropertyCallbackInfo<v8::Array>& info) { |
9985 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2); | 10101 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2); |
9986 result->Set(0, v8_str("x")); | 10102 result->Set(0, v8_str("x")); |
9987 result->Set(1, v8::Object::New(info.GetIsolate())); | 10103 result->Set(1, v8::Symbol::GetIterator(info.GetIsolate())); |
9988 info.GetReturnValue().Set(result); | 10104 info.GetReturnValue().Set(result); |
9989 } | 10105 } |
9990 | 10106 |
9991 | 10107 |
9992 THREADED_TEST(GetOwnPropertyNamesWithInterceptor) { | 10108 THREADED_TEST(GetOwnPropertyNamesWithInterceptor) { |
9993 v8::Isolate* isolate = CcTest::isolate(); | 10109 v8::Isolate* isolate = CcTest::isolate(); |
9994 v8::HandleScope handle_scope(isolate); | 10110 v8::HandleScope handle_scope(isolate); |
9995 v8::Handle<v8::ObjectTemplate> obj_template = | 10111 v8::Handle<v8::ObjectTemplate> obj_template = |
9996 v8::ObjectTemplate::New(isolate); | 10112 v8::ObjectTemplate::New(isolate); |
9997 | 10113 |
9998 obj_template->Set(v8_str("7"), v8::Integer::New(CcTest::isolate(), 7)); | 10114 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)); | 10115 obj_template->Set(v8_str("x"), v8::Integer::New(CcTest::isolate(), 42)); |
10000 obj_template->SetIndexedPropertyHandler(NULL, NULL, NULL, NULL, | 10116 obj_template->SetIndexedPropertyHandler(NULL, NULL, NULL, NULL, |
10001 IndexedPropertyEnumerator); | 10117 IndexedPropertyEnumerator); |
10002 obj_template->SetNamedPropertyHandler(NULL, NULL, NULL, NULL, | 10118 obj_template->SetHandler(v8::NamedPropertyHandlerConfiguration( |
10003 NamedPropertyEnumerator); | 10119 NULL, NULL, NULL, NULL, NamedPropertyEnumerator)); |
10004 | 10120 |
10005 LocalContext context; | 10121 LocalContext context; |
10006 v8::Handle<v8::Object> global = context->Global(); | 10122 v8::Handle<v8::Object> global = context->Global(); |
10007 global->Set(v8_str("object"), obj_template->NewInstance()); | 10123 global->Set(v8_str("object"), obj_template->NewInstance()); |
10008 | 10124 |
10009 v8::Handle<v8::Value> result = | 10125 v8::Handle<v8::Value> result = |
10010 CompileRun("Object.getOwnPropertyNames(object)"); | 10126 CompileRun("Object.getOwnPropertyNames(object)"); |
10011 CHECK(result->IsArray()); | 10127 CHECK(result->IsArray()); |
10012 v8::Handle<v8::Array> result_array = v8::Handle<v8::Array>::Cast(result); | 10128 v8::Handle<v8::Array> result_array = v8::Handle<v8::Array>::Cast(result); |
10013 CHECK_EQ(3, result_array->Length()); | 10129 CHECK_EQ(2, result_array->Length()); |
10014 CHECK(result_array->Get(0)->IsString()); | 10130 CHECK(result_array->Get(0)->IsString()); |
10015 CHECK(result_array->Get(1)->IsString()); | 10131 CHECK(result_array->Get(1)->IsString()); |
10016 CHECK(result_array->Get(2)->IsString()); | |
10017 CHECK_EQ(v8_str("7"), result_array->Get(0)); | 10132 CHECK_EQ(v8_str("7"), result_array->Get(0)); |
10018 CHECK_EQ(v8_str("[object Object]"), result_array->Get(1)); | 10133 CHECK_EQ(v8_str("x"), result_array->Get(1)); |
10019 CHECK_EQ(v8_str("x"), result_array->Get(2)); | 10134 |
| 10135 result = CompileRun("var ret = []; for (var k in object) ret.push(k); ret"); |
| 10136 CHECK(result->IsArray()); |
| 10137 result_array = v8::Handle<v8::Array>::Cast(result); |
| 10138 CHECK_EQ(2, result_array->Length()); |
| 10139 CHECK(result_array->Get(0)->IsString()); |
| 10140 CHECK(result_array->Get(1)->IsString()); |
| 10141 CHECK_EQ(v8_str("7"), result_array->Get(0)); |
| 10142 CHECK_EQ(v8_str("x"), result_array->Get(1)); |
| 10143 |
| 10144 result = CompileRun("Object.getOwnPropertySymbols(object)"); |
| 10145 CHECK(result->IsArray()); |
| 10146 result_array = v8::Handle<v8::Array>::Cast(result); |
| 10147 CHECK_EQ(1, result_array->Length()); |
| 10148 CHECK_EQ(result_array->Get(0), v8::Symbol::GetIterator(isolate)); |
10020 } | 10149 } |
10021 | 10150 |
10022 | 10151 |
10023 static void ConstTenGetter(Local<String> name, | 10152 static void ConstTenGetter(Local<String> name, |
10024 const v8::PropertyCallbackInfo<v8::Value>& info) { | 10153 const v8::PropertyCallbackInfo<v8::Value>& info) { |
10025 info.GetReturnValue().Set(v8_num(10)); | 10154 info.GetReturnValue().Set(v8_num(10)); |
10026 } | 10155 } |
10027 | 10156 |
10028 | 10157 |
10029 THREADED_TEST(CrossDomainAccessors) { | 10158 THREADED_TEST(CrossDomainAccessors) { |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10283 | 10412 |
10284 value = v8_compile("var p = 'as' + 'df';")->Run(); | 10413 value = v8_compile("var p = 'as' + 'df';")->Run(); |
10285 value = v8_compile("obj[p];")->Run(); | 10414 value = v8_compile("obj[p];")->Run(); |
10286 | 10415 |
10287 context1->Exit(); | 10416 context1->Exit(); |
10288 context0->Exit(); | 10417 context0->Exit(); |
10289 } | 10418 } |
10290 | 10419 |
10291 | 10420 |
10292 static void AccessControlNamedGetter( | 10421 static void AccessControlNamedGetter( |
10293 Local<String>, | 10422 Local<Name>, const v8::PropertyCallbackInfo<v8::Value>& info) { |
10294 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
10295 info.GetReturnValue().Set(42); | 10423 info.GetReturnValue().Set(42); |
10296 } | 10424 } |
10297 | 10425 |
10298 | 10426 |
10299 static void AccessControlNamedSetter( | 10427 static void AccessControlNamedSetter( |
10300 Local<String>, | 10428 Local<Name>, Local<Value> value, |
10301 Local<Value> value, | |
10302 const v8::PropertyCallbackInfo<v8::Value>& info) { | 10429 const v8::PropertyCallbackInfo<v8::Value>& info) { |
10303 info.GetReturnValue().Set(value); | 10430 info.GetReturnValue().Set(value); |
10304 } | 10431 } |
10305 | 10432 |
10306 | 10433 |
10307 static void AccessControlIndexedGetter( | 10434 static void AccessControlIndexedGetter( |
10308 uint32_t index, | 10435 uint32_t index, |
10309 const v8::PropertyCallbackInfo<v8::Value>& info) { | 10436 const v8::PropertyCallbackInfo<v8::Value>& info) { |
10310 info.GetReturnValue().Set(v8_num(42)); | 10437 info.GetReturnValue().Set(v8_num(42)); |
10311 } | 10438 } |
(...skipping 18 matching lines...) Expand all Loading... |
10330 v8::Local<Context> context0 = Context::New(isolate); | 10457 v8::Local<Context> context0 = Context::New(isolate); |
10331 context0->Enter(); | 10458 context0->Enter(); |
10332 | 10459 |
10333 // Create an object that requires access-check functions to be | 10460 // Create an object that requires access-check functions to be |
10334 // called for cross-domain access. The object also has interceptors | 10461 // called for cross-domain access. The object also has interceptors |
10335 // interceptor. | 10462 // interceptor. |
10336 v8::Handle<v8::ObjectTemplate> object_template = | 10463 v8::Handle<v8::ObjectTemplate> object_template = |
10337 v8::ObjectTemplate::New(isolate); | 10464 v8::ObjectTemplate::New(isolate); |
10338 object_template->SetAccessCheckCallbacks(NamedAccessCounter, | 10465 object_template->SetAccessCheckCallbacks(NamedAccessCounter, |
10339 IndexedAccessCounter); | 10466 IndexedAccessCounter); |
10340 object_template->SetNamedPropertyHandler(AccessControlNamedGetter, | 10467 object_template->SetHandler(v8::NamedPropertyHandlerConfiguration( |
10341 AccessControlNamedSetter); | 10468 AccessControlNamedGetter, AccessControlNamedSetter)); |
10342 object_template->SetIndexedPropertyHandler(AccessControlIndexedGetter, | 10469 object_template->SetIndexedPropertyHandler(AccessControlIndexedGetter, |
10343 AccessControlIndexedSetter); | 10470 AccessControlIndexedSetter); |
10344 Local<v8::Object> object = object_template->NewInstance(); | 10471 Local<v8::Object> object = object_template->NewInstance(); |
10345 | 10472 |
10346 v8::HandleScope scope1(isolate); | 10473 v8::HandleScope scope1(isolate); |
10347 | 10474 |
10348 // Create another environment. | 10475 // Create another environment. |
10349 v8::Local<Context> context1 = Context::New(isolate); | 10476 v8::Local<Context> context1 = Context::New(isolate); |
10350 context1->Enter(); | 10477 context1->Enter(); |
10351 | 10478 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10415 context->Global()->Set(v8_str("i"), o); | 10542 context->Global()->Set(v8_str("i"), o); |
10416 Local<Value> value = CompileRun("i.x"); | 10543 Local<Value> value = CompileRun("i.x"); |
10417 CHECK_EQ(42, value->Int32Value()); | 10544 CHECK_EQ(42, value->Int32Value()); |
10418 | 10545 |
10419 value = CompileRun("i.f()"); | 10546 value = CompileRun("i.f()"); |
10420 CHECK_EQ(12, value->Int32Value()); | 10547 CHECK_EQ(12, value->Int32Value()); |
10421 } | 10548 } |
10422 | 10549 |
10423 | 10550 |
10424 static void GlobalObjectInstancePropertiesGet( | 10551 static void GlobalObjectInstancePropertiesGet( |
10425 Local<String> key, | 10552 Local<Name> key, const v8::PropertyCallbackInfo<v8::Value>&) { |
10426 const v8::PropertyCallbackInfo<v8::Value>&) { | |
10427 ApiTestFuzzer::Fuzz(); | 10553 ApiTestFuzzer::Fuzz(); |
10428 } | 10554 } |
10429 | 10555 |
10430 | 10556 |
10431 THREADED_TEST(GlobalObjectInstanceProperties) { | 10557 THREADED_TEST(GlobalObjectInstanceProperties) { |
10432 v8::Isolate* isolate = CcTest::isolate(); | 10558 v8::Isolate* isolate = CcTest::isolate(); |
10433 v8::HandleScope handle_scope(isolate); | 10559 v8::HandleScope handle_scope(isolate); |
10434 | 10560 |
10435 Local<Value> global_object; | 10561 Local<Value> global_object; |
10436 | 10562 |
10437 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); | 10563 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); |
10438 t->InstanceTemplate()->SetNamedPropertyHandler( | 10564 t->InstanceTemplate()->SetHandler( |
10439 GlobalObjectInstancePropertiesGet); | 10565 v8::NamedPropertyHandlerConfiguration(GlobalObjectInstancePropertiesGet)); |
10440 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); | 10566 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); |
10441 instance_template->Set(v8_str("x"), v8_num(42)); | 10567 instance_template->Set(v8_str("x"), v8_num(42)); |
10442 instance_template->Set(v8_str("f"), | 10568 instance_template->Set(v8_str("f"), |
10443 v8::FunctionTemplate::New(isolate, | 10569 v8::FunctionTemplate::New(isolate, |
10444 InstanceFunctionCallback)); | 10570 InstanceFunctionCallback)); |
10445 | 10571 |
10446 // The script to check how Crankshaft compiles missing global function | 10572 // The script to check how Crankshaft compiles missing global function |
10447 // invocations. function g is not defined and should throw on call. | 10573 // invocations. function g is not defined and should throw on call. |
10448 const char* script = | 10574 const char* script = |
10449 "function wrapper(call) {" | 10575 "function wrapper(call) {" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10553 shadow_y_getter_call_count++; | 10679 shadow_y_getter_call_count++; |
10554 info.GetReturnValue().Set(v8_num(shadow_y)); | 10680 info.GetReturnValue().Set(v8_num(shadow_y)); |
10555 } | 10681 } |
10556 | 10682 |
10557 | 10683 |
10558 static void ShadowIndexedGet(uint32_t index, | 10684 static void ShadowIndexedGet(uint32_t index, |
10559 const v8::PropertyCallbackInfo<v8::Value>&) { | 10685 const v8::PropertyCallbackInfo<v8::Value>&) { |
10560 } | 10686 } |
10561 | 10687 |
10562 | 10688 |
10563 static void ShadowNamedGet(Local<String> key, | 10689 static void ShadowNamedGet(Local<Name> key, |
10564 const v8::PropertyCallbackInfo<v8::Value>&) { | 10690 const v8::PropertyCallbackInfo<v8::Value>&) {} |
10565 } | |
10566 | 10691 |
10567 | 10692 |
10568 THREADED_TEST(ShadowObject) { | 10693 THREADED_TEST(ShadowObject) { |
10569 shadow_y = shadow_y_setter_call_count = shadow_y_getter_call_count = 0; | 10694 shadow_y = shadow_y_setter_call_count = shadow_y_getter_call_count = 0; |
10570 v8::Isolate* isolate = CcTest::isolate(); | 10695 v8::Isolate* isolate = CcTest::isolate(); |
10571 v8::HandleScope handle_scope(isolate); | 10696 v8::HandleScope handle_scope(isolate); |
10572 | 10697 |
10573 Local<ObjectTemplate> global_template = v8::ObjectTemplate::New(isolate); | 10698 Local<ObjectTemplate> global_template = v8::ObjectTemplate::New(isolate); |
10574 LocalContext context(NULL, global_template); | 10699 LocalContext context(NULL, global_template); |
10575 | 10700 |
10576 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); | 10701 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); |
10577 t->InstanceTemplate()->SetNamedPropertyHandler(ShadowNamedGet); | 10702 t->InstanceTemplate()->SetHandler( |
| 10703 v8::NamedPropertyHandlerConfiguration(ShadowNamedGet)); |
10578 t->InstanceTemplate()->SetIndexedPropertyHandler(ShadowIndexedGet); | 10704 t->InstanceTemplate()->SetIndexedPropertyHandler(ShadowIndexedGet); |
10579 Local<ObjectTemplate> proto = t->PrototypeTemplate(); | 10705 Local<ObjectTemplate> proto = t->PrototypeTemplate(); |
10580 Local<ObjectTemplate> instance = t->InstanceTemplate(); | 10706 Local<ObjectTemplate> instance = t->InstanceTemplate(); |
10581 | 10707 |
10582 proto->Set(v8_str("f"), | 10708 proto->Set(v8_str("f"), |
10583 v8::FunctionTemplate::New(isolate, | 10709 v8::FunctionTemplate::New(isolate, |
10584 ShadowFunctionCallback, | 10710 ShadowFunctionCallback, |
10585 Local<Value>())); | 10711 Local<Value>())); |
10586 proto->Set(v8_str("x"), v8_num(12)); | 10712 proto->Set(v8_str("x"), v8_num(12)); |
10587 | 10713 |
(...skipping 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11676 } | 11802 } |
11677 } | 11803 } |
11678 CHECK_EQ(kIterations, v8::HandleScope::NumberOfHandles(isolate)); | 11804 CHECK_EQ(kIterations, v8::HandleScope::NumberOfHandles(isolate)); |
11679 } | 11805 } |
11680 CHECK_EQ(0, v8::HandleScope::NumberOfHandles(isolate)); | 11806 CHECK_EQ(0, v8::HandleScope::NumberOfHandles(isolate)); |
11681 CHECK_EQ(kNesting * kIterations, Recurse(isolate, kNesting, kIterations)); | 11807 CHECK_EQ(kNesting * kIterations, Recurse(isolate, kNesting, kIterations)); |
11682 } | 11808 } |
11683 | 11809 |
11684 | 11810 |
11685 static void InterceptorHasOwnPropertyGetter( | 11811 static void InterceptorHasOwnPropertyGetter( |
11686 Local<String> name, | 11812 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
11687 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
11688 ApiTestFuzzer::Fuzz(); | 11813 ApiTestFuzzer::Fuzz(); |
11689 } | 11814 } |
11690 | 11815 |
11691 | 11816 |
11692 THREADED_TEST(InterceptorHasOwnProperty) { | 11817 THREADED_TEST(InterceptorHasOwnProperty) { |
11693 LocalContext context; | 11818 LocalContext context; |
11694 v8::Isolate* isolate = context->GetIsolate(); | 11819 v8::Isolate* isolate = context->GetIsolate(); |
11695 v8::HandleScope scope(isolate); | 11820 v8::HandleScope scope(isolate); |
11696 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate); | 11821 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate); |
11697 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); | 11822 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); |
11698 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetter); | 11823 instance_templ->SetHandler( |
| 11824 v8::NamedPropertyHandlerConfiguration(InterceptorHasOwnPropertyGetter)); |
11699 Local<Function> function = fun_templ->GetFunction(); | 11825 Local<Function> function = fun_templ->GetFunction(); |
11700 context->Global()->Set(v8_str("constructor"), function); | 11826 context->Global()->Set(v8_str("constructor"), function); |
11701 v8::Handle<Value> value = CompileRun( | 11827 v8::Handle<Value> value = CompileRun( |
11702 "var o = new constructor();" | 11828 "var o = new constructor();" |
11703 "o.hasOwnProperty('ostehaps');"); | 11829 "o.hasOwnProperty('ostehaps');"); |
11704 CHECK_EQ(false, value->BooleanValue()); | 11830 CHECK_EQ(false, value->BooleanValue()); |
11705 value = CompileRun( | 11831 value = CompileRun( |
11706 "o.ostehaps = 42;" | 11832 "o.ostehaps = 42;" |
11707 "o.hasOwnProperty('ostehaps');"); | 11833 "o.hasOwnProperty('ostehaps');"); |
11708 CHECK_EQ(true, value->BooleanValue()); | 11834 CHECK_EQ(true, value->BooleanValue()); |
11709 value = CompileRun( | 11835 value = CompileRun( |
11710 "var p = new constructor();" | 11836 "var p = new constructor();" |
11711 "p.hasOwnProperty('ostehaps');"); | 11837 "p.hasOwnProperty('ostehaps');"); |
11712 CHECK_EQ(false, value->BooleanValue()); | 11838 CHECK_EQ(false, value->BooleanValue()); |
11713 } | 11839 } |
11714 | 11840 |
11715 | 11841 |
11716 static void InterceptorHasOwnPropertyGetterGC( | 11842 static void InterceptorHasOwnPropertyGetterGC( |
11717 Local<String> name, | 11843 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
11718 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
11719 ApiTestFuzzer::Fuzz(); | 11844 ApiTestFuzzer::Fuzz(); |
11720 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 11845 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
11721 } | 11846 } |
11722 | 11847 |
11723 | 11848 |
11724 THREADED_TEST(InterceptorHasOwnPropertyCausingGC) { | 11849 THREADED_TEST(InterceptorHasOwnPropertyCausingGC) { |
11725 LocalContext context; | 11850 LocalContext context; |
11726 v8::Isolate* isolate = context->GetIsolate(); | 11851 v8::Isolate* isolate = context->GetIsolate(); |
11727 v8::HandleScope scope(isolate); | 11852 v8::HandleScope scope(isolate); |
11728 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate); | 11853 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate); |
11729 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); | 11854 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); |
11730 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetterGC); | 11855 instance_templ->SetHandler( |
| 11856 v8::NamedPropertyHandlerConfiguration(InterceptorHasOwnPropertyGetterGC)); |
11731 Local<Function> function = fun_templ->GetFunction(); | 11857 Local<Function> function = fun_templ->GetFunction(); |
11732 context->Global()->Set(v8_str("constructor"), function); | 11858 context->Global()->Set(v8_str("constructor"), function); |
11733 // Let's first make some stuff so we can be sure to get a good GC. | 11859 // Let's first make some stuff so we can be sure to get a good GC. |
11734 CompileRun( | 11860 CompileRun( |
11735 "function makestr(size) {" | 11861 "function makestr(size) {" |
11736 " switch (size) {" | 11862 " switch (size) {" |
11737 " case 1: return 'f';" | 11863 " case 1: return 'f';" |
11738 " case 2: return 'fo';" | 11864 " case 2: return 'fo';" |
11739 " case 3: return 'foo';" | 11865 " case 3: return 'foo';" |
11740 " }" | 11866 " }" |
11741 " return makestr(size >> 1) + makestr((size + 1) >> 1);" | 11867 " return makestr(size >> 1) + makestr((size + 1) >> 1);" |
11742 "}" | 11868 "}" |
11743 "var x = makestr(12345);" | 11869 "var x = makestr(12345);" |
11744 "x = makestr(31415);" | 11870 "x = makestr(31415);" |
11745 "x = makestr(23456);"); | 11871 "x = makestr(23456);"); |
11746 v8::Handle<Value> value = CompileRun( | 11872 v8::Handle<Value> value = CompileRun( |
11747 "var o = new constructor();" | 11873 "var o = new constructor();" |
11748 "o.__proto__ = new String(x);" | 11874 "o.__proto__ = new String(x);" |
11749 "o.hasOwnProperty('ostehaps');"); | 11875 "o.hasOwnProperty('ostehaps');"); |
11750 CHECK_EQ(false, value->BooleanValue()); | 11876 CHECK_EQ(false, value->BooleanValue()); |
11751 } | 11877 } |
11752 | 11878 |
11753 | 11879 |
11754 typedef void (*NamedPropertyGetter)( | 11880 static void CheckInterceptorLoadIC( |
11755 Local<String> property, | 11881 v8::GenericNamedPropertyGetterCallback getter, const char* source, |
11756 const v8::PropertyCallbackInfo<v8::Value>& info); | 11882 int expected) { |
11757 | |
11758 | |
11759 static void CheckInterceptorLoadIC(NamedPropertyGetter getter, | |
11760 const char* source, | |
11761 int expected) { | |
11762 v8::Isolate* isolate = CcTest::isolate(); | 11883 v8::Isolate* isolate = CcTest::isolate(); |
11763 v8::HandleScope scope(isolate); | 11884 v8::HandleScope scope(isolate); |
11764 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 11885 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
11765 templ->SetNamedPropertyHandler(getter, 0, 0, 0, 0, v8_str("data")); | 11886 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(getter, 0, 0, 0, 0, |
| 11887 v8_str("data"))); |
11766 LocalContext context; | 11888 LocalContext context; |
11767 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 11889 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
11768 v8::Handle<Value> value = CompileRun(source); | 11890 v8::Handle<Value> value = CompileRun(source); |
11769 CHECK_EQ(expected, value->Int32Value()); | 11891 CHECK_EQ(expected, value->Int32Value()); |
11770 } | 11892 } |
11771 | 11893 |
11772 | 11894 |
11773 static void InterceptorLoadICGetter( | 11895 static void InterceptorLoadICGetter( |
11774 Local<String> name, | 11896 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
11775 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
11776 ApiTestFuzzer::Fuzz(); | 11897 ApiTestFuzzer::Fuzz(); |
11777 v8::Isolate* isolate = CcTest::isolate(); | 11898 v8::Isolate* isolate = CcTest::isolate(); |
11778 CHECK_EQ(isolate, info.GetIsolate()); | 11899 CHECK_EQ(isolate, info.GetIsolate()); |
11779 CHECK_EQ(v8_str("data"), info.Data()); | 11900 CHECK_EQ(v8_str("data"), info.Data()); |
11780 CHECK_EQ(v8_str("x"), name); | 11901 CHECK_EQ(v8_str("x"), name); |
11781 info.GetReturnValue().Set(v8::Integer::New(isolate, 42)); | 11902 info.GetReturnValue().Set(v8::Integer::New(isolate, 42)); |
11782 } | 11903 } |
11783 | 11904 |
11784 | 11905 |
11785 // This test should hit the load IC for the interceptor case. | 11906 // This test should hit the load IC for the interceptor case. |
11786 THREADED_TEST(InterceptorLoadIC) { | 11907 THREADED_TEST(InterceptorLoadIC) { |
11787 CheckInterceptorLoadIC(InterceptorLoadICGetter, | 11908 CheckInterceptorLoadIC(InterceptorLoadICGetter, |
11788 "var result = 0;" | 11909 "var result = 0;" |
11789 "for (var i = 0; i < 1000; i++) {" | 11910 "for (var i = 0; i < 1000; i++) {" |
11790 " result = o.x;" | 11911 " result = o.x;" |
11791 "}", | 11912 "}", |
11792 42); | 11913 42); |
11793 } | 11914 } |
11794 | 11915 |
11795 | 11916 |
11796 // Below go several tests which verify that JITing for various | 11917 // Below go several tests which verify that JITing for various |
11797 // configurations of interceptor and explicit fields works fine | 11918 // configurations of interceptor and explicit fields works fine |
11798 // (those cases are special cased to get better performance). | 11919 // (those cases are special cased to get better performance). |
11799 | 11920 |
11800 static void InterceptorLoadXICGetter( | 11921 static void InterceptorLoadXICGetter( |
11801 Local<String> name, | 11922 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
11802 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
11803 ApiTestFuzzer::Fuzz(); | 11923 ApiTestFuzzer::Fuzz(); |
11804 info.GetReturnValue().Set( | 11924 info.GetReturnValue().Set( |
11805 v8_str("x")->Equals(name) ? | 11925 v8_str("x")->Equals(name) ? |
11806 v8::Handle<v8::Value>(v8::Integer::New(info.GetIsolate(), 42)) : | 11926 v8::Handle<v8::Value>(v8::Integer::New(info.GetIsolate(), 42)) : |
11807 v8::Handle<v8::Value>()); | 11927 v8::Handle<v8::Value>()); |
11808 } | 11928 } |
11809 | 11929 |
11810 | 11930 |
11811 THREADED_TEST(InterceptorLoadICWithFieldOnHolder) { | 11931 THREADED_TEST(InterceptorLoadICWithFieldOnHolder) { |
11812 CheckInterceptorLoadIC(InterceptorLoadXICGetter, | 11932 CheckInterceptorLoadIC(InterceptorLoadXICGetter, |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11907 "for (var i = 0; i < 1000; i++) {" | 12027 "for (var i = 0; i < 1000; i++) {" |
11908 " result += o.y;" | 12028 " result += o.y;" |
11909 "}" | 12029 "}" |
11910 "result;", | 12030 "result;", |
11911 42 * 1000); | 12031 42 * 1000); |
11912 } | 12032 } |
11913 | 12033 |
11914 | 12034 |
11915 static int interceptor_load_not_handled_calls = 0; | 12035 static int interceptor_load_not_handled_calls = 0; |
11916 static void InterceptorLoadNotHandled( | 12036 static void InterceptorLoadNotHandled( |
11917 Local<String> name, | 12037 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
11918 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
11919 ++interceptor_load_not_handled_calls; | 12038 ++interceptor_load_not_handled_calls; |
11920 } | 12039 } |
11921 | 12040 |
11922 | 12041 |
11923 // Test how post-interceptor lookups are done in the non-cacheable | 12042 // Test how post-interceptor lookups are done in the non-cacheable |
11924 // case: the interceptor should not be invoked during this lookup. | 12043 // case: the interceptor should not be invoked during this lookup. |
11925 THREADED_TEST(InterceptorLoadICPostInterceptor) { | 12044 THREADED_TEST(InterceptorLoadICPostInterceptor) { |
11926 interceptor_load_not_handled_calls = 0; | 12045 interceptor_load_not_handled_calls = 0; |
11927 CheckInterceptorLoadIC(InterceptorLoadNotHandled, | 12046 CheckInterceptorLoadIC(InterceptorLoadNotHandled, |
11928 "receiver = new Object();" | 12047 "receiver = new Object();" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11969 Local<Value> value, | 12088 Local<Value> value, |
11970 const v8::PropertyCallbackInfo<void>& info) { | 12089 const v8::PropertyCallbackInfo<void>& info) { |
11971 Local<Object>::Cast(info.This())->ForceSet(name, value); | 12090 Local<Object>::Cast(info.This())->ForceSet(name, value); |
11972 } | 12091 } |
11973 | 12092 |
11974 | 12093 |
11975 THREADED_TEST(InterceptorLoadICWithCallbackOnHolder) { | 12094 THREADED_TEST(InterceptorLoadICWithCallbackOnHolder) { |
11976 v8::Isolate* isolate = CcTest::isolate(); | 12095 v8::Isolate* isolate = CcTest::isolate(); |
11977 v8::HandleScope scope(isolate); | 12096 v8::HandleScope scope(isolate); |
11978 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 12097 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
11979 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); | 12098 templ->SetHandler( |
| 12099 v8::NamedPropertyHandlerConfiguration(InterceptorLoadXICGetter)); |
11980 templ->SetAccessor(v8_str("y"), Return239Callback); | 12100 templ->SetAccessor(v8_str("y"), Return239Callback); |
11981 LocalContext context; | 12101 LocalContext context; |
11982 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 12102 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
11983 | 12103 |
11984 // Check the case when receiver and interceptor's holder | 12104 // Check the case when receiver and interceptor's holder |
11985 // are the same objects. | 12105 // are the same objects. |
11986 v8::Handle<Value> value = CompileRun( | 12106 v8::Handle<Value> value = CompileRun( |
11987 "var result = 0;" | 12107 "var result = 0;" |
11988 "for (var i = 0; i < 7; i++) {" | 12108 "for (var i = 0; i < 7; i++) {" |
11989 " result = o.y;" | 12109 " result = o.y;" |
11990 "}"); | 12110 "}"); |
11991 CHECK_EQ(239, value->Int32Value()); | 12111 CHECK_EQ(239, value->Int32Value()); |
11992 | 12112 |
11993 // Check the case when interceptor's holder is in proto chain | 12113 // Check the case when interceptor's holder is in proto chain |
11994 // of receiver. | 12114 // of receiver. |
11995 value = CompileRun( | 12115 value = CompileRun( |
11996 "r = { __proto__: o };" | 12116 "r = { __proto__: o };" |
11997 "var result = 0;" | 12117 "var result = 0;" |
11998 "for (var i = 0; i < 7; i++) {" | 12118 "for (var i = 0; i < 7; i++) {" |
11999 " result = r.y;" | 12119 " result = r.y;" |
12000 "}"); | 12120 "}"); |
12001 CHECK_EQ(239, value->Int32Value()); | 12121 CHECK_EQ(239, value->Int32Value()); |
12002 } | 12122 } |
12003 | 12123 |
12004 | 12124 |
12005 THREADED_TEST(InterceptorLoadICWithCallbackOnProto) { | 12125 THREADED_TEST(InterceptorLoadICWithCallbackOnProto) { |
12006 v8::Isolate* isolate = CcTest::isolate(); | 12126 v8::Isolate* isolate = CcTest::isolate(); |
12007 v8::HandleScope scope(isolate); | 12127 v8::HandleScope scope(isolate); |
12008 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); | 12128 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); |
12009 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); | 12129 templ_o->SetHandler( |
| 12130 v8::NamedPropertyHandlerConfiguration(InterceptorLoadXICGetter)); |
12010 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(isolate); | 12131 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(isolate); |
12011 templ_p->SetAccessor(v8_str("y"), Return239Callback); | 12132 templ_p->SetAccessor(v8_str("y"), Return239Callback); |
12012 | 12133 |
12013 LocalContext context; | 12134 LocalContext context; |
12014 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); | 12135 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); |
12015 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); | 12136 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); |
12016 | 12137 |
12017 // Check the case when receiver and interceptor's holder | 12138 // Check the case when receiver and interceptor's holder |
12018 // are the same objects. | 12139 // are the same objects. |
12019 v8::Handle<Value> value = CompileRun( | 12140 v8::Handle<Value> value = CompileRun( |
(...skipping 13 matching lines...) Expand all Loading... |
12033 " result = r.x + r.y;" | 12154 " result = r.x + r.y;" |
12034 "}"); | 12155 "}"); |
12035 CHECK_EQ(239 + 42, value->Int32Value()); | 12156 CHECK_EQ(239 + 42, value->Int32Value()); |
12036 } | 12157 } |
12037 | 12158 |
12038 | 12159 |
12039 THREADED_TEST(InterceptorLoadICForCallbackWithOverride) { | 12160 THREADED_TEST(InterceptorLoadICForCallbackWithOverride) { |
12040 v8::Isolate* isolate = CcTest::isolate(); | 12161 v8::Isolate* isolate = CcTest::isolate(); |
12041 v8::HandleScope scope(isolate); | 12162 v8::HandleScope scope(isolate); |
12042 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 12163 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12043 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); | 12164 templ->SetHandler( |
| 12165 v8::NamedPropertyHandlerConfiguration(InterceptorLoadXICGetter)); |
12044 templ->SetAccessor(v8_str("y"), Return239Callback); | 12166 templ->SetAccessor(v8_str("y"), Return239Callback); |
12045 | 12167 |
12046 LocalContext context; | 12168 LocalContext context; |
12047 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 12169 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
12048 | 12170 |
12049 v8::Handle<Value> value = CompileRun( | 12171 v8::Handle<Value> value = CompileRun( |
12050 "fst = new Object(); fst.__proto__ = o;" | 12172 "fst = new Object(); fst.__proto__ = o;" |
12051 "snd = new Object(); snd.__proto__ = fst;" | 12173 "snd = new Object(); snd.__proto__ = fst;" |
12052 "var result1 = 0;" | 12174 "var result1 = 0;" |
12053 "for (var i = 0; i < 7; i++) {" | 12175 "for (var i = 0; i < 7; i++) {" |
12054 " result1 = snd.x;" | 12176 " result1 = snd.x;" |
12055 "}" | 12177 "}" |
12056 "fst.x = 239;" | 12178 "fst.x = 239;" |
12057 "var result = 0;" | 12179 "var result = 0;" |
12058 "for (var i = 0; i < 7; i++) {" | 12180 "for (var i = 0; i < 7; i++) {" |
12059 " result = snd.x;" | 12181 " result = snd.x;" |
12060 "}" | 12182 "}" |
12061 "result + result1"); | 12183 "result + result1"); |
12062 CHECK_EQ(239 + 42, value->Int32Value()); | 12184 CHECK_EQ(239 + 42, value->Int32Value()); |
12063 } | 12185 } |
12064 | 12186 |
12065 | 12187 |
12066 // Test the case when we stored callback into | 12188 // Test the case when we stored callback into |
12067 // a stub, but interceptor produced value on its own. | 12189 // a stub, but interceptor produced value on its own. |
12068 THREADED_TEST(InterceptorLoadICCallbackNotNeeded) { | 12190 THREADED_TEST(InterceptorLoadICCallbackNotNeeded) { |
12069 v8::Isolate* isolate = CcTest::isolate(); | 12191 v8::Isolate* isolate = CcTest::isolate(); |
12070 v8::HandleScope scope(isolate); | 12192 v8::HandleScope scope(isolate); |
12071 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); | 12193 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); |
12072 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); | 12194 templ_o->SetHandler( |
| 12195 v8::NamedPropertyHandlerConfiguration(InterceptorLoadXICGetter)); |
12073 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(isolate); | 12196 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(isolate); |
12074 templ_p->SetAccessor(v8_str("y"), Return239Callback); | 12197 templ_p->SetAccessor(v8_str("y"), Return239Callback); |
12075 | 12198 |
12076 LocalContext context; | 12199 LocalContext context; |
12077 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); | 12200 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); |
12078 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); | 12201 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); |
12079 | 12202 |
12080 v8::Handle<Value> value = CompileRun( | 12203 v8::Handle<Value> value = CompileRun( |
12081 "o.__proto__ = p;" | 12204 "o.__proto__ = p;" |
12082 "for (var i = 0; i < 7; i++) {" | 12205 "for (var i = 0; i < 7; i++) {" |
12083 " o.x;" | 12206 " o.x;" |
12084 // Now it should be ICed and keep a reference to x defined on p | 12207 // Now it should be ICed and keep a reference to x defined on p |
12085 "}" | 12208 "}" |
12086 "var result = 0;" | 12209 "var result = 0;" |
12087 "for (var i = 0; i < 7; i++) {" | 12210 "for (var i = 0; i < 7; i++) {" |
12088 " result += o.x;" | 12211 " result += o.x;" |
12089 "}" | 12212 "}" |
12090 "result"); | 12213 "result"); |
12091 CHECK_EQ(42 * 7, value->Int32Value()); | 12214 CHECK_EQ(42 * 7, value->Int32Value()); |
12092 } | 12215 } |
12093 | 12216 |
12094 | 12217 |
12095 // Test the case when we stored callback into | 12218 // Test the case when we stored callback into |
12096 // a stub, but it got invalidated later on. | 12219 // a stub, but it got invalidated later on. |
12097 THREADED_TEST(InterceptorLoadICInvalidatedCallback) { | 12220 THREADED_TEST(InterceptorLoadICInvalidatedCallback) { |
12098 v8::Isolate* isolate = CcTest::isolate(); | 12221 v8::Isolate* isolate = CcTest::isolate(); |
12099 v8::HandleScope scope(isolate); | 12222 v8::HandleScope scope(isolate); |
12100 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); | 12223 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); |
12101 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); | 12224 templ_o->SetHandler( |
| 12225 v8::NamedPropertyHandlerConfiguration(InterceptorLoadXICGetter)); |
12102 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(isolate); | 12226 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(isolate); |
12103 templ_p->SetAccessor(v8_str("y"), Return239Callback, SetOnThis); | 12227 templ_p->SetAccessor(v8_str("y"), Return239Callback, SetOnThis); |
12104 | 12228 |
12105 LocalContext context; | 12229 LocalContext context; |
12106 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); | 12230 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); |
12107 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); | 12231 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); |
12108 | 12232 |
12109 v8::Handle<Value> value = CompileRun( | 12233 v8::Handle<Value> value = CompileRun( |
12110 "inbetween = new Object();" | 12234 "inbetween = new Object();" |
12111 "o.__proto__ = inbetween;" | 12235 "o.__proto__ = inbetween;" |
(...skipping 12 matching lines...) Expand all Loading... |
12124 } | 12248 } |
12125 | 12249 |
12126 | 12250 |
12127 // Test the case when we stored callback into | 12251 // Test the case when we stored callback into |
12128 // a stub, but it got invalidated later on due to override on | 12252 // a stub, but it got invalidated later on due to override on |
12129 // global object which is between interceptor and callbacks' holders. | 12253 // global object which is between interceptor and callbacks' holders. |
12130 THREADED_TEST(InterceptorLoadICInvalidatedCallbackViaGlobal) { | 12254 THREADED_TEST(InterceptorLoadICInvalidatedCallbackViaGlobal) { |
12131 v8::Isolate* isolate = CcTest::isolate(); | 12255 v8::Isolate* isolate = CcTest::isolate(); |
12132 v8::HandleScope scope(isolate); | 12256 v8::HandleScope scope(isolate); |
12133 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); | 12257 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); |
12134 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); | 12258 templ_o->SetHandler( |
| 12259 v8::NamedPropertyHandlerConfiguration(InterceptorLoadXICGetter)); |
12135 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(isolate); | 12260 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(isolate); |
12136 templ_p->SetAccessor(v8_str("y"), Return239Callback, SetOnThis); | 12261 templ_p->SetAccessor(v8_str("y"), Return239Callback, SetOnThis); |
12137 | 12262 |
12138 LocalContext context; | 12263 LocalContext context; |
12139 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); | 12264 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); |
12140 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); | 12265 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); |
12141 | 12266 |
12142 v8::Handle<Value> value = CompileRun( | 12267 v8::Handle<Value> value = CompileRun( |
12143 "o.__proto__ = this;" | 12268 "o.__proto__ = this;" |
12144 "this.__proto__ = p;" | 12269 "this.__proto__ = p;" |
12145 "for (var i = 0; i < 10; i++) {" | 12270 "for (var i = 0; i < 10; i++) {" |
12146 " if (o.y != 239) throw 'oops: ' + o.y;" | 12271 " if (o.y != 239) throw 'oops: ' + o.y;" |
12147 // Now it should be ICed and keep a reference to y defined on p | 12272 // Now it should be ICed and keep a reference to y defined on p |
12148 "}" | 12273 "}" |
12149 "this.y = 42;" | 12274 "this.y = 42;" |
12150 "var result = 0;" | 12275 "var result = 0;" |
12151 "for (var i = 0; i < 10; i++) {" | 12276 "for (var i = 0; i < 10; i++) {" |
12152 " result += o.y;" | 12277 " result += o.y;" |
12153 "}" | 12278 "}" |
12154 "result"); | 12279 "result"); |
12155 CHECK_EQ(42 * 10, value->Int32Value()); | 12280 CHECK_EQ(42 * 10, value->Int32Value()); |
12156 } | 12281 } |
12157 | 12282 |
12158 | 12283 |
12159 static void InterceptorLoadICGetter0( | 12284 static void InterceptorLoadICGetter0( |
12160 Local<String> name, | 12285 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
12161 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
12162 ApiTestFuzzer::Fuzz(); | 12286 ApiTestFuzzer::Fuzz(); |
12163 CHECK(v8_str("x")->Equals(name)); | 12287 CHECK(v8_str("x")->Equals(name)); |
12164 info.GetReturnValue().Set(v8::Integer::New(info.GetIsolate(), 0)); | 12288 info.GetReturnValue().Set(v8::Integer::New(info.GetIsolate(), 0)); |
12165 } | 12289 } |
12166 | 12290 |
12167 | 12291 |
12168 THREADED_TEST(InterceptorReturningZero) { | 12292 THREADED_TEST(InterceptorReturningZero) { |
12169 CheckInterceptorLoadIC(InterceptorLoadICGetter0, | 12293 CheckInterceptorLoadIC(InterceptorLoadICGetter0, |
12170 "o.x == undefined ? 1 : 0", | 12294 "o.x == undefined ? 1 : 0", |
12171 0); | 12295 0); |
12172 } | 12296 } |
12173 | 12297 |
12174 | 12298 |
12175 static void InterceptorStoreICSetter( | 12299 static void InterceptorStoreICSetter( |
12176 Local<String> key, | 12300 Local<Name> key, Local<Value> value, |
12177 Local<Value> value, | |
12178 const v8::PropertyCallbackInfo<v8::Value>& info) { | 12301 const v8::PropertyCallbackInfo<v8::Value>& info) { |
12179 CHECK(v8_str("x")->Equals(key)); | 12302 CHECK(v8_str("x")->Equals(key)); |
12180 CHECK_EQ(42, value->Int32Value()); | 12303 CHECK_EQ(42, value->Int32Value()); |
12181 info.GetReturnValue().Set(value); | 12304 info.GetReturnValue().Set(value); |
12182 } | 12305 } |
12183 | 12306 |
12184 | 12307 |
12185 // This test should hit the store IC for the interceptor case. | 12308 // This test should hit the store IC for the interceptor case. |
12186 THREADED_TEST(InterceptorStoreIC) { | 12309 THREADED_TEST(InterceptorStoreIC) { |
12187 v8::Isolate* isolate = CcTest::isolate(); | 12310 v8::Isolate* isolate = CcTest::isolate(); |
12188 v8::HandleScope scope(isolate); | 12311 v8::HandleScope scope(isolate); |
12189 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 12312 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12190 templ->SetNamedPropertyHandler(InterceptorLoadICGetter, | 12313 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
12191 InterceptorStoreICSetter, | 12314 InterceptorLoadICGetter, InterceptorStoreICSetter, 0, 0, 0, |
12192 0, 0, 0, v8_str("data")); | 12315 v8_str("data"))); |
12193 LocalContext context; | 12316 LocalContext context; |
12194 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 12317 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
12195 CompileRun( | 12318 CompileRun( |
12196 "for (var i = 0; i < 1000; i++) {" | 12319 "for (var i = 0; i < 1000; i++) {" |
12197 " o.x = 42;" | 12320 " o.x = 42;" |
12198 "}"); | 12321 "}"); |
12199 } | 12322 } |
12200 | 12323 |
12201 | 12324 |
12202 THREADED_TEST(InterceptorStoreICWithNoSetter) { | 12325 THREADED_TEST(InterceptorStoreICWithNoSetter) { |
12203 v8::Isolate* isolate = CcTest::isolate(); | 12326 v8::Isolate* isolate = CcTest::isolate(); |
12204 v8::HandleScope scope(isolate); | 12327 v8::HandleScope scope(isolate); |
12205 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 12328 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12206 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); | 12329 templ->SetHandler( |
| 12330 v8::NamedPropertyHandlerConfiguration(InterceptorLoadXICGetter)); |
12207 LocalContext context; | 12331 LocalContext context; |
12208 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 12332 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
12209 v8::Handle<Value> value = CompileRun( | 12333 v8::Handle<Value> value = CompileRun( |
12210 "for (var i = 0; i < 1000; i++) {" | 12334 "for (var i = 0; i < 1000; i++) {" |
12211 " o.y = 239;" | 12335 " o.y = 239;" |
12212 "}" | 12336 "}" |
12213 "42 + o.y"); | 12337 "42 + o.y"); |
12214 CHECK_EQ(239 + 42, value->Int32Value()); | 12338 CHECK_EQ(239 + 42, value->Int32Value()); |
12215 } | 12339 } |
12216 | 12340 |
12217 | 12341 |
12218 | 12342 |
12219 | 12343 |
12220 v8::Handle<Value> call_ic_function; | 12344 v8::Handle<Value> call_ic_function; |
12221 v8::Handle<Value> call_ic_function2; | 12345 v8::Handle<Value> call_ic_function2; |
12222 v8::Handle<Value> call_ic_function3; | 12346 v8::Handle<Value> call_ic_function3; |
12223 | 12347 |
12224 static void InterceptorCallICGetter( | 12348 static void InterceptorCallICGetter( |
12225 Local<String> name, | 12349 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
12226 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
12227 ApiTestFuzzer::Fuzz(); | 12350 ApiTestFuzzer::Fuzz(); |
12228 CHECK(v8_str("x")->Equals(name)); | 12351 CHECK(v8_str("x")->Equals(name)); |
12229 info.GetReturnValue().Set(call_ic_function); | 12352 info.GetReturnValue().Set(call_ic_function); |
12230 } | 12353 } |
12231 | 12354 |
12232 | 12355 |
12233 // This test should hit the call IC for the interceptor case. | 12356 // This test should hit the call IC for the interceptor case. |
12234 THREADED_TEST(InterceptorCallIC) { | 12357 THREADED_TEST(InterceptorCallIC) { |
12235 v8::Isolate* isolate = CcTest::isolate(); | 12358 v8::Isolate* isolate = CcTest::isolate(); |
12236 v8::HandleScope scope(isolate); | 12359 v8::HandleScope scope(isolate); |
12237 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 12360 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12238 templ->SetNamedPropertyHandler(InterceptorCallICGetter); | 12361 templ->SetHandler( |
| 12362 v8::NamedPropertyHandlerConfiguration(InterceptorCallICGetter)); |
12239 LocalContext context; | 12363 LocalContext context; |
12240 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 12364 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
12241 call_ic_function = | 12365 call_ic_function = |
12242 v8_compile("function f(x) { return x + 1; }; f")->Run(); | 12366 v8_compile("function f(x) { return x + 1; }; f")->Run(); |
12243 v8::Handle<Value> value = CompileRun( | 12367 v8::Handle<Value> value = CompileRun( |
12244 "var result = 0;" | 12368 "var result = 0;" |
12245 "for (var i = 0; i < 1000; i++) {" | 12369 "for (var i = 0; i < 1000; i++) {" |
12246 " result = o.x(41);" | 12370 " result = o.x(41);" |
12247 "}"); | 12371 "}"); |
12248 CHECK_EQ(42, value->Int32Value()); | 12372 CHECK_EQ(42, value->Int32Value()); |
12249 } | 12373 } |
12250 | 12374 |
12251 | 12375 |
12252 // This test checks that if interceptor doesn't provide | 12376 // This test checks that if interceptor doesn't provide |
12253 // a value, we can fetch regular value. | 12377 // a value, we can fetch regular value. |
12254 THREADED_TEST(InterceptorCallICSeesOthers) { | 12378 THREADED_TEST(InterceptorCallICSeesOthers) { |
12255 v8::Isolate* isolate = CcTest::isolate(); | 12379 v8::Isolate* isolate = CcTest::isolate(); |
12256 v8::HandleScope scope(isolate); | 12380 v8::HandleScope scope(isolate); |
12257 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 12381 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12258 templ->SetNamedPropertyHandler(NoBlockGetterX); | 12382 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(NoBlockGetterX)); |
12259 LocalContext context; | 12383 LocalContext context; |
12260 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 12384 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
12261 v8::Handle<Value> value = CompileRun( | 12385 v8::Handle<Value> value = CompileRun( |
12262 "o.x = function f(x) { return x + 1; };" | 12386 "o.x = function f(x) { return x + 1; };" |
12263 "var result = 0;" | 12387 "var result = 0;" |
12264 "for (var i = 0; i < 7; i++) {" | 12388 "for (var i = 0; i < 7; i++) {" |
12265 " result = o.x(41);" | 12389 " result = o.x(41);" |
12266 "}"); | 12390 "}"); |
12267 CHECK_EQ(42, value->Int32Value()); | 12391 CHECK_EQ(42, value->Int32Value()); |
12268 } | 12392 } |
12269 | 12393 |
12270 | 12394 |
12271 static v8::Handle<Value> call_ic_function4; | 12395 static v8::Handle<Value> call_ic_function4; |
12272 static void InterceptorCallICGetter4( | 12396 static void InterceptorCallICGetter4( |
12273 Local<String> name, | 12397 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
12274 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
12275 ApiTestFuzzer::Fuzz(); | 12398 ApiTestFuzzer::Fuzz(); |
12276 CHECK(v8_str("x")->Equals(name)); | 12399 CHECK(v8_str("x")->Equals(name)); |
12277 info.GetReturnValue().Set(call_ic_function4); | 12400 info.GetReturnValue().Set(call_ic_function4); |
12278 } | 12401 } |
12279 | 12402 |
12280 | 12403 |
12281 // This test checks that if interceptor provides a function, | 12404 // This test checks that if interceptor provides a function, |
12282 // even if we cached shadowed variant, interceptor's function | 12405 // even if we cached shadowed variant, interceptor's function |
12283 // is invoked | 12406 // is invoked |
12284 THREADED_TEST(InterceptorCallICCacheableNotNeeded) { | 12407 THREADED_TEST(InterceptorCallICCacheableNotNeeded) { |
12285 v8::Isolate* isolate = CcTest::isolate(); | 12408 v8::Isolate* isolate = CcTest::isolate(); |
12286 v8::HandleScope scope(isolate); | 12409 v8::HandleScope scope(isolate); |
12287 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 12410 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12288 templ->SetNamedPropertyHandler(InterceptorCallICGetter4); | 12411 templ->SetHandler( |
| 12412 v8::NamedPropertyHandlerConfiguration(InterceptorCallICGetter4)); |
12289 LocalContext context; | 12413 LocalContext context; |
12290 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 12414 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
12291 call_ic_function4 = | 12415 call_ic_function4 = |
12292 v8_compile("function f(x) { return x - 1; }; f")->Run(); | 12416 v8_compile("function f(x) { return x - 1; }; f")->Run(); |
12293 v8::Handle<Value> value = CompileRun( | 12417 v8::Handle<Value> value = CompileRun( |
12294 "Object.getPrototypeOf(o).x = function(x) { return x + 1; };" | 12418 "Object.getPrototypeOf(o).x = function(x) { return x + 1; };" |
12295 "var result = 0;" | 12419 "var result = 0;" |
12296 "for (var i = 0; i < 1000; i++) {" | 12420 "for (var i = 0; i < 1000; i++) {" |
12297 " result = o.x(42);" | 12421 " result = o.x(42);" |
12298 "}"); | 12422 "}"); |
12299 CHECK_EQ(41, value->Int32Value()); | 12423 CHECK_EQ(41, value->Int32Value()); |
12300 } | 12424 } |
12301 | 12425 |
12302 | 12426 |
12303 // Test the case when we stored cacheable lookup into | 12427 // Test the case when we stored cacheable lookup into |
12304 // a stub, but it got invalidated later on | 12428 // a stub, but it got invalidated later on |
12305 THREADED_TEST(InterceptorCallICInvalidatedCacheable) { | 12429 THREADED_TEST(InterceptorCallICInvalidatedCacheable) { |
12306 v8::Isolate* isolate = CcTest::isolate(); | 12430 v8::Isolate* isolate = CcTest::isolate(); |
12307 v8::HandleScope scope(isolate); | 12431 v8::HandleScope scope(isolate); |
12308 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 12432 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12309 templ->SetNamedPropertyHandler(NoBlockGetterX); | 12433 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(NoBlockGetterX)); |
12310 LocalContext context; | 12434 LocalContext context; |
12311 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 12435 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
12312 v8::Handle<Value> value = CompileRun( | 12436 v8::Handle<Value> value = CompileRun( |
12313 "proto1 = new Object();" | 12437 "proto1 = new Object();" |
12314 "proto2 = new Object();" | 12438 "proto2 = new Object();" |
12315 "o.__proto__ = proto1;" | 12439 "o.__proto__ = proto1;" |
12316 "proto1.__proto__ = proto2;" | 12440 "proto1.__proto__ = proto2;" |
12317 "proto2.y = function(x) { return x + 1; };" | 12441 "proto2.y = function(x) { return x + 1; };" |
12318 // Invoke it many times to compile a stub | 12442 // Invoke it many times to compile a stub |
12319 "for (var i = 0; i < 7; i++) {" | 12443 "for (var i = 0; i < 7; i++) {" |
12320 " o.y(42);" | 12444 " o.y(42);" |
12321 "}" | 12445 "}" |
12322 "proto1.y = function(x) { return x - 1; };" | 12446 "proto1.y = function(x) { return x - 1; };" |
12323 "var result = 0;" | 12447 "var result = 0;" |
12324 "for (var i = 0; i < 7; i++) {" | 12448 "for (var i = 0; i < 7; i++) {" |
12325 " result += o.y(42);" | 12449 " result += o.y(42);" |
12326 "}"); | 12450 "}"); |
12327 CHECK_EQ(41 * 7, value->Int32Value()); | 12451 CHECK_EQ(41 * 7, value->Int32Value()); |
12328 } | 12452 } |
12329 | 12453 |
12330 | 12454 |
12331 // This test checks that if interceptor doesn't provide a function, | 12455 // This test checks that if interceptor doesn't provide a function, |
12332 // cached constant function is used | 12456 // cached constant function is used |
12333 THREADED_TEST(InterceptorCallICConstantFunctionUsed) { | 12457 THREADED_TEST(InterceptorCallICConstantFunctionUsed) { |
12334 v8::Isolate* isolate = CcTest::isolate(); | 12458 v8::Isolate* isolate = CcTest::isolate(); |
12335 v8::HandleScope scope(isolate); | 12459 v8::HandleScope scope(isolate); |
12336 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 12460 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12337 templ->SetNamedPropertyHandler(NoBlockGetterX); | 12461 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(NoBlockGetterX)); |
12338 LocalContext context; | 12462 LocalContext context; |
12339 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 12463 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
12340 v8::Handle<Value> value = CompileRun( | 12464 v8::Handle<Value> value = CompileRun( |
12341 "function inc(x) { return x + 1; };" | 12465 "function inc(x) { return x + 1; };" |
12342 "inc(1);" | 12466 "inc(1);" |
12343 "o.x = inc;" | 12467 "o.x = inc;" |
12344 "var result = 0;" | 12468 "var result = 0;" |
12345 "for (var i = 0; i < 1000; i++) {" | 12469 "for (var i = 0; i < 1000; i++) {" |
12346 " result = o.x(42);" | 12470 " result = o.x(42);" |
12347 "}"); | 12471 "}"); |
12348 CHECK_EQ(43, value->Int32Value()); | 12472 CHECK_EQ(43, value->Int32Value()); |
12349 } | 12473 } |
12350 | 12474 |
12351 | 12475 |
12352 static v8::Handle<Value> call_ic_function5; | 12476 static v8::Handle<Value> call_ic_function5; |
12353 static void InterceptorCallICGetter5( | 12477 static void InterceptorCallICGetter5( |
12354 Local<String> name, | 12478 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
12355 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
12356 ApiTestFuzzer::Fuzz(); | 12479 ApiTestFuzzer::Fuzz(); |
12357 if (v8_str("x")->Equals(name)) | 12480 if (v8_str("x")->Equals(name)) |
12358 info.GetReturnValue().Set(call_ic_function5); | 12481 info.GetReturnValue().Set(call_ic_function5); |
12359 } | 12482 } |
12360 | 12483 |
12361 | 12484 |
12362 // This test checks that if interceptor provides a function, | 12485 // This test checks that if interceptor provides a function, |
12363 // even if we cached constant function, interceptor's function | 12486 // even if we cached constant function, interceptor's function |
12364 // is invoked | 12487 // is invoked |
12365 THREADED_TEST(InterceptorCallICConstantFunctionNotNeeded) { | 12488 THREADED_TEST(InterceptorCallICConstantFunctionNotNeeded) { |
12366 v8::Isolate* isolate = CcTest::isolate(); | 12489 v8::Isolate* isolate = CcTest::isolate(); |
12367 v8::HandleScope scope(isolate); | 12490 v8::HandleScope scope(isolate); |
12368 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 12491 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12369 templ->SetNamedPropertyHandler(InterceptorCallICGetter5); | 12492 templ->SetHandler( |
| 12493 v8::NamedPropertyHandlerConfiguration(InterceptorCallICGetter5)); |
12370 LocalContext context; | 12494 LocalContext context; |
12371 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 12495 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
12372 call_ic_function5 = | 12496 call_ic_function5 = |
12373 v8_compile("function f(x) { return x - 1; }; f")->Run(); | 12497 v8_compile("function f(x) { return x - 1; }; f")->Run(); |
12374 v8::Handle<Value> value = CompileRun( | 12498 v8::Handle<Value> value = CompileRun( |
12375 "function inc(x) { return x + 1; };" | 12499 "function inc(x) { return x + 1; };" |
12376 "inc(1);" | 12500 "inc(1);" |
12377 "o.x = inc;" | 12501 "o.x = inc;" |
12378 "var result = 0;" | 12502 "var result = 0;" |
12379 "for (var i = 0; i < 1000; i++) {" | 12503 "for (var i = 0; i < 1000; i++) {" |
12380 " result = o.x(42);" | 12504 " result = o.x(42);" |
12381 "}"); | 12505 "}"); |
12382 CHECK_EQ(41, value->Int32Value()); | 12506 CHECK_EQ(41, value->Int32Value()); |
12383 } | 12507 } |
12384 | 12508 |
12385 | 12509 |
12386 static v8::Handle<Value> call_ic_function6; | 12510 static v8::Handle<Value> call_ic_function6; |
12387 static void InterceptorCallICGetter6( | 12511 static void InterceptorCallICGetter6( |
12388 Local<String> name, | 12512 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
12389 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
12390 ApiTestFuzzer::Fuzz(); | 12513 ApiTestFuzzer::Fuzz(); |
12391 if (v8_str("x")->Equals(name)) | 12514 if (v8_str("x")->Equals(name)) |
12392 info.GetReturnValue().Set(call_ic_function6); | 12515 info.GetReturnValue().Set(call_ic_function6); |
12393 } | 12516 } |
12394 | 12517 |
12395 | 12518 |
12396 // Same test as above, except the code is wrapped in a function | 12519 // Same test as above, except the code is wrapped in a function |
12397 // to test the optimized compiler. | 12520 // to test the optimized compiler. |
12398 THREADED_TEST(InterceptorCallICConstantFunctionNotNeededWrapped) { | 12521 THREADED_TEST(InterceptorCallICConstantFunctionNotNeededWrapped) { |
12399 i::FLAG_allow_natives_syntax = true; | 12522 i::FLAG_allow_natives_syntax = true; |
12400 v8::Isolate* isolate = CcTest::isolate(); | 12523 v8::Isolate* isolate = CcTest::isolate(); |
12401 v8::HandleScope scope(isolate); | 12524 v8::HandleScope scope(isolate); |
12402 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 12525 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12403 templ->SetNamedPropertyHandler(InterceptorCallICGetter6); | 12526 templ->SetHandler( |
| 12527 v8::NamedPropertyHandlerConfiguration(InterceptorCallICGetter6)); |
12404 LocalContext context; | 12528 LocalContext context; |
12405 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 12529 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
12406 call_ic_function6 = | 12530 call_ic_function6 = |
12407 v8_compile("function f(x) { return x - 1; }; f")->Run(); | 12531 v8_compile("function f(x) { return x - 1; }; f")->Run(); |
12408 v8::Handle<Value> value = CompileRun( | 12532 v8::Handle<Value> value = CompileRun( |
12409 "function inc(x) { return x + 1; };" | 12533 "function inc(x) { return x + 1; };" |
12410 "inc(1);" | 12534 "inc(1);" |
12411 "o.x = inc;" | 12535 "o.x = inc;" |
12412 "function test() {" | 12536 "function test() {" |
12413 " var result = 0;" | 12537 " var result = 0;" |
(...skipping 10 matching lines...) Expand all Loading... |
12424 CHECK_EQ(41, value->Int32Value()); | 12548 CHECK_EQ(41, value->Int32Value()); |
12425 } | 12549 } |
12426 | 12550 |
12427 | 12551 |
12428 // Test the case when we stored constant function into | 12552 // Test the case when we stored constant function into |
12429 // a stub, but it got invalidated later on | 12553 // a stub, but it got invalidated later on |
12430 THREADED_TEST(InterceptorCallICInvalidatedConstantFunction) { | 12554 THREADED_TEST(InterceptorCallICInvalidatedConstantFunction) { |
12431 v8::Isolate* isolate = CcTest::isolate(); | 12555 v8::Isolate* isolate = CcTest::isolate(); |
12432 v8::HandleScope scope(isolate); | 12556 v8::HandleScope scope(isolate); |
12433 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 12557 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12434 templ->SetNamedPropertyHandler(NoBlockGetterX); | 12558 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(NoBlockGetterX)); |
12435 LocalContext context; | 12559 LocalContext context; |
12436 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 12560 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
12437 v8::Handle<Value> value = CompileRun( | 12561 v8::Handle<Value> value = CompileRun( |
12438 "function inc(x) { return x + 1; };" | 12562 "function inc(x) { return x + 1; };" |
12439 "inc(1);" | 12563 "inc(1);" |
12440 "proto1 = new Object();" | 12564 "proto1 = new Object();" |
12441 "proto2 = new Object();" | 12565 "proto2 = new Object();" |
12442 "o.__proto__ = proto1;" | 12566 "o.__proto__ = proto1;" |
12443 "proto1.__proto__ = proto2;" | 12567 "proto1.__proto__ = proto2;" |
12444 "proto2.y = inc;" | 12568 "proto2.y = inc;" |
(...skipping 10 matching lines...) Expand all Loading... |
12455 } | 12579 } |
12456 | 12580 |
12457 | 12581 |
12458 // Test the case when we stored constant function into | 12582 // Test the case when we stored constant function into |
12459 // a stub, but it got invalidated later on due to override on | 12583 // a stub, but it got invalidated later on due to override on |
12460 // global object which is between interceptor and constant function' holders. | 12584 // global object which is between interceptor and constant function' holders. |
12461 THREADED_TEST(InterceptorCallICInvalidatedConstantFunctionViaGlobal) { | 12585 THREADED_TEST(InterceptorCallICInvalidatedConstantFunctionViaGlobal) { |
12462 v8::Isolate* isolate = CcTest::isolate(); | 12586 v8::Isolate* isolate = CcTest::isolate(); |
12463 v8::HandleScope scope(isolate); | 12587 v8::HandleScope scope(isolate); |
12464 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 12588 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12465 templ->SetNamedPropertyHandler(NoBlockGetterX); | 12589 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(NoBlockGetterX)); |
12466 LocalContext context; | 12590 LocalContext context; |
12467 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 12591 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
12468 v8::Handle<Value> value = CompileRun( | 12592 v8::Handle<Value> value = CompileRun( |
12469 "function inc(x) { return x + 1; };" | 12593 "function inc(x) { return x + 1; };" |
12470 "inc(1);" | 12594 "inc(1);" |
12471 "o.__proto__ = this;" | 12595 "o.__proto__ = this;" |
12472 "this.__proto__.y = inc;" | 12596 "this.__proto__.y = inc;" |
12473 // Invoke it many times to compile a stub | 12597 // Invoke it many times to compile a stub |
12474 "for (var i = 0; i < 7; i++) {" | 12598 "for (var i = 0; i < 7; i++) {" |
12475 " if (o.y(42) != 43) throw 'oops: ' + o.y(42);" | 12599 " if (o.y(42) != 43) throw 'oops: ' + o.y(42);" |
12476 "}" | 12600 "}" |
12477 "this.y = function(x) { return x - 1; };" | 12601 "this.y = function(x) { return x - 1; };" |
12478 "var result = 0;" | 12602 "var result = 0;" |
12479 "for (var i = 0; i < 7; i++) {" | 12603 "for (var i = 0; i < 7; i++) {" |
12480 " result += o.y(42);" | 12604 " result += o.y(42);" |
12481 "}"); | 12605 "}"); |
12482 CHECK_EQ(41 * 7, value->Int32Value()); | 12606 CHECK_EQ(41 * 7, value->Int32Value()); |
12483 } | 12607 } |
12484 | 12608 |
12485 | 12609 |
12486 // Test the case when actual function to call sits on global object. | 12610 // Test the case when actual function to call sits on global object. |
12487 THREADED_TEST(InterceptorCallICCachedFromGlobal) { | 12611 THREADED_TEST(InterceptorCallICCachedFromGlobal) { |
12488 v8::Isolate* isolate = CcTest::isolate(); | 12612 v8::Isolate* isolate = CcTest::isolate(); |
12489 v8::HandleScope scope(isolate); | 12613 v8::HandleScope scope(isolate); |
12490 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); | 12614 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); |
12491 templ_o->SetNamedPropertyHandler(NoBlockGetterX); | 12615 templ_o->SetHandler(v8::NamedPropertyHandlerConfiguration(NoBlockGetterX)); |
12492 | 12616 |
12493 LocalContext context; | 12617 LocalContext context; |
12494 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); | 12618 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); |
12495 | 12619 |
12496 v8::Handle<Value> value = CompileRun( | 12620 v8::Handle<Value> value = CompileRun( |
12497 "try {" | 12621 "try {" |
12498 " o.__proto__ = this;" | 12622 " o.__proto__ = this;" |
12499 " for (var i = 0; i < 10; i++) {" | 12623 " for (var i = 0; i < 10; i++) {" |
12500 " var v = o.parseFloat('239');" | 12624 " var v = o.parseFloat('239');" |
12501 " if (v != 239) throw v;" | 12625 " if (v != 239) throw v;" |
12502 // Now it should be ICed and keep a reference to parseFloat. | 12626 // Now it should be ICed and keep a reference to parseFloat. |
12503 " }" | 12627 " }" |
12504 " var result = 0;" | 12628 " var result = 0;" |
12505 " for (var i = 0; i < 10; i++) {" | 12629 " for (var i = 0; i < 10; i++) {" |
12506 " result += o.parseFloat('239');" | 12630 " result += o.parseFloat('239');" |
12507 " }" | 12631 " }" |
12508 " result" | 12632 " result" |
12509 "} catch(e) {" | 12633 "} catch(e) {" |
12510 " e" | 12634 " e" |
12511 "};"); | 12635 "};"); |
12512 CHECK_EQ(239 * 10, value->Int32Value()); | 12636 CHECK_EQ(239 * 10, value->Int32Value()); |
12513 } | 12637 } |
12514 | 12638 |
12515 static void InterceptorCallICFastApi( | 12639 static void InterceptorCallICFastApi( |
12516 Local<String> name, | 12640 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
12517 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
12518 ApiTestFuzzer::Fuzz(); | 12641 ApiTestFuzzer::Fuzz(); |
12519 CheckReturnValue(info, FUNCTION_ADDR(InterceptorCallICFastApi)); | 12642 CheckReturnValue(info, FUNCTION_ADDR(InterceptorCallICFastApi)); |
12520 int* call_count = | 12643 int* call_count = |
12521 reinterpret_cast<int*>(v8::External::Cast(*info.Data())->Value()); | 12644 reinterpret_cast<int*>(v8::External::Cast(*info.Data())->Value()); |
12522 ++(*call_count); | 12645 ++(*call_count); |
12523 if ((*call_count) % 20 == 0) { | 12646 if ((*call_count) % 20 == 0) { |
12524 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 12647 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
12525 } | 12648 } |
12526 } | 12649 } |
12527 | 12650 |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12696 v8::Handle<v8::FunctionTemplate> fun_templ = | 12819 v8::Handle<v8::FunctionTemplate> fun_templ = |
12697 v8::FunctionTemplate::New(isolate); | 12820 v8::FunctionTemplate::New(isolate); |
12698 v8::Handle<v8::FunctionTemplate> method_templ = | 12821 v8::Handle<v8::FunctionTemplate> method_templ = |
12699 v8::FunctionTemplate::New(isolate, | 12822 v8::FunctionTemplate::New(isolate, |
12700 FastApiCallback_TrivialSignature, | 12823 FastApiCallback_TrivialSignature, |
12701 v8_str("method_data"), | 12824 v8_str("method_data"), |
12702 v8::Handle<v8::Signature>()); | 12825 v8::Handle<v8::Signature>()); |
12703 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 12826 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
12704 proto_templ->Set(v8_str("method"), method_templ); | 12827 proto_templ->Set(v8_str("method"), method_templ); |
12705 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 12828 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
12706 templ->SetNamedPropertyHandler( | 12829 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
12707 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, | 12830 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, |
12708 v8::External::New(isolate, &interceptor_call_count)); | 12831 v8::External::New(isolate, &interceptor_call_count))); |
12709 LocalContext context; | 12832 LocalContext context; |
12710 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 12833 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
12711 GenerateSomeGarbage(); | 12834 GenerateSomeGarbage(); |
12712 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 12835 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
12713 CompileRun( | 12836 CompileRun( |
12714 "var result = 0;" | 12837 "var result = 0;" |
12715 "for (var i = 0; i < 100; i++) {" | 12838 "for (var i = 0; i < 100; i++) {" |
12716 " result = o.method(41);" | 12839 " result = o.method(41);" |
12717 "}"); | 12840 "}"); |
12718 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); | 12841 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); |
12719 CHECK_EQ(100, interceptor_call_count); | 12842 CHECK_EQ(100, interceptor_call_count); |
12720 } | 12843 } |
12721 | 12844 |
12722 | 12845 |
12723 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature) { | 12846 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature) { |
12724 int interceptor_call_count = 0; | 12847 int interceptor_call_count = 0; |
12725 v8::Isolate* isolate = CcTest::isolate(); | 12848 v8::Isolate* isolate = CcTest::isolate(); |
12726 v8::HandleScope scope(isolate); | 12849 v8::HandleScope scope(isolate); |
12727 v8::Handle<v8::FunctionTemplate> fun_templ = | 12850 v8::Handle<v8::FunctionTemplate> fun_templ = |
12728 v8::FunctionTemplate::New(isolate); | 12851 v8::FunctionTemplate::New(isolate); |
12729 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( | 12852 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
12730 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), | 12853 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), |
12731 v8::Signature::New(isolate, fun_templ)); | 12854 v8::Signature::New(isolate, fun_templ)); |
12732 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 12855 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
12733 proto_templ->Set(v8_str("method"), method_templ); | 12856 proto_templ->Set(v8_str("method"), method_templ); |
12734 fun_templ->SetHiddenPrototype(true); | 12857 fun_templ->SetHiddenPrototype(true); |
12735 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 12858 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
12736 templ->SetNamedPropertyHandler( | 12859 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
12737 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, | 12860 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, |
12738 v8::External::New(isolate, &interceptor_call_count)); | 12861 v8::External::New(isolate, &interceptor_call_count))); |
12739 LocalContext context; | 12862 LocalContext context; |
12740 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 12863 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
12741 GenerateSomeGarbage(); | 12864 GenerateSomeGarbage(); |
12742 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 12865 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
12743 CompileRun( | 12866 CompileRun( |
12744 "o.foo = 17;" | 12867 "o.foo = 17;" |
12745 "var receiver = {};" | 12868 "var receiver = {};" |
12746 "receiver.__proto__ = o;" | 12869 "receiver.__proto__ = o;" |
12747 "var result = 0;" | 12870 "var result = 0;" |
12748 "for (var i = 0; i < 100; i++) {" | 12871 "for (var i = 0; i < 100; i++) {" |
(...skipping 10 matching lines...) Expand all Loading... |
12759 v8::HandleScope scope(isolate); | 12882 v8::HandleScope scope(isolate); |
12760 v8::Handle<v8::FunctionTemplate> fun_templ = | 12883 v8::Handle<v8::FunctionTemplate> fun_templ = |
12761 v8::FunctionTemplate::New(isolate); | 12884 v8::FunctionTemplate::New(isolate); |
12762 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( | 12885 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
12763 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), | 12886 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), |
12764 v8::Signature::New(isolate, fun_templ)); | 12887 v8::Signature::New(isolate, fun_templ)); |
12765 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 12888 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
12766 proto_templ->Set(v8_str("method"), method_templ); | 12889 proto_templ->Set(v8_str("method"), method_templ); |
12767 fun_templ->SetHiddenPrototype(true); | 12890 fun_templ->SetHiddenPrototype(true); |
12768 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 12891 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
12769 templ->SetNamedPropertyHandler( | 12892 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
12770 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, | 12893 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, |
12771 v8::External::New(isolate, &interceptor_call_count)); | 12894 v8::External::New(isolate, &interceptor_call_count))); |
12772 LocalContext context; | 12895 LocalContext context; |
12773 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 12896 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
12774 GenerateSomeGarbage(); | 12897 GenerateSomeGarbage(); |
12775 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 12898 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
12776 CompileRun( | 12899 CompileRun( |
12777 "o.foo = 17;" | 12900 "o.foo = 17;" |
12778 "var receiver = {};" | 12901 "var receiver = {};" |
12779 "receiver.__proto__ = o;" | 12902 "receiver.__proto__ = o;" |
12780 "var result = 0;" | 12903 "var result = 0;" |
12781 "var saved_result = 0;" | 12904 "var saved_result = 0;" |
(...skipping 16 matching lines...) Expand all Loading... |
12798 v8::HandleScope scope(isolate); | 12921 v8::HandleScope scope(isolate); |
12799 v8::Handle<v8::FunctionTemplate> fun_templ = | 12922 v8::Handle<v8::FunctionTemplate> fun_templ = |
12800 v8::FunctionTemplate::New(isolate); | 12923 v8::FunctionTemplate::New(isolate); |
12801 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( | 12924 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
12802 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), | 12925 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), |
12803 v8::Signature::New(isolate, fun_templ)); | 12926 v8::Signature::New(isolate, fun_templ)); |
12804 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 12927 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
12805 proto_templ->Set(v8_str("method"), method_templ); | 12928 proto_templ->Set(v8_str("method"), method_templ); |
12806 fun_templ->SetHiddenPrototype(true); | 12929 fun_templ->SetHiddenPrototype(true); |
12807 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 12930 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
12808 templ->SetNamedPropertyHandler( | 12931 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
12809 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, | 12932 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, |
12810 v8::External::New(isolate, &interceptor_call_count)); | 12933 v8::External::New(isolate, &interceptor_call_count))); |
12811 LocalContext context; | 12934 LocalContext context; |
12812 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 12935 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
12813 GenerateSomeGarbage(); | 12936 GenerateSomeGarbage(); |
12814 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 12937 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
12815 CompileRun( | 12938 CompileRun( |
12816 "o.foo = 17;" | 12939 "o.foo = 17;" |
12817 "var receiver = {};" | 12940 "var receiver = {};" |
12818 "receiver.__proto__ = o;" | 12941 "receiver.__proto__ = o;" |
12819 "var result = 0;" | 12942 "var result = 0;" |
12820 "var saved_result = 0;" | 12943 "var saved_result = 0;" |
(...skipping 16 matching lines...) Expand all Loading... |
12837 v8::HandleScope scope(isolate); | 12960 v8::HandleScope scope(isolate); |
12838 v8::Handle<v8::FunctionTemplate> fun_templ = | 12961 v8::Handle<v8::FunctionTemplate> fun_templ = |
12839 v8::FunctionTemplate::New(isolate); | 12962 v8::FunctionTemplate::New(isolate); |
12840 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( | 12963 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
12841 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), | 12964 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), |
12842 v8::Signature::New(isolate, fun_templ)); | 12965 v8::Signature::New(isolate, fun_templ)); |
12843 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 12966 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
12844 proto_templ->Set(v8_str("method"), method_templ); | 12967 proto_templ->Set(v8_str("method"), method_templ); |
12845 fun_templ->SetHiddenPrototype(true); | 12968 fun_templ->SetHiddenPrototype(true); |
12846 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 12969 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
12847 templ->SetNamedPropertyHandler( | 12970 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
12848 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, | 12971 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, |
12849 v8::External::New(isolate, &interceptor_call_count)); | 12972 v8::External::New(isolate, &interceptor_call_count))); |
12850 LocalContext context; | 12973 LocalContext context; |
12851 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 12974 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
12852 GenerateSomeGarbage(); | 12975 GenerateSomeGarbage(); |
12853 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 12976 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
12854 v8::TryCatch try_catch; | 12977 v8::TryCatch try_catch; |
12855 CompileRun( | 12978 CompileRun( |
12856 "o.foo = 17;" | 12979 "o.foo = 17;" |
12857 "var receiver = {};" | 12980 "var receiver = {};" |
12858 "receiver.__proto__ = o;" | 12981 "receiver.__proto__ = o;" |
12859 "var result = 0;" | 12982 "var result = 0;" |
(...skipping 20 matching lines...) Expand all Loading... |
12880 v8::HandleScope scope(isolate); | 13003 v8::HandleScope scope(isolate); |
12881 v8::Handle<v8::FunctionTemplate> fun_templ = | 13004 v8::Handle<v8::FunctionTemplate> fun_templ = |
12882 v8::FunctionTemplate::New(isolate); | 13005 v8::FunctionTemplate::New(isolate); |
12883 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( | 13006 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
12884 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), | 13007 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), |
12885 v8::Signature::New(isolate, fun_templ)); | 13008 v8::Signature::New(isolate, fun_templ)); |
12886 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 13009 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
12887 proto_templ->Set(v8_str("method"), method_templ); | 13010 proto_templ->Set(v8_str("method"), method_templ); |
12888 fun_templ->SetHiddenPrototype(true); | 13011 fun_templ->SetHiddenPrototype(true); |
12889 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 13012 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
12890 templ->SetNamedPropertyHandler( | 13013 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
12891 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, | 13014 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, |
12892 v8::External::New(isolate, &interceptor_call_count)); | 13015 v8::External::New(isolate, &interceptor_call_count))); |
12893 LocalContext context; | 13016 LocalContext context; |
12894 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 13017 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
12895 GenerateSomeGarbage(); | 13018 GenerateSomeGarbage(); |
12896 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 13019 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
12897 v8::TryCatch try_catch; | 13020 v8::TryCatch try_catch; |
12898 CompileRun( | 13021 CompileRun( |
12899 "o.foo = 17;" | 13022 "o.foo = 17;" |
12900 "var receiver = {};" | 13023 "var receiver = {};" |
12901 "receiver.__proto__ = o;" | 13024 "receiver.__proto__ = o;" |
12902 "var result = 0;" | 13025 "var result = 0;" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13082 CHECK(try_catch.HasCaught()); | 13205 CHECK(try_catch.HasCaught()); |
13083 CHECK_EQ(v8_str("TypeError: Illegal invocation"), | 13206 CHECK_EQ(v8_str("TypeError: Illegal invocation"), |
13084 try_catch.Exception()->ToString(isolate)); | 13207 try_catch.Exception()->ToString(isolate)); |
13085 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 13208 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); |
13086 } | 13209 } |
13087 | 13210 |
13088 | 13211 |
13089 v8::Handle<Value> keyed_call_ic_function; | 13212 v8::Handle<Value> keyed_call_ic_function; |
13090 | 13213 |
13091 static void InterceptorKeyedCallICGetter( | 13214 static void InterceptorKeyedCallICGetter( |
13092 Local<String> name, | 13215 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
13093 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
13094 ApiTestFuzzer::Fuzz(); | 13216 ApiTestFuzzer::Fuzz(); |
13095 if (v8_str("x")->Equals(name)) { | 13217 if (v8_str("x")->Equals(name)) { |
13096 info.GetReturnValue().Set(keyed_call_ic_function); | 13218 info.GetReturnValue().Set(keyed_call_ic_function); |
13097 } | 13219 } |
13098 } | 13220 } |
13099 | 13221 |
13100 | 13222 |
13101 // Test the case when we stored cacheable lookup into | 13223 // Test the case when we stored cacheable lookup into |
13102 // a stub, but the function name changed (to another cacheable function). | 13224 // a stub, but the function name changed (to another cacheable function). |
13103 THREADED_TEST(InterceptorKeyedCallICKeyChange1) { | 13225 THREADED_TEST(InterceptorKeyedCallICKeyChange1) { |
13104 v8::Isolate* isolate = CcTest::isolate(); | 13226 v8::Isolate* isolate = CcTest::isolate(); |
13105 v8::HandleScope scope(isolate); | 13227 v8::HandleScope scope(isolate); |
13106 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 13228 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
13107 templ->SetNamedPropertyHandler(NoBlockGetterX); | 13229 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(NoBlockGetterX)); |
13108 LocalContext context; | 13230 LocalContext context; |
13109 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 13231 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
13110 CompileRun( | 13232 CompileRun( |
13111 "proto = new Object();" | 13233 "proto = new Object();" |
13112 "proto.y = function(x) { return x + 1; };" | 13234 "proto.y = function(x) { return x + 1; };" |
13113 "proto.z = function(x) { return x - 1; };" | 13235 "proto.z = function(x) { return x - 1; };" |
13114 "o.__proto__ = proto;" | 13236 "o.__proto__ = proto;" |
13115 "var result = 0;" | 13237 "var result = 0;" |
13116 "var method = 'y';" | 13238 "var method = 'y';" |
13117 "for (var i = 0; i < 10; i++) {" | 13239 "for (var i = 0; i < 10; i++) {" |
13118 " if (i == 5) { method = 'z'; };" | 13240 " if (i == 5) { method = 'z'; };" |
13119 " result += o[method](41);" | 13241 " result += o[method](41);" |
13120 "}"); | 13242 "}"); |
13121 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); | 13243 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); |
13122 } | 13244 } |
13123 | 13245 |
13124 | 13246 |
13125 // Test the case when we stored cacheable lookup into | 13247 // Test the case when we stored cacheable lookup into |
13126 // a stub, but the function name changed (and the new function is present | 13248 // a stub, but the function name changed (and the new function is present |
13127 // both before and after the interceptor in the prototype chain). | 13249 // both before and after the interceptor in the prototype chain). |
13128 THREADED_TEST(InterceptorKeyedCallICKeyChange2) { | 13250 THREADED_TEST(InterceptorKeyedCallICKeyChange2) { |
13129 v8::Isolate* isolate = CcTest::isolate(); | 13251 v8::Isolate* isolate = CcTest::isolate(); |
13130 v8::HandleScope scope(isolate); | 13252 v8::HandleScope scope(isolate); |
13131 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 13253 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
13132 templ->SetNamedPropertyHandler(InterceptorKeyedCallICGetter); | 13254 templ->SetHandler( |
| 13255 v8::NamedPropertyHandlerConfiguration(InterceptorKeyedCallICGetter)); |
13133 LocalContext context; | 13256 LocalContext context; |
13134 context->Global()->Set(v8_str("proto1"), templ->NewInstance()); | 13257 context->Global()->Set(v8_str("proto1"), templ->NewInstance()); |
13135 keyed_call_ic_function = | 13258 keyed_call_ic_function = |
13136 v8_compile("function f(x) { return x - 1; }; f")->Run(); | 13259 v8_compile("function f(x) { return x - 1; }; f")->Run(); |
13137 CompileRun( | 13260 CompileRun( |
13138 "o = new Object();" | 13261 "o = new Object();" |
13139 "proto2 = new Object();" | 13262 "proto2 = new Object();" |
13140 "o.y = function(x) { return x + 1; };" | 13263 "o.y = function(x) { return x + 1; };" |
13141 "proto2.y = function(x) { return x + 2; };" | 13264 "proto2.y = function(x) { return x + 2; };" |
13142 "o.__proto__ = proto1;" | 13265 "o.__proto__ = proto1;" |
13143 "proto1.__proto__ = proto2;" | 13266 "proto1.__proto__ = proto2;" |
13144 "var result = 0;" | 13267 "var result = 0;" |
13145 "var method = 'x';" | 13268 "var method = 'x';" |
13146 "for (var i = 0; i < 10; i++) {" | 13269 "for (var i = 0; i < 10; i++) {" |
13147 " if (i == 5) { method = 'y'; };" | 13270 " if (i == 5) { method = 'y'; };" |
13148 " result += o[method](41);" | 13271 " result += o[method](41);" |
13149 "}"); | 13272 "}"); |
13150 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); | 13273 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); |
13151 } | 13274 } |
13152 | 13275 |
13153 | 13276 |
13154 // Same as InterceptorKeyedCallICKeyChange1 only the cacheable function sit | 13277 // Same as InterceptorKeyedCallICKeyChange1 only the cacheable function sit |
13155 // on the global object. | 13278 // on the global object. |
13156 THREADED_TEST(InterceptorKeyedCallICKeyChangeOnGlobal) { | 13279 THREADED_TEST(InterceptorKeyedCallICKeyChangeOnGlobal) { |
13157 v8::Isolate* isolate = CcTest::isolate(); | 13280 v8::Isolate* isolate = CcTest::isolate(); |
13158 v8::HandleScope scope(isolate); | 13281 v8::HandleScope scope(isolate); |
13159 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 13282 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
13160 templ->SetNamedPropertyHandler(NoBlockGetterX); | 13283 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(NoBlockGetterX)); |
13161 LocalContext context; | 13284 LocalContext context; |
13162 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 13285 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
13163 CompileRun( | 13286 CompileRun( |
13164 "function inc(x) { return x + 1; };" | 13287 "function inc(x) { return x + 1; };" |
13165 "inc(1);" | 13288 "inc(1);" |
13166 "function dec(x) { return x - 1; };" | 13289 "function dec(x) { return x - 1; };" |
13167 "dec(1);" | 13290 "dec(1);" |
13168 "o.__proto__ = this;" | 13291 "o.__proto__ = this;" |
13169 "this.__proto__.x = inc;" | 13292 "this.__proto__.x = inc;" |
13170 "this.__proto__.y = dec;" | 13293 "this.__proto__.y = dec;" |
13171 "var result = 0;" | 13294 "var result = 0;" |
13172 "var method = 'x';" | 13295 "var method = 'x';" |
13173 "for (var i = 0; i < 10; i++) {" | 13296 "for (var i = 0; i < 10; i++) {" |
13174 " if (i == 5) { method = 'y'; };" | 13297 " if (i == 5) { method = 'y'; };" |
13175 " result += o[method](41);" | 13298 " result += o[method](41);" |
13176 "}"); | 13299 "}"); |
13177 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); | 13300 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); |
13178 } | 13301 } |
13179 | 13302 |
13180 | 13303 |
13181 // Test the case when actual function to call sits on global object. | 13304 // Test the case when actual function to call sits on global object. |
13182 THREADED_TEST(InterceptorKeyedCallICFromGlobal) { | 13305 THREADED_TEST(InterceptorKeyedCallICFromGlobal) { |
13183 v8::Isolate* isolate = CcTest::isolate(); | 13306 v8::Isolate* isolate = CcTest::isolate(); |
13184 v8::HandleScope scope(isolate); | 13307 v8::HandleScope scope(isolate); |
13185 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); | 13308 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); |
13186 templ_o->SetNamedPropertyHandler(NoBlockGetterX); | 13309 templ_o->SetHandler(v8::NamedPropertyHandlerConfiguration(NoBlockGetterX)); |
13187 LocalContext context; | 13310 LocalContext context; |
13188 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); | 13311 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); |
13189 | 13312 |
13190 CompileRun( | 13313 CompileRun( |
13191 "function len(x) { return x.length; };" | 13314 "function len(x) { return x.length; };" |
13192 "o.__proto__ = this;" | 13315 "o.__proto__ = this;" |
13193 "var m = 'parseFloat';" | 13316 "var m = 'parseFloat';" |
13194 "var result = 0;" | 13317 "var result = 0;" |
13195 "for (var i = 0; i < 10; i++) {" | 13318 "for (var i = 0; i < 10; i++) {" |
13196 " if (i == 5) {" | 13319 " if (i == 5) {" |
13197 " m = 'len';" | 13320 " m = 'len';" |
13198 " saved_result = result;" | 13321 " saved_result = result;" |
13199 " };" | 13322 " };" |
13200 " result = o[m]('239');" | 13323 " result = o[m]('239');" |
13201 "}"); | 13324 "}"); |
13202 CHECK_EQ(3, context->Global()->Get(v8_str("result"))->Int32Value()); | 13325 CHECK_EQ(3, context->Global()->Get(v8_str("result"))->Int32Value()); |
13203 CHECK_EQ(239, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 13326 CHECK_EQ(239, context->Global()->Get(v8_str("saved_result"))->Int32Value()); |
13204 } | 13327 } |
13205 | 13328 |
13206 | 13329 |
13207 // Test the map transition before the interceptor. | 13330 // Test the map transition before the interceptor. |
13208 THREADED_TEST(InterceptorKeyedCallICMapChangeBefore) { | 13331 THREADED_TEST(InterceptorKeyedCallICMapChangeBefore) { |
13209 v8::Isolate* isolate = CcTest::isolate(); | 13332 v8::Isolate* isolate = CcTest::isolate(); |
13210 v8::HandleScope scope(isolate); | 13333 v8::HandleScope scope(isolate); |
13211 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); | 13334 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); |
13212 templ_o->SetNamedPropertyHandler(NoBlockGetterX); | 13335 templ_o->SetHandler(v8::NamedPropertyHandlerConfiguration(NoBlockGetterX)); |
13213 LocalContext context; | 13336 LocalContext context; |
13214 context->Global()->Set(v8_str("proto"), templ_o->NewInstance()); | 13337 context->Global()->Set(v8_str("proto"), templ_o->NewInstance()); |
13215 | 13338 |
13216 CompileRun( | 13339 CompileRun( |
13217 "var o = new Object();" | 13340 "var o = new Object();" |
13218 "o.__proto__ = proto;" | 13341 "o.__proto__ = proto;" |
13219 "o.method = function(x) { return x + 1; };" | 13342 "o.method = function(x) { return x + 1; };" |
13220 "var m = 'method';" | 13343 "var m = 'method';" |
13221 "var result = 0;" | 13344 "var result = 0;" |
13222 "for (var i = 0; i < 10; i++) {" | 13345 "for (var i = 0; i < 10; i++) {" |
13223 " if (i == 5) { o.method = function(x) { return x - 1; }; };" | 13346 " if (i == 5) { o.method = function(x) { return x - 1; }; };" |
13224 " result += o[m](41);" | 13347 " result += o[m](41);" |
13225 "}"); | 13348 "}"); |
13226 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); | 13349 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); |
13227 } | 13350 } |
13228 | 13351 |
13229 | 13352 |
13230 // Test the map transition after the interceptor. | 13353 // Test the map transition after the interceptor. |
13231 THREADED_TEST(InterceptorKeyedCallICMapChangeAfter) { | 13354 THREADED_TEST(InterceptorKeyedCallICMapChangeAfter) { |
13232 v8::Isolate* isolate = CcTest::isolate(); | 13355 v8::Isolate* isolate = CcTest::isolate(); |
13233 v8::HandleScope scope(isolate); | 13356 v8::HandleScope scope(isolate); |
13234 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); | 13357 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); |
13235 templ_o->SetNamedPropertyHandler(NoBlockGetterX); | 13358 templ_o->SetHandler(v8::NamedPropertyHandlerConfiguration(NoBlockGetterX)); |
13236 LocalContext context; | 13359 LocalContext context; |
13237 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); | 13360 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); |
13238 | 13361 |
13239 CompileRun( | 13362 CompileRun( |
13240 "var proto = new Object();" | 13363 "var proto = new Object();" |
13241 "o.__proto__ = proto;" | 13364 "o.__proto__ = proto;" |
13242 "proto.method = function(x) { return x + 1; };" | 13365 "proto.method = function(x) { return x + 1; };" |
13243 "var m = 'method';" | 13366 "var m = 'method';" |
13244 "var result = 0;" | 13367 "var result = 0;" |
13245 "for (var i = 0; i < 10; i++) {" | 13368 "for (var i = 0; i < 10; i++) {" |
13246 " if (i == 5) { proto.method = function(x) { return x - 1; }; };" | 13369 " if (i == 5) { proto.method = function(x) { return x - 1; }; };" |
13247 " result += o[m](41);" | 13370 " result += o[m](41);" |
13248 "}"); | 13371 "}"); |
13249 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); | 13372 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); |
13250 } | 13373 } |
13251 | 13374 |
13252 | 13375 |
13253 static int interceptor_call_count = 0; | 13376 static int interceptor_call_count = 0; |
13254 | 13377 |
13255 static void InterceptorICRefErrorGetter( | 13378 static void InterceptorICRefErrorGetter( |
13256 Local<String> name, | 13379 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
13257 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
13258 ApiTestFuzzer::Fuzz(); | 13380 ApiTestFuzzer::Fuzz(); |
13259 if (v8_str("x")->Equals(name) && interceptor_call_count++ < 20) { | 13381 if (v8_str("x")->Equals(name) && interceptor_call_count++ < 20) { |
13260 info.GetReturnValue().Set(call_ic_function2); | 13382 info.GetReturnValue().Set(call_ic_function2); |
13261 } | 13383 } |
13262 } | 13384 } |
13263 | 13385 |
13264 | 13386 |
13265 // This test should hit load and call ICs for the interceptor case. | 13387 // 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 | 13388 // Once in a while, the interceptor will reply that a property was not |
13267 // found in which case we should get a reference error. | 13389 // found in which case we should get a reference error. |
13268 THREADED_TEST(InterceptorICReferenceErrors) { | 13390 THREADED_TEST(InterceptorICReferenceErrors) { |
13269 v8::Isolate* isolate = CcTest::isolate(); | 13391 v8::Isolate* isolate = CcTest::isolate(); |
13270 v8::HandleScope scope(isolate); | 13392 v8::HandleScope scope(isolate); |
13271 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 13393 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
13272 templ->SetNamedPropertyHandler(InterceptorICRefErrorGetter); | 13394 templ->SetHandler( |
| 13395 v8::NamedPropertyHandlerConfiguration(InterceptorICRefErrorGetter)); |
13273 LocalContext context(0, templ, v8::Handle<Value>()); | 13396 LocalContext context(0, templ, v8::Handle<Value>()); |
13274 call_ic_function2 = v8_compile("function h(x) { return x; }; h")->Run(); | 13397 call_ic_function2 = v8_compile("function h(x) { return x; }; h")->Run(); |
13275 v8::Handle<Value> value = CompileRun( | 13398 v8::Handle<Value> value = CompileRun( |
13276 "function f() {" | 13399 "function f() {" |
13277 " for (var i = 0; i < 1000; i++) {" | 13400 " for (var i = 0; i < 1000; i++) {" |
13278 " try { x; } catch(e) { return true; }" | 13401 " try { x; } catch(e) { return true; }" |
13279 " }" | 13402 " }" |
13280 " return false;" | 13403 " return false;" |
13281 "};" | 13404 "};" |
13282 "f();"); | 13405 "f();"); |
13283 CHECK_EQ(true, value->BooleanValue()); | 13406 CHECK_EQ(true, value->BooleanValue()); |
13284 interceptor_call_count = 0; | 13407 interceptor_call_count = 0; |
13285 value = CompileRun( | 13408 value = CompileRun( |
13286 "function g() {" | 13409 "function g() {" |
13287 " for (var i = 0; i < 1000; i++) {" | 13410 " for (var i = 0; i < 1000; i++) {" |
13288 " try { x(42); } catch(e) { return true; }" | 13411 " try { x(42); } catch(e) { return true; }" |
13289 " }" | 13412 " }" |
13290 " return false;" | 13413 " return false;" |
13291 "};" | 13414 "};" |
13292 "g();"); | 13415 "g();"); |
13293 CHECK_EQ(true, value->BooleanValue()); | 13416 CHECK_EQ(true, value->BooleanValue()); |
13294 } | 13417 } |
13295 | 13418 |
13296 | 13419 |
13297 static int interceptor_ic_exception_get_count = 0; | 13420 static int interceptor_ic_exception_get_count = 0; |
13298 | 13421 |
13299 static void InterceptorICExceptionGetter( | 13422 static void InterceptorICExceptionGetter( |
13300 Local<String> name, | 13423 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
13301 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
13302 ApiTestFuzzer::Fuzz(); | 13424 ApiTestFuzzer::Fuzz(); |
13303 if (v8_str("x")->Equals(name) && ++interceptor_ic_exception_get_count < 20) { | 13425 if (v8_str("x")->Equals(name) && ++interceptor_ic_exception_get_count < 20) { |
13304 info.GetReturnValue().Set(call_ic_function3); | 13426 info.GetReturnValue().Set(call_ic_function3); |
13305 } | 13427 } |
13306 if (interceptor_ic_exception_get_count == 20) { | 13428 if (interceptor_ic_exception_get_count == 20) { |
13307 info.GetIsolate()->ThrowException(v8_num(42)); | 13429 info.GetIsolate()->ThrowException(v8_num(42)); |
13308 return; | 13430 return; |
13309 } | 13431 } |
13310 } | 13432 } |
13311 | 13433 |
13312 | 13434 |
13313 // Test interceptor load/call IC where the interceptor throws an | 13435 // Test interceptor load/call IC where the interceptor throws an |
13314 // exception once in a while. | 13436 // exception once in a while. |
13315 THREADED_TEST(InterceptorICGetterExceptions) { | 13437 THREADED_TEST(InterceptorICGetterExceptions) { |
13316 interceptor_ic_exception_get_count = 0; | 13438 interceptor_ic_exception_get_count = 0; |
13317 v8::Isolate* isolate = CcTest::isolate(); | 13439 v8::Isolate* isolate = CcTest::isolate(); |
13318 v8::HandleScope scope(isolate); | 13440 v8::HandleScope scope(isolate); |
13319 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 13441 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
13320 templ->SetNamedPropertyHandler(InterceptorICExceptionGetter); | 13442 templ->SetHandler( |
| 13443 v8::NamedPropertyHandlerConfiguration(InterceptorICExceptionGetter)); |
13321 LocalContext context(0, templ, v8::Handle<Value>()); | 13444 LocalContext context(0, templ, v8::Handle<Value>()); |
13322 call_ic_function3 = v8_compile("function h(x) { return x; }; h")->Run(); | 13445 call_ic_function3 = v8_compile("function h(x) { return x; }; h")->Run(); |
13323 v8::Handle<Value> value = CompileRun( | 13446 v8::Handle<Value> value = CompileRun( |
13324 "function f() {" | 13447 "function f() {" |
13325 " for (var i = 0; i < 100; i++) {" | 13448 " for (var i = 0; i < 100; i++) {" |
13326 " try { x; } catch(e) { return true; }" | 13449 " try { x; } catch(e) { return true; }" |
13327 " }" | 13450 " }" |
13328 " return false;" | 13451 " return false;" |
13329 "};" | 13452 "};" |
13330 "f();"); | 13453 "f();"); |
13331 CHECK_EQ(true, value->BooleanValue()); | 13454 CHECK_EQ(true, value->BooleanValue()); |
13332 interceptor_ic_exception_get_count = 0; | 13455 interceptor_ic_exception_get_count = 0; |
13333 value = CompileRun( | 13456 value = CompileRun( |
13334 "function f() {" | 13457 "function f() {" |
13335 " for (var i = 0; i < 100; i++) {" | 13458 " for (var i = 0; i < 100; i++) {" |
13336 " try { x(42); } catch(e) { return true; }" | 13459 " try { x(42); } catch(e) { return true; }" |
13337 " }" | 13460 " }" |
13338 " return false;" | 13461 " return false;" |
13339 "};" | 13462 "};" |
13340 "f();"); | 13463 "f();"); |
13341 CHECK_EQ(true, value->BooleanValue()); | 13464 CHECK_EQ(true, value->BooleanValue()); |
13342 } | 13465 } |
13343 | 13466 |
13344 | 13467 |
13345 static int interceptor_ic_exception_set_count = 0; | 13468 static int interceptor_ic_exception_set_count = 0; |
13346 | 13469 |
13347 static void InterceptorICExceptionSetter( | 13470 static void InterceptorICExceptionSetter( |
13348 Local<String> key, | 13471 Local<Name> key, Local<Value> value, |
13349 Local<Value> value, | 13472 const v8::PropertyCallbackInfo<v8::Value>& info) { |
13350 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
13351 ApiTestFuzzer::Fuzz(); | 13473 ApiTestFuzzer::Fuzz(); |
13352 if (++interceptor_ic_exception_set_count > 20) { | 13474 if (++interceptor_ic_exception_set_count > 20) { |
13353 info.GetIsolate()->ThrowException(v8_num(42)); | 13475 info.GetIsolate()->ThrowException(v8_num(42)); |
13354 } | 13476 } |
13355 } | 13477 } |
13356 | 13478 |
13357 | 13479 |
13358 // Test interceptor store IC where the interceptor throws an exception | 13480 // Test interceptor store IC where the interceptor throws an exception |
13359 // once in a while. | 13481 // once in a while. |
13360 THREADED_TEST(InterceptorICSetterExceptions) { | 13482 THREADED_TEST(InterceptorICSetterExceptions) { |
13361 interceptor_ic_exception_set_count = 0; | 13483 interceptor_ic_exception_set_count = 0; |
13362 v8::Isolate* isolate = CcTest::isolate(); | 13484 v8::Isolate* isolate = CcTest::isolate(); |
13363 v8::HandleScope scope(isolate); | 13485 v8::HandleScope scope(isolate); |
13364 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 13486 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
13365 templ->SetNamedPropertyHandler(0, InterceptorICExceptionSetter); | 13487 templ->SetHandler( |
| 13488 v8::NamedPropertyHandlerConfiguration(0, InterceptorICExceptionSetter)); |
13366 LocalContext context(0, templ, v8::Handle<Value>()); | 13489 LocalContext context(0, templ, v8::Handle<Value>()); |
13367 v8::Handle<Value> value = CompileRun( | 13490 v8::Handle<Value> value = CompileRun( |
13368 "function f() {" | 13491 "function f() {" |
13369 " for (var i = 0; i < 100; i++) {" | 13492 " for (var i = 0; i < 100; i++) {" |
13370 " try { x = 42; } catch(e) { return true; }" | 13493 " try { x = 42; } catch(e) { return true; }" |
13371 " }" | 13494 " }" |
13372 " return false;" | 13495 " return false;" |
13373 "};" | 13496 "};" |
13374 "f();"); | 13497 "f();"); |
13375 CHECK_EQ(true, value->BooleanValue()); | 13498 CHECK_EQ(true, value->BooleanValue()); |
13376 } | 13499 } |
13377 | 13500 |
13378 | 13501 |
13379 // Test that we ignore null interceptors. | 13502 // Test that we ignore null interceptors. |
13380 THREADED_TEST(NullNamedInterceptor) { | 13503 THREADED_TEST(NullNamedInterceptor) { |
13381 v8::Isolate* isolate = CcTest::isolate(); | 13504 v8::Isolate* isolate = CcTest::isolate(); |
13382 v8::HandleScope scope(isolate); | 13505 v8::HandleScope scope(isolate); |
13383 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 13506 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
13384 templ->SetNamedPropertyHandler( | 13507 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
13385 static_cast<v8::NamedPropertyGetterCallback>(0)); | 13508 static_cast<v8::GenericNamedPropertyGetterCallback>(0))); |
13386 LocalContext context; | 13509 LocalContext context; |
13387 templ->Set(CcTest::isolate(), "x", v8_num(42)); | 13510 templ->Set(CcTest::isolate(), "x", v8_num(42)); |
13388 v8::Handle<v8::Object> obj = templ->NewInstance(); | 13511 v8::Handle<v8::Object> obj = templ->NewInstance(); |
13389 context->Global()->Set(v8_str("obj"), obj); | 13512 context->Global()->Set(v8_str("obj"), obj); |
13390 v8::Handle<Value> value = CompileRun("obj.x"); | 13513 v8::Handle<Value> value = CompileRun("obj.x"); |
13391 CHECK(value->IsInt32()); | 13514 CHECK(value->IsInt32()); |
13392 CHECK_EQ(42, value->Int32Value()); | 13515 CHECK_EQ(42, value->Int32Value()); |
13393 } | 13516 } |
13394 | 13517 |
13395 | 13518 |
(...skipping 11 matching lines...) Expand all Loading... |
13407 v8::Handle<Value> value = CompileRun("obj[42]"); | 13530 v8::Handle<Value> value = CompileRun("obj[42]"); |
13408 CHECK(value->IsInt32()); | 13531 CHECK(value->IsInt32()); |
13409 CHECK_EQ(42, value->Int32Value()); | 13532 CHECK_EQ(42, value->Int32Value()); |
13410 } | 13533 } |
13411 | 13534 |
13412 | 13535 |
13413 THREADED_TEST(NamedPropertyHandlerGetterAttributes) { | 13536 THREADED_TEST(NamedPropertyHandlerGetterAttributes) { |
13414 v8::Isolate* isolate = CcTest::isolate(); | 13537 v8::Isolate* isolate = CcTest::isolate(); |
13415 v8::HandleScope scope(isolate); | 13538 v8::HandleScope scope(isolate); |
13416 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); | 13539 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); |
13417 templ->InstanceTemplate()->SetNamedPropertyHandler(InterceptorLoadXICGetter); | 13540 templ->InstanceTemplate()->SetHandler( |
| 13541 v8::NamedPropertyHandlerConfiguration(InterceptorLoadXICGetter)); |
13418 LocalContext env; | 13542 LocalContext env; |
13419 env->Global()->Set(v8_str("obj"), | 13543 env->Global()->Set(v8_str("obj"), |
13420 templ->GetFunction()->NewInstance()); | 13544 templ->GetFunction()->NewInstance()); |
13421 ExpectTrue("obj.x === 42"); | 13545 ExpectTrue("obj.x === 42"); |
13422 ExpectTrue("!obj.propertyIsEnumerable('x')"); | 13546 ExpectTrue("!obj.propertyIsEnumerable('x')"); |
13423 } | 13547 } |
13424 | 13548 |
13425 | 13549 |
13426 static void ThrowingGetter(Local<String> name, | 13550 static void ThrowingGetter(Local<String> name, |
13427 const v8::PropertyCallbackInfo<v8::Value>& info) { | 13551 const v8::PropertyCallbackInfo<v8::Value>& info) { |
(...skipping 2447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15875 } | 15999 } |
15876 info.GetReturnValue().Set(3); | 16000 info.GetReturnValue().Set(3); |
15877 } | 16001 } |
15878 | 16002 |
15879 static void ForceSetSetter(v8::Local<v8::String> name, | 16003 static void ForceSetSetter(v8::Local<v8::String> name, |
15880 v8::Local<v8::Value> value, | 16004 v8::Local<v8::Value> value, |
15881 const v8::PropertyCallbackInfo<void>& info) { | 16005 const v8::PropertyCallbackInfo<void>& info) { |
15882 force_set_set_count++; | 16006 force_set_set_count++; |
15883 } | 16007 } |
15884 | 16008 |
| 16009 static void ForceSetInterceptGetter( |
| 16010 v8::Local<v8::Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 16011 CHECK(name->IsString()); |
| 16012 ForceSetGetter(Local<String>::Cast(name), info); |
| 16013 } |
| 16014 |
15885 static void ForceSetInterceptSetter( | 16015 static void ForceSetInterceptSetter( |
15886 v8::Local<v8::String> name, | 16016 v8::Local<v8::Name> name, v8::Local<v8::Value> value, |
15887 v8::Local<v8::Value> value, | |
15888 const v8::PropertyCallbackInfo<v8::Value>& info) { | 16017 const v8::PropertyCallbackInfo<v8::Value>& info) { |
15889 force_set_set_count++; | 16018 force_set_set_count++; |
15890 info.GetReturnValue().SetUndefined(); | 16019 info.GetReturnValue().SetUndefined(); |
15891 } | 16020 } |
15892 | 16021 |
15893 | 16022 |
15894 TEST(ForceSet) { | 16023 TEST(ForceSet) { |
15895 force_set_get_count = 0; | 16024 force_set_get_count = 0; |
15896 force_set_set_count = 0; | 16025 force_set_set_count = 0; |
15897 pass_on_get = false; | 16026 pass_on_get = false; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15937 | 16066 |
15938 | 16067 |
15939 TEST(ForceSetWithInterceptor) { | 16068 TEST(ForceSetWithInterceptor) { |
15940 force_set_get_count = 0; | 16069 force_set_get_count = 0; |
15941 force_set_set_count = 0; | 16070 force_set_set_count = 0; |
15942 pass_on_get = false; | 16071 pass_on_get = false; |
15943 | 16072 |
15944 v8::Isolate* isolate = CcTest::isolate(); | 16073 v8::Isolate* isolate = CcTest::isolate(); |
15945 v8::HandleScope scope(isolate); | 16074 v8::HandleScope scope(isolate); |
15946 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); | 16075 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); |
15947 templ->SetNamedPropertyHandler(ForceSetGetter, ForceSetInterceptSetter); | 16076 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
| 16077 ForceSetInterceptGetter, ForceSetInterceptSetter)); |
15948 LocalContext context(NULL, templ); | 16078 LocalContext context(NULL, templ); |
15949 v8::Handle<v8::Object> global = context->Global(); | 16079 v8::Handle<v8::Object> global = context->Global(); |
15950 | 16080 |
15951 v8::Handle<v8::String> some_property = | 16081 v8::Handle<v8::String> some_property = |
15952 v8::String::NewFromUtf8(isolate, "a"); | 16082 v8::String::NewFromUtf8(isolate, "a"); |
15953 CHECK_EQ(0, force_set_set_count); | 16083 CHECK_EQ(0, force_set_set_count); |
15954 CHECK_EQ(0, force_set_get_count); | 16084 CHECK_EQ(0, force_set_get_count); |
15955 CHECK_EQ(3, global->Get(some_property)->Int32Value()); | 16085 CHECK_EQ(3, global->Get(some_property)->Int32Value()); |
15956 // Setting the property shouldn't override it, just call the setter | 16086 // Setting the property shouldn't override it, just call the setter |
15957 // which in this case does nothing. | 16087 // 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)); | 16135 CHECK(global->ForceDelete(simple_property)); |
16006 CHECK(global->Get(simple_property)->IsUndefined()); | 16136 CHECK(global->Get(simple_property)->IsUndefined()); |
16007 } | 16137 } |
16008 | 16138 |
16009 | 16139 |
16010 static int force_delete_interceptor_count = 0; | 16140 static int force_delete_interceptor_count = 0; |
16011 static bool pass_on_delete = false; | 16141 static bool pass_on_delete = false; |
16012 | 16142 |
16013 | 16143 |
16014 static void ForceDeleteDeleter( | 16144 static void ForceDeleteDeleter( |
16015 v8::Local<v8::String> name, | 16145 v8::Local<v8::Name> name, |
16016 const v8::PropertyCallbackInfo<v8::Boolean>& info) { | 16146 const v8::PropertyCallbackInfo<v8::Boolean>& info) { |
16017 force_delete_interceptor_count++; | 16147 force_delete_interceptor_count++; |
16018 if (pass_on_delete) return; | 16148 if (pass_on_delete) return; |
16019 info.GetReturnValue().Set(true); | 16149 info.GetReturnValue().Set(true); |
16020 } | 16150 } |
16021 | 16151 |
16022 | 16152 |
16023 THREADED_TEST(ForceDeleteWithInterceptor) { | 16153 THREADED_TEST(ForceDeleteWithInterceptor) { |
16024 force_delete_interceptor_count = 0; | 16154 force_delete_interceptor_count = 0; |
16025 pass_on_delete = false; | 16155 pass_on_delete = false; |
16026 | 16156 |
16027 v8::Isolate* isolate = CcTest::isolate(); | 16157 v8::Isolate* isolate = CcTest::isolate(); |
16028 v8::HandleScope scope(isolate); | 16158 v8::HandleScope scope(isolate); |
16029 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); | 16159 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); |
16030 templ->SetNamedPropertyHandler(0, 0, 0, ForceDeleteDeleter); | 16160 templ->SetHandler( |
| 16161 v8::NamedPropertyHandlerConfiguration(0, 0, 0, ForceDeleteDeleter)); |
16031 LocalContext context(NULL, templ); | 16162 LocalContext context(NULL, templ); |
16032 v8::Handle<v8::Object> global = context->Global(); | 16163 v8::Handle<v8::Object> global = context->Global(); |
16033 | 16164 |
16034 v8::Handle<v8::String> some_property = | 16165 v8::Handle<v8::String> some_property = |
16035 v8::String::NewFromUtf8(isolate, "a"); | 16166 v8::String::NewFromUtf8(isolate, "a"); |
16036 global->ForceSet(some_property, v8::Integer::New(isolate, 42), | 16167 global->ForceSet(some_property, v8::Integer::New(isolate, 42), |
16037 v8::DontDelete); | 16168 v8::DontDelete); |
16038 | 16169 |
16039 // Deleting a property should get intercepted and nothing should | 16170 // Deleting a property should get intercepted and nothing should |
16040 // happen. | 16171 // happen. |
(...skipping 3391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19432 static void SetterWhichSetsYOnThisTo23( | 19563 static void SetterWhichSetsYOnThisTo23( |
19433 Local<String> name, | 19564 Local<String> name, |
19434 Local<Value> value, | 19565 Local<Value> value, |
19435 const v8::PropertyCallbackInfo<void>& info) { | 19566 const v8::PropertyCallbackInfo<void>& info) { |
19436 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); | 19567 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); |
19437 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); | 19568 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); |
19438 Local<Object>::Cast(info.This())->Set(v8_str("y"), v8_num(23)); | 19569 Local<Object>::Cast(info.This())->Set(v8_str("y"), v8_num(23)); |
19439 } | 19570 } |
19440 | 19571 |
19441 | 19572 |
19442 void FooGetInterceptor(Local<String> name, | 19573 void FooGetInterceptor(Local<Name> name, |
19443 const v8::PropertyCallbackInfo<v8::Value>& info) { | 19574 const v8::PropertyCallbackInfo<v8::Value>& info) { |
19444 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); | 19575 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); |
19445 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); | 19576 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); |
19446 if (!name->Equals(v8_str("foo"))) return; | 19577 if (!name->Equals(v8_str("foo"))) return; |
19447 info.GetReturnValue().Set(v8_num(42)); | 19578 info.GetReturnValue().Set(v8_num(42)); |
19448 } | 19579 } |
19449 | 19580 |
19450 | 19581 |
19451 void FooSetInterceptor(Local<String> name, | 19582 void FooSetInterceptor(Local<Name> name, Local<Value> value, |
19452 Local<Value> value, | |
19453 const v8::PropertyCallbackInfo<v8::Value>& info) { | 19583 const v8::PropertyCallbackInfo<v8::Value>& info) { |
19454 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); | 19584 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); |
19455 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); | 19585 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); |
19456 if (!name->Equals(v8_str("foo"))) return; | 19586 if (!name->Equals(v8_str("foo"))) return; |
19457 Local<Object>::Cast(info.This())->Set(v8_str("y"), v8_num(23)); | 19587 Local<Object>::Cast(info.This())->Set(v8_str("y"), v8_num(23)); |
19458 info.GetReturnValue().Set(v8_num(23)); | 19588 info.GetReturnValue().Set(v8_num(23)); |
19459 } | 19589 } |
19460 | 19590 |
19461 | 19591 |
19462 TEST(SetterOnConstructorPrototype) { | 19592 TEST(SetterOnConstructorPrototype) { |
(...skipping 25 matching lines...) Expand all Loading... |
19488 script = v8_compile("new C2();"); | 19618 script = v8_compile("new C2();"); |
19489 for (int i = 0; i < 10; i++) { | 19619 for (int i = 0; i < 10; i++) { |
19490 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run()); | 19620 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run()); |
19491 CHECK_EQ(42, c2->Get(v8_str("x"))->Int32Value()); | 19621 CHECK_EQ(42, c2->Get(v8_str("x"))->Int32Value()); |
19492 CHECK_EQ(23, c2->Get(v8_str("y"))->Int32Value()); | 19622 CHECK_EQ(23, c2->Get(v8_str("y"))->Int32Value()); |
19493 } | 19623 } |
19494 } | 19624 } |
19495 | 19625 |
19496 | 19626 |
19497 static void NamedPropertyGetterWhichReturns42( | 19627 static void NamedPropertyGetterWhichReturns42( |
19498 Local<String> name, | 19628 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
19499 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
19500 info.GetReturnValue().Set(v8_num(42)); | 19629 info.GetReturnValue().Set(v8_num(42)); |
19501 } | 19630 } |
19502 | 19631 |
19503 | 19632 |
19504 static void NamedPropertySetterWhichSetsYOnThisTo23( | 19633 static void NamedPropertySetterWhichSetsYOnThisTo23( |
19505 Local<String> name, | 19634 Local<Name> name, Local<Value> value, |
19506 Local<Value> value, | |
19507 const v8::PropertyCallbackInfo<v8::Value>& info) { | 19635 const v8::PropertyCallbackInfo<v8::Value>& info) { |
19508 if (name->Equals(v8_str("x"))) { | 19636 if (name->Equals(v8_str("x"))) { |
19509 Local<Object>::Cast(info.This())->Set(v8_str("y"), v8_num(23)); | 19637 Local<Object>::Cast(info.This())->Set(v8_str("y"), v8_num(23)); |
19510 } | 19638 } |
19511 } | 19639 } |
19512 | 19640 |
19513 | 19641 |
19514 THREADED_TEST(InterceptorOnConstructorPrototype) { | 19642 THREADED_TEST(InterceptorOnConstructorPrototype) { |
19515 v8::Isolate* isolate = CcTest::isolate(); | 19643 v8::Isolate* isolate = CcTest::isolate(); |
19516 v8::HandleScope scope(isolate); | 19644 v8::HandleScope scope(isolate); |
19517 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 19645 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
19518 templ->SetNamedPropertyHandler(NamedPropertyGetterWhichReturns42, | 19646 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
19519 NamedPropertySetterWhichSetsYOnThisTo23); | 19647 NamedPropertyGetterWhichReturns42, |
| 19648 NamedPropertySetterWhichSetsYOnThisTo23)); |
19520 LocalContext context; | 19649 LocalContext context; |
19521 context->Global()->Set(v8_str("P"), templ->NewInstance()); | 19650 context->Global()->Set(v8_str("P"), templ->NewInstance()); |
19522 CompileRun("function C1() {" | 19651 CompileRun("function C1() {" |
19523 " this.x = 23;" | 19652 " this.x = 23;" |
19524 "};" | 19653 "};" |
19525 "C1.prototype = P;" | 19654 "C1.prototype = P;" |
19526 "function C2() {" | 19655 "function C2() {" |
19527 " this.x = 23" | 19656 " this.x = 23" |
19528 "};" | 19657 "};" |
19529 "C2.prototype = { };" | 19658 "C2.prototype = { };" |
(...skipping 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20801 CHECK(!globalProxy->StrictEquals(global)); | 20930 CHECK(!globalProxy->StrictEquals(global)); |
20802 CHECK(globalProxy->StrictEquals(globalProxy)); | 20931 CHECK(globalProxy->StrictEquals(globalProxy)); |
20803 | 20932 |
20804 CHECK(global->Equals(global)); | 20933 CHECK(global->Equals(global)); |
20805 CHECK(!global->Equals(globalProxy)); | 20934 CHECK(!global->Equals(globalProxy)); |
20806 CHECK(!globalProxy->Equals(global)); | 20935 CHECK(!globalProxy->Equals(global)); |
20807 CHECK(globalProxy->Equals(globalProxy)); | 20936 CHECK(globalProxy->Equals(globalProxy)); |
20808 } | 20937 } |
20809 | 20938 |
20810 | 20939 |
20811 static void Getter(v8::Local<v8::String> property, | 20940 static void Getter(v8::Local<v8::Name> property, |
20812 const v8::PropertyCallbackInfo<v8::Value>& info ) { | 20941 const v8::PropertyCallbackInfo<v8::Value>& info) { |
20813 info.GetReturnValue().Set(v8_str("42!")); | 20942 info.GetReturnValue().Set(v8_str("42!")); |
20814 } | 20943 } |
20815 | 20944 |
20816 | 20945 |
20817 static void Enumerator(const v8::PropertyCallbackInfo<v8::Array>& info) { | 20946 static void Enumerator(const v8::PropertyCallbackInfo<v8::Array>& info) { |
20818 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate()); | 20947 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate()); |
20819 result->Set(0, v8_str("universalAnswer")); | 20948 result->Set(0, v8_str("universalAnswer")); |
20820 info.GetReturnValue().Set(result); | 20949 info.GetReturnValue().Set(result); |
20821 } | 20950 } |
20822 | 20951 |
20823 | 20952 |
20824 TEST(NamedEnumeratorAndForIn) { | 20953 TEST(NamedEnumeratorAndForIn) { |
20825 LocalContext context; | 20954 LocalContext context; |
20826 v8::Isolate* isolate = context->GetIsolate(); | 20955 v8::Isolate* isolate = context->GetIsolate(); |
20827 v8::HandleScope handle_scope(isolate); | 20956 v8::HandleScope handle_scope(isolate); |
20828 v8::Context::Scope context_scope(context.local()); | 20957 v8::Context::Scope context_scope(context.local()); |
20829 | 20958 |
20830 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(isolate); | 20959 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(isolate); |
20831 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); | 20960 tmpl->SetHandler(v8::NamedPropertyHandlerConfiguration(Getter, NULL, NULL, |
| 20961 NULL, Enumerator)); |
20832 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); | 20962 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); |
20833 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( | 20963 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( |
20834 "var result = []; for (var k in o) result.push(k); result")); | 20964 "var result = []; for (var k in o) result.push(k); result")); |
20835 CHECK_EQ(1, result->Length()); | 20965 CHECK_EQ(1, result->Length()); |
20836 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); | 20966 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); |
20837 } | 20967 } |
20838 | 20968 |
20839 | 20969 |
20840 TEST(DefinePropertyPostDetach) { | 20970 TEST(DefinePropertyPostDetach) { |
20841 LocalContext context; | 20971 LocalContext context; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20966 | 21096 |
20967 | 21097 |
20968 void HasOwnPropertyIndexedPropertyGetter( | 21098 void HasOwnPropertyIndexedPropertyGetter( |
20969 uint32_t index, | 21099 uint32_t index, |
20970 const v8::PropertyCallbackInfo<v8::Value>& info) { | 21100 const v8::PropertyCallbackInfo<v8::Value>& info) { |
20971 if (index == 42) info.GetReturnValue().Set(v8_str("yes")); | 21101 if (index == 42) info.GetReturnValue().Set(v8_str("yes")); |
20972 } | 21102 } |
20973 | 21103 |
20974 | 21104 |
20975 void HasOwnPropertyNamedPropertyGetter( | 21105 void HasOwnPropertyNamedPropertyGetter( |
20976 Local<String> property, | 21106 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")); | 21107 if (property->Equals(v8_str("foo"))) info.GetReturnValue().Set(v8_str("yes")); |
20979 } | 21108 } |
20980 | 21109 |
20981 | 21110 |
20982 void HasOwnPropertyIndexedPropertyQuery( | 21111 void HasOwnPropertyIndexedPropertyQuery( |
20983 uint32_t index, const v8::PropertyCallbackInfo<v8::Integer>& info) { | 21112 uint32_t index, const v8::PropertyCallbackInfo<v8::Integer>& info) { |
20984 if (index == 42) info.GetReturnValue().Set(1); | 21113 if (index == 42) info.GetReturnValue().Set(1); |
20985 } | 21114 } |
20986 | 21115 |
20987 | 21116 |
20988 void HasOwnPropertyNamedPropertyQuery( | 21117 void HasOwnPropertyNamedPropertyQuery( |
20989 Local<String> property, | 21118 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); | 21119 if (property->Equals(v8_str("foo"))) info.GetReturnValue().Set(1); |
20992 } | 21120 } |
20993 | 21121 |
20994 | 21122 |
20995 void HasOwnPropertyNamedPropertyQuery2( | 21123 void HasOwnPropertyNamedPropertyQuery2( |
20996 Local<String> property, | 21124 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); | 21125 if (property->Equals(v8_str("bar"))) info.GetReturnValue().Set(1); |
20999 } | 21126 } |
21000 | 21127 |
21001 | 21128 |
21002 void HasOwnPropertyAccessorGetter( | 21129 void HasOwnPropertyAccessorGetter( |
21003 Local<String> property, | 21130 Local<String> property, |
21004 const v8::PropertyCallbackInfo<v8::Value>& info) { | 21131 const v8::PropertyCallbackInfo<v8::Value>& info) { |
21005 info.GetReturnValue().Set(v8_str("yes")); | 21132 info.GetReturnValue().Set(v8_str("yes")); |
21006 } | 21133 } |
21007 | 21134 |
(...skipping 18 matching lines...) Expand all Loading... |
21026 Handle<Object> object = value->ToObject(isolate); | 21153 Handle<Object> object = value->ToObject(isolate); |
21027 CHECK(object->Has(v8_str("foo"))); | 21154 CHECK(object->Has(v8_str("foo"))); |
21028 CHECK(!object->HasOwnProperty(v8_str("foo"))); | 21155 CHECK(!object->HasOwnProperty(v8_str("foo"))); |
21029 CHECK(object->HasOwnProperty(v8_str("bar"))); | 21156 CHECK(object->HasOwnProperty(v8_str("bar"))); |
21030 CHECK(object->Has(v8_str("baz"))); | 21157 CHECK(object->Has(v8_str("baz"))); |
21031 CHECK(!object->HasOwnProperty(v8_str("baz"))); | 21158 CHECK(!object->HasOwnProperty(v8_str("baz"))); |
21032 CHECK(object->HasOwnProperty(v8_str("bla"))); | 21159 CHECK(object->HasOwnProperty(v8_str("bla"))); |
21033 } | 21160 } |
21034 { // Check named getter interceptors. | 21161 { // Check named getter interceptors. |
21035 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 21162 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
21036 templ->SetNamedPropertyHandler(HasOwnPropertyNamedPropertyGetter); | 21163 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
| 21164 HasOwnPropertyNamedPropertyGetter)); |
21037 Handle<Object> instance = templ->NewInstance(); | 21165 Handle<Object> instance = templ->NewInstance(); |
21038 CHECK(!instance->HasOwnProperty(v8_str("42"))); | 21166 CHECK(!instance->HasOwnProperty(v8_str("42"))); |
21039 CHECK(instance->HasOwnProperty(v8_str("foo"))); | 21167 CHECK(instance->HasOwnProperty(v8_str("foo"))); |
21040 CHECK(!instance->HasOwnProperty(v8_str("bar"))); | 21168 CHECK(!instance->HasOwnProperty(v8_str("bar"))); |
21041 } | 21169 } |
21042 { // Check indexed getter interceptors. | 21170 { // Check indexed getter interceptors. |
21043 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 21171 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
21044 templ->SetIndexedPropertyHandler(HasOwnPropertyIndexedPropertyGetter); | 21172 templ->SetIndexedPropertyHandler(HasOwnPropertyIndexedPropertyGetter); |
21045 Handle<Object> instance = templ->NewInstance(); | 21173 Handle<Object> instance = templ->NewInstance(); |
21046 CHECK(instance->HasOwnProperty(v8_str("42"))); | 21174 CHECK(instance->HasOwnProperty(v8_str("42"))); |
21047 CHECK(!instance->HasOwnProperty(v8_str("43"))); | 21175 CHECK(!instance->HasOwnProperty(v8_str("43"))); |
21048 CHECK(!instance->HasOwnProperty(v8_str("foo"))); | 21176 CHECK(!instance->HasOwnProperty(v8_str("foo"))); |
21049 } | 21177 } |
21050 { // Check named query interceptors. | 21178 { // Check named query interceptors. |
21051 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 21179 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
21052 templ->SetNamedPropertyHandler(0, 0, HasOwnPropertyNamedPropertyQuery); | 21180 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
| 21181 0, 0, HasOwnPropertyNamedPropertyQuery)); |
21053 Handle<Object> instance = templ->NewInstance(); | 21182 Handle<Object> instance = templ->NewInstance(); |
21054 CHECK(instance->HasOwnProperty(v8_str("foo"))); | 21183 CHECK(instance->HasOwnProperty(v8_str("foo"))); |
21055 CHECK(!instance->HasOwnProperty(v8_str("bar"))); | 21184 CHECK(!instance->HasOwnProperty(v8_str("bar"))); |
21056 } | 21185 } |
21057 { // Check indexed query interceptors. | 21186 { // Check indexed query interceptors. |
21058 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 21187 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
21059 templ->SetIndexedPropertyHandler(0, 0, HasOwnPropertyIndexedPropertyQuery); | 21188 templ->SetIndexedPropertyHandler(0, 0, HasOwnPropertyIndexedPropertyQuery); |
21060 Handle<Object> instance = templ->NewInstance(); | 21189 Handle<Object> instance = templ->NewInstance(); |
21061 CHECK(instance->HasOwnProperty(v8_str("42"))); | 21190 CHECK(instance->HasOwnProperty(v8_str("42"))); |
21062 CHECK(!instance->HasOwnProperty(v8_str("41"))); | 21191 CHECK(!instance->HasOwnProperty(v8_str("41"))); |
21063 } | 21192 } |
21064 { // Check callbacks. | 21193 { // Check callbacks. |
21065 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 21194 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
21066 templ->SetAccessor(v8_str("foo"), HasOwnPropertyAccessorGetter); | 21195 templ->SetAccessor(v8_str("foo"), HasOwnPropertyAccessorGetter); |
21067 Handle<Object> instance = templ->NewInstance(); | 21196 Handle<Object> instance = templ->NewInstance(); |
21068 CHECK(instance->HasOwnProperty(v8_str("foo"))); | 21197 CHECK(instance->HasOwnProperty(v8_str("foo"))); |
21069 CHECK(!instance->HasOwnProperty(v8_str("bar"))); | 21198 CHECK(!instance->HasOwnProperty(v8_str("bar"))); |
21070 } | 21199 } |
21071 { // Check that query wins on disagreement. | 21200 { // Check that query wins on disagreement. |
21072 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 21201 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
21073 templ->SetNamedPropertyHandler(HasOwnPropertyNamedPropertyGetter, | 21202 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
21074 0, | 21203 HasOwnPropertyNamedPropertyGetter, 0, |
21075 HasOwnPropertyNamedPropertyQuery2); | 21204 HasOwnPropertyNamedPropertyQuery2)); |
21076 Handle<Object> instance = templ->NewInstance(); | 21205 Handle<Object> instance = templ->NewInstance(); |
21077 CHECK(!instance->HasOwnProperty(v8_str("foo"))); | 21206 CHECK(!instance->HasOwnProperty(v8_str("foo"))); |
21078 CHECK(instance->HasOwnProperty(v8_str("bar"))); | 21207 CHECK(instance->HasOwnProperty(v8_str("bar"))); |
21079 } | 21208 } |
21080 } | 21209 } |
21081 | 21210 |
21082 | 21211 |
21083 TEST(IndexedInterceptorWithStringProto) { | 21212 TEST(IndexedInterceptorWithStringProto) { |
21084 v8::Isolate* isolate = CcTest::isolate(); | 21213 v8::Isolate* isolate = CcTest::isolate(); |
21085 v8::HandleScope scope(isolate); | 21214 v8::HandleScope scope(isolate); |
(...skipping 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22192 } | 22321 } |
22193 | 22322 |
22194 | 22323 |
22195 static void Helper137002(bool do_store, | 22324 static void Helper137002(bool do_store, |
22196 bool polymorphic, | 22325 bool polymorphic, |
22197 bool remove_accessor, | 22326 bool remove_accessor, |
22198 bool interceptor) { | 22327 bool interceptor) { |
22199 LocalContext context; | 22328 LocalContext context; |
22200 Local<ObjectTemplate> templ = ObjectTemplate::New(context->GetIsolate()); | 22329 Local<ObjectTemplate> templ = ObjectTemplate::New(context->GetIsolate()); |
22201 if (interceptor) { | 22330 if (interceptor) { |
22202 templ->SetNamedPropertyHandler(FooGetInterceptor, FooSetInterceptor); | 22331 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(FooGetInterceptor, |
| 22332 FooSetInterceptor)); |
22203 } else { | 22333 } else { |
22204 templ->SetAccessor(v8_str("foo"), | 22334 templ->SetAccessor(v8_str("foo"), |
22205 GetterWhichReturns42, | 22335 GetterWhichReturns42, |
22206 SetterWhichSetsYOnThisTo23); | 22336 SetterWhichSetsYOnThisTo23); |
22207 } | 22337 } |
22208 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 22338 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
22209 | 22339 |
22210 // Turn monomorphic on slow object with native accessor, then turn | 22340 // Turn monomorphic on slow object with native accessor, then turn |
22211 // polymorphic, finally optimize to create negative lookup and fail. | 22341 // polymorphic, finally optimize to create negative lookup and fail. |
22212 CompileRun(do_store ? | 22342 CompileRun(do_store ? |
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22966 | 23096 |
22967 class RequestInterruptTestWithMethodCallAndInterceptor | 23097 class RequestInterruptTestWithMethodCallAndInterceptor |
22968 : public RequestInterruptTestBaseWithSimpleInterrupt { | 23098 : public RequestInterruptTestBaseWithSimpleInterrupt { |
22969 public: | 23099 public: |
22970 virtual void TestBody() { | 23100 virtual void TestBody() { |
22971 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); | 23101 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); |
22972 v8::Local<v8::Template> proto = t->PrototypeTemplate(); | 23102 v8::Local<v8::Template> proto = t->PrototypeTemplate(); |
22973 proto->Set(v8_str("shouldContinue"), Function::New( | 23103 proto->Set(v8_str("shouldContinue"), Function::New( |
22974 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this))); | 23104 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this))); |
22975 v8::Local<v8::ObjectTemplate> instance_template = t->InstanceTemplate(); | 23105 v8::Local<v8::ObjectTemplate> instance_template = t->InstanceTemplate(); |
22976 instance_template->SetNamedPropertyHandler(EmptyInterceptor); | 23106 instance_template->SetHandler( |
| 23107 v8::NamedPropertyHandlerConfiguration(EmptyInterceptor)); |
22977 | 23108 |
22978 env_->Global()->Set(v8_str("Klass"), t->GetFunction()); | 23109 env_->Global()->Set(v8_str("Klass"), t->GetFunction()); |
22979 | 23110 |
22980 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }"); | 23111 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }"); |
22981 } | 23112 } |
22982 | 23113 |
22983 private: | 23114 private: |
22984 static void EmptyInterceptor( | 23115 static void EmptyInterceptor( |
22985 Local<String> property, | 23116 Local<Name> property, const v8::PropertyCallbackInfo<v8::Value>& info) {} |
22986 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
22987 } | |
22988 }; | 23117 }; |
22989 | 23118 |
22990 | 23119 |
22991 class RequestInterruptTestWithMathAbs | 23120 class RequestInterruptTestWithMathAbs |
22992 : public RequestInterruptTestBaseWithSimpleInterrupt { | 23121 : public RequestInterruptTestBaseWithSimpleInterrupt { |
22993 public: | 23122 public: |
22994 virtual void TestBody() { | 23123 virtual void TestBody() { |
22995 env_->Global()->Set(v8_str("WakeUpInterruptor"), Function::New( | 23124 env_->Global()->Set(v8_str("WakeUpInterruptor"), Function::New( |
22996 isolate_, | 23125 isolate_, |
22997 WakeUpInterruptorCallback, | 23126 WakeUpInterruptorCallback, |
(...skipping 1255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
24253 v8::HandleScope scope(CcTest::isolate()); | 24382 v8::HandleScope scope(CcTest::isolate()); |
24254 RandomLengthOneByteResource* r = | 24383 RandomLengthOneByteResource* r = |
24255 new RandomLengthOneByteResource(i::String::kMaxLength); | 24384 new RandomLengthOneByteResource(i::String::kMaxLength); |
24256 v8::Local<v8::String> str = v8::String::NewExternal(CcTest::isolate(), r); | 24385 v8::Local<v8::String> str = v8::String::NewExternal(CcTest::isolate(), r); |
24257 CHECK(!str.IsEmpty()); | 24386 CHECK(!str.IsEmpty()); |
24258 v8::TryCatch try_catch; | 24387 v8::TryCatch try_catch; |
24259 v8::Local<v8::String> result = v8::String::Concat(str, str); | 24388 v8::Local<v8::String> result = v8::String::Concat(str, str); |
24260 CHECK(result.IsEmpty()); | 24389 CHECK(result.IsEmpty()); |
24261 CHECK(!try_catch.HasCaught()); | 24390 CHECK(!try_catch.HasCaught()); |
24262 } | 24391 } |
OLD | NEW |