Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 Handle<Object> result = CallTrap( | 227 Handle<Object> result = CallTrap( |
| 228 "get", isolate->derived_get_trap(), ARRAY_SIZE(args), args); | 228 "get", isolate->derived_get_trap(), ARRAY_SIZE(args), args); |
| 229 if (isolate->has_pending_exception()) return Failure::Exception(); | 229 if (isolate->has_pending_exception()) return Failure::Exception(); |
| 230 | 230 |
| 231 return *result; | 231 return *result; |
| 232 } | 232 } |
| 233 | 233 |
| 234 | 234 |
| 235 MaybeObject* JSProxy::GetElementWithHandler(Object* receiver, | 235 MaybeObject* JSProxy::GetElementWithHandler(Object* receiver, |
| 236 uint32_t index) { | 236 uint32_t index) { |
| 237 Heap* heap = GetHeap(); | |
| 238 Object* number; | |
| 239 MaybeObject* maybe = heap->NumberFromUint32(index); | |
| 240 if (!maybe->To<Object>(&number)) return maybe; | |
| 241 maybe = heap->NumberToString(number); | |
| 242 String* name; | 237 String* name; |
| 238 MaybeObject* maybe = GetHeap()->Uint32ToString(index); | |
| 243 if (!maybe->To<String>(&name)) return maybe; | 239 if (!maybe->To<String>(&name)) return maybe; |
| 244 return GetPropertyWithHandler(receiver, name); | 240 return GetPropertyWithHandler(receiver, name); |
| 245 } | 241 } |
| 246 | 242 |
| 247 | 243 |
| 244 MaybeObject* JSProxy::SetElementWithHandler(uint32_t index, | |
| 245 Object* value, | |
| 246 StrictModeFlag strict_mode) { | |
| 247 String* name; | |
| 248 MaybeObject* maybe = GetHeap()->Uint32ToString(index); | |
| 249 if (!maybe->To<String>(&name)) return maybe; | |
| 250 return SetPropertyWithHandler(name, value, NONE, strict_mode); | |
| 251 } | |
| 252 | |
| 253 | |
| 254 bool JSProxy::HasElementWithHandler(uint32_t index) { | |
| 255 String* name; | |
| 256 MaybeObject* maybe = GetHeap()->Uint32ToString(index); | |
| 257 if (!maybe->To<String>(&name)) return maybe; | |
| 258 return HasPropertyWithHandler(name); | |
| 259 } | |
| 260 | |
| 261 | |
| 248 MaybeObject* Object::GetPropertyWithDefinedGetter(Object* receiver, | 262 MaybeObject* Object::GetPropertyWithDefinedGetter(Object* receiver, |
| 249 JSFunction* getter) { | 263 JSFunction* getter) { |
| 250 HandleScope scope; | 264 HandleScope scope; |
| 251 Handle<JSFunction> fun(JSFunction::cast(getter)); | 265 Handle<JSFunction> fun(JSFunction::cast(getter)); |
| 252 Handle<Object> self(receiver); | 266 Handle<Object> self(receiver); |
| 253 #ifdef ENABLE_DEBUGGER_SUPPORT | 267 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 254 Debug* debug = fun->GetHeap()->isolate()->debug(); | 268 Debug* debug = fun->GetHeap()->isolate()->debug(); |
| 255 // Handle stepping into a getter if step into is active. | 269 // Handle stepping into a getter if step into is active. |
| 256 if (debug->StepInActive()) { | 270 if (debug->StepInActive()) { |
| 257 debug->HandleStepIn(fun, Handle<Object>::null(), 0, false); | 271 debug->HandleStepIn(fun, Handle<Object>::null(), 0, false); |
| (...skipping 1661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1919 | 1933 |
| 1920 MaybeObject* JSObject::SetElementWithCallbackSetterInPrototypes( | 1934 MaybeObject* JSObject::SetElementWithCallbackSetterInPrototypes( |
| 1921 uint32_t index, | 1935 uint32_t index, |
| 1922 Object* value, | 1936 Object* value, |
| 1923 bool* found, | 1937 bool* found, |
| 1924 StrictModeFlag strict_mode) { | 1938 StrictModeFlag strict_mode) { |
| 1925 Heap* heap = GetHeap(); | 1939 Heap* heap = GetHeap(); |
| 1926 for (Object* pt = GetPrototype(); | 1940 for (Object* pt = GetPrototype(); |
| 1927 pt != heap->null_value(); | 1941 pt != heap->null_value(); |
| 1928 pt = pt->GetPrototype()) { | 1942 pt = pt->GetPrototype()) { |
| 1943 if (pt->IsJSProxy()) { | |
| 1944 String* name; | |
| 1945 MaybeObject* maybe = GetHeap()->Uint32ToString(index); | |
| 1946 if (!maybe->To<String>(&name)) { | |
| 1947 *found = true; // Force abort | |
| 1948 return maybe; | |
| 1949 } | |
| 1950 return JSProxy::cast(pt)->SetPropertyWithHandlerIfDefiningSetter( | |
| 1951 name, value, NONE, strict_mode, found); | |
| 1952 } | |
| 1929 if (!JSObject::cast(pt)->HasDictionaryElements()) { | 1953 if (!JSObject::cast(pt)->HasDictionaryElements()) { |
| 1930 continue; | 1954 continue; |
| 1931 } | 1955 } |
| 1932 NumberDictionary* dictionary = JSObject::cast(pt)->element_dictionary(); | 1956 NumberDictionary* dictionary = JSObject::cast(pt)->element_dictionary(); |
| 1933 int entry = dictionary->FindEntry(index); | 1957 int entry = dictionary->FindEntry(index); |
| 1934 if (entry != NumberDictionary::kNotFound) { | 1958 if (entry != NumberDictionary::kNotFound) { |
| 1935 PropertyDetails details = dictionary->DetailsAt(entry); | 1959 PropertyDetails details = dictionary->DetailsAt(entry); |
| 1936 if (details.type() == CALLBACKS) { | 1960 if (details.type() == CALLBACKS) { |
| 1937 *found = true; | 1961 *found = true; |
| 1938 return SetElementWithCallback(dictionary->ValueAt(entry), | 1962 return SetElementWithCallback(dictionary->ValueAt(entry), |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2254 Handle<Object> value(value_raw); | 2278 Handle<Object> value(value_raw); |
| 2255 | 2279 |
| 2256 Handle<Object> args[] = { receiver, name, value }; | 2280 Handle<Object> args[] = { receiver, name, value }; |
| 2257 CallTrap("set", isolate->derived_set_trap(), ARRAY_SIZE(args), args); | 2281 CallTrap("set", isolate->derived_set_trap(), ARRAY_SIZE(args), args); |
| 2258 if (isolate->has_pending_exception()) return Failure::Exception(); | 2282 if (isolate->has_pending_exception()) return Failure::Exception(); |
| 2259 | 2283 |
| 2260 return *value; | 2284 return *value; |
| 2261 } | 2285 } |
| 2262 | 2286 |
| 2263 | 2287 |
| 2288 MUST_USE_RESULT MaybeObject* JSProxy::SetPropertyWithHandlerIfDefiningSetter( | |
| 2289 String* name, | |
| 2290 Object* value, | |
| 2291 PropertyAttributes attributes, | |
| 2292 StrictModeFlag strict_mode, | |
| 2293 bool* found) { | |
| 2294 *found = true; // except where defined otherwise... | |
| 2295 Isolate* isolate = GetHeap()->isolate(); | |
| 2296 Handle<JSProxy> proxy(this); | |
| 2297 Handle<String> hname(name); | |
| 2298 Handle<Object> hvalue(value); | |
| 2299 Handle<Object> args[] = { hname }; | |
| 2300 Handle<Object> result = proxy->CallTrap( | |
| 2301 "getOwnPropertyDescriptor", Handle<Object>(), ARRAY_SIZE(args), args); | |
| 2302 if (isolate->has_pending_exception()) return Failure::Exception(); | |
| 2303 | |
| 2304 if (!result->IsUndefined()) { | |
| 2305 // The proxy handler cares about this property. | |
| 2306 // Check whether it is virtualized as an accessor. | |
| 2307 // Emulate [[GetProperty]] semantics for proxies. | |
| 2308 bool has_pending_exception; | |
| 2309 Object** argv[] = { result.location() }; | |
| 2310 Handle<Object> desc = | |
| 2311 Execution::Call(isolate->to_complete_property_descriptor(), result, | |
| 2312 ARRAY_SIZE(argv), argv, &has_pending_exception); | |
| 2313 if (has_pending_exception) return Failure::Exception(); | |
| 2314 | |
| 2315 Handle<String> conf_name = | |
| 2316 isolate->factory()->LookupAsciiSymbol("configurable_"); | |
| 2317 Handle<Object> configurable(v8::internal::GetProperty(desc, conf_name)); | |
| 2318 ASSERT(!isolate->has_pending_exception()); | |
| 2319 if (configurable->IsFalse()) { | |
| 2320 Handle<Object> args[] = { Handle<Object>(proxy->handler()), proxy, hname } ; | |
|
Rico
2011/09/14 11:26:50
Long line
rossberg
2011/09/15 09:00:13
Done.
| |
| 2321 Handle<Object> error = isolate->factory()->NewTypeError( | |
| 2322 "proxy_prop_not_configurable", HandleVector(args, ARRAY_SIZE(args))); | |
| 2323 return isolate->Throw(*error); | |
| 2324 } | |
| 2325 ASSERT(configurable->IsTrue()); | |
| 2326 | |
| 2327 // Check for AccessorDescriptor. | |
| 2328 Handle<String> set_name = isolate->factory()->LookupAsciiSymbol("set_"); | |
| 2329 Handle<Object> setter(v8::internal::GetProperty(desc, set_name)); | |
| 2330 ASSERT(!isolate->has_pending_exception()); | |
| 2331 if (!setter->IsUndefined()) { | |
| 2332 // We have a setter -- invoke it. | |
| 2333 return proxy->SetPropertyWithDefinedSetter( | |
| 2334 JSFunction::cast(*setter), *hvalue); | |
| 2335 } else { | |
| 2336 Handle<String> get_name = isolate->factory()->LookupAsciiSymbol("get_"); | |
| 2337 Handle<Object> getter(v8::internal::GetProperty(desc, get_name)); | |
| 2338 ASSERT(!isolate->has_pending_exception()); | |
| 2339 if (!getter->IsUndefined()) { | |
| 2340 // We have a getter but no setter -- the property may not be | |
| 2341 // written. In strict mode, throw an error. | |
| 2342 if (strict_mode == kNonStrictMode) return *hvalue; | |
| 2343 Handle<Object> args[] = { hname, proxy }; | |
| 2344 Handle<Object> error = isolate->factory()->NewTypeError( | |
| 2345 "no_setter_in_callback", HandleVector(args, ARRAY_SIZE(args))); | |
| 2346 return isolate->Throw(*error); | |
| 2347 } | |
| 2348 } | |
| 2349 // Fall-through. | |
| 2350 } | |
| 2351 | |
| 2352 // The proxy does not define the property as an accessor. | |
| 2353 *found = false; | |
| 2354 return value; | |
| 2355 } | |
| 2356 | |
| 2357 | |
| 2264 MUST_USE_RESULT MaybeObject* JSProxy::DeletePropertyWithHandler( | 2358 MUST_USE_RESULT MaybeObject* JSProxy::DeletePropertyWithHandler( |
| 2265 String* name_raw, DeleteMode mode) { | 2359 String* name_raw, DeleteMode mode) { |
| 2266 Isolate* isolate = GetIsolate(); | 2360 Isolate* isolate = GetIsolate(); |
| 2267 HandleScope scope(isolate); | 2361 HandleScope scope(isolate); |
| 2268 Handle<Object> receiver(this); | 2362 Handle<Object> receiver(this); |
| 2269 Handle<Object> name(name_raw); | 2363 Handle<Object> name(name_raw); |
| 2270 | 2364 |
| 2271 Handle<Object> args[] = { name }; | 2365 Handle<Object> args[] = { name }; |
| 2272 Handle<Object> result = CallTrap( | 2366 Handle<Object> result = CallTrap( |
| 2273 "delete", Handle<Object>(), ARRAY_SIZE(args), args); | 2367 "delete", Handle<Object>(), ARRAY_SIZE(args), args); |
| 2274 if (isolate->has_pending_exception()) return Failure::Exception(); | 2368 if (isolate->has_pending_exception()) return Failure::Exception(); |
| 2275 | 2369 |
| 2276 Object* bool_result = result->ToBoolean(); | 2370 Object* bool_result = result->ToBoolean(); |
| 2277 if (mode == STRICT_DELETION && bool_result == GetHeap()->false_value()) { | 2371 if (mode == STRICT_DELETION && bool_result == GetHeap()->false_value()) { |
| 2278 Handle<String> trap_name = isolate->factory()->LookupAsciiSymbol("delete"); | 2372 Handle<String> trap_name = isolate->factory()->LookupAsciiSymbol("delete"); |
| 2279 Handle<Object> args[] = { Handle<Object>(handler()), trap_name }; | 2373 Handle<Object> args[] = { Handle<Object>(handler()), trap_name }; |
| 2280 Handle<Object> error = isolate->factory()->NewTypeError( | 2374 Handle<Object> error = isolate->factory()->NewTypeError( |
| 2281 "handler_failed", HandleVector(args, ARRAY_SIZE(args))); | 2375 "handler_failed", HandleVector(args, ARRAY_SIZE(args))); |
| 2282 isolate->Throw(*error); | 2376 isolate->Throw(*error); |
| 2283 return Failure::Exception(); | 2377 return Failure::Exception(); |
| 2284 } | 2378 } |
| 2285 return bool_result; | 2379 return bool_result; |
| 2286 } | 2380 } |
| 2287 | 2381 |
| 2288 | 2382 |
| 2383 MUST_USE_RESULT MaybeObject* JSProxy::DeleteElementWithHandler( | |
| 2384 uint32_t index, | |
| 2385 DeleteMode mode) { | |
| 2386 Isolate* isolate = GetIsolate(); | |
| 2387 HandleScope scope(isolate); | |
| 2388 Handle<String> name = isolate->factory()->Uint32ToString(index); | |
| 2389 return JSProxy::DeletePropertyWithHandler(*name, mode); | |
| 2390 } | |
| 2391 | |
| 2392 | |
| 2289 MUST_USE_RESULT PropertyAttributes JSProxy::GetPropertyAttributeWithHandler( | 2393 MUST_USE_RESULT PropertyAttributes JSProxy::GetPropertyAttributeWithHandler( |
| 2290 JSReceiver* receiver_raw, | 2394 JSReceiver* receiver_raw, |
| 2291 String* name_raw) { | 2395 String* name_raw) { |
| 2292 Isolate* isolate = GetIsolate(); | 2396 Isolate* isolate = GetIsolate(); |
| 2293 HandleScope scope(isolate); | 2397 HandleScope scope(isolate); |
| 2398 Handle<JSProxy> proxy(this); | |
| 2294 Handle<JSReceiver> receiver(receiver_raw); | 2399 Handle<JSReceiver> receiver(receiver_raw); |
| 2295 Handle<Object> name(name_raw); | 2400 Handle<Object> name(name_raw); |
| 2296 | 2401 |
| 2297 Handle<Object> args[] = { name }; | 2402 Handle<Object> args[] = { name }; |
| 2298 Handle<Object> result = CallTrap( | 2403 Handle<Object> result = CallTrap( |
| 2299 "getPropertyDescriptor", Handle<Object>(), ARRAY_SIZE(args), args); | 2404 "getPropertyDescriptor", Handle<Object>(), ARRAY_SIZE(args), args); |
| 2300 if (isolate->has_pending_exception()) return NONE; | 2405 if (isolate->has_pending_exception()) return NONE; |
| 2301 | 2406 |
| 2302 if (result->IsUndefined()) return ABSENT; | 2407 if (result->IsUndefined()) return ABSENT; |
| 2303 | 2408 |
| 2304 bool has_pending_exception; | 2409 bool has_pending_exception; |
| 2305 Object** argv[] = { result.location() }; | 2410 Object** argv[] = { result.location() }; |
| 2306 Handle<Object> desc = | 2411 Handle<Object> desc = |
| 2307 Execution::Call(isolate->to_complete_property_descriptor(), result, | 2412 Execution::Call(isolate->to_complete_property_descriptor(), result, |
| 2308 ARRAY_SIZE(argv), argv, &has_pending_exception); | 2413 ARRAY_SIZE(argv), argv, &has_pending_exception); |
| 2309 if (has_pending_exception) return NONE; | 2414 if (has_pending_exception) return NONE; |
| 2310 | 2415 |
| 2311 // Convert result to PropertyAttributes. | 2416 // Convert result to PropertyAttributes. |
| 2312 Handle<String> enum_name = isolate->factory()->LookupAsciiSymbol("enumerable") ; | 2417 Handle<String> enum_name = isolate->factory()->LookupAsciiSymbol("enumerable_" ); |
|
Rico
2011/09/14 11:26:50
Long line
rossberg
2011/09/15 09:00:13
Done.
| |
| 2313 Handle<Object> enumerable(v8::internal::GetProperty(desc, enum_name)); | 2418 Handle<Object> enumerable(v8::internal::GetProperty(desc, enum_name)); |
| 2314 if (isolate->has_pending_exception()) return NONE; | 2419 if (isolate->has_pending_exception()) return NONE; |
| 2315 Handle<String> conf_name = isolate->factory()->LookupAsciiSymbol("configurable "); | 2420 Handle<String> conf_name = isolate->factory()->LookupAsciiSymbol("configurable _"); |
|
Rico
2011/09/14 11:26:50
Long line
rossberg
2011/09/15 09:00:13
Done.
| |
| 2316 Handle<Object> configurable(v8::internal::GetProperty(desc, conf_name)); | 2421 Handle<Object> configurable(v8::internal::GetProperty(desc, conf_name)); |
| 2317 if (isolate->has_pending_exception()) return NONE; | 2422 if (isolate->has_pending_exception()) return NONE; |
| 2318 Handle<String> writ_name = isolate->factory()->LookupAsciiSymbol("writable"); | 2423 Handle<String> writ_name = isolate->factory()->LookupAsciiSymbol("writable_"); |
| 2319 Handle<Object> writable(v8::internal::GetProperty(desc, writ_name)); | 2424 Handle<Object> writable(v8::internal::GetProperty(desc, writ_name)); |
| 2320 if (isolate->has_pending_exception()) return NONE; | 2425 if (isolate->has_pending_exception()) return NONE; |
| 2321 | 2426 |
| 2427 if (configurable->IsFalse()) { | |
| 2428 Handle<Object> args[] = { Handle<Object>(proxy->handler()), proxy, name }; | |
| 2429 Handle<Object> error = isolate->factory()->NewTypeError( | |
| 2430 "proxy_prop_not_configurable", HandleVector(args, ARRAY_SIZE(args))); | |
| 2431 isolate->Throw(*error); | |
| 2432 return NONE; | |
| 2433 } | |
| 2434 | |
| 2322 int attributes = NONE; | 2435 int attributes = NONE; |
| 2323 if (enumerable->ToBoolean()->IsFalse()) attributes |= DONT_ENUM; | 2436 if (enumerable->ToBoolean()->IsFalse()) attributes |= DONT_ENUM; |
| 2324 if (configurable->ToBoolean()->IsFalse()) attributes |= DONT_DELETE; | 2437 if (configurable->ToBoolean()->IsFalse()) attributes |= DONT_DELETE; |
| 2325 if (writable->ToBoolean()->IsFalse()) attributes |= READ_ONLY; | 2438 if (writable->ToBoolean()->IsFalse()) attributes |= READ_ONLY; |
| 2326 return static_cast<PropertyAttributes>(attributes); | 2439 return static_cast<PropertyAttributes>(attributes); |
| 2327 } | 2440 } |
| 2328 | 2441 |
| 2329 | 2442 |
| 2443 MUST_USE_RESULT PropertyAttributes JSProxy::GetElementAttributeWithHandler( | |
| 2444 JSReceiver* receiver, | |
| 2445 uint32_t index) { | |
| 2446 Isolate* isolate = GetIsolate(); | |
| 2447 HandleScope scope(isolate); | |
| 2448 Handle<String> name = isolate->factory()->Uint32ToString(index); | |
| 2449 return GetPropertyAttributeWithHandler(receiver, *name); | |
| 2450 } | |
| 2451 | |
| 2452 | |
| 2330 void JSProxy::Fix() { | 2453 void JSProxy::Fix() { |
| 2331 Isolate* isolate = GetIsolate(); | 2454 Isolate* isolate = GetIsolate(); |
| 2332 HandleScope scope(isolate); | 2455 HandleScope scope(isolate); |
| 2333 Handle<JSProxy> self(this); | 2456 Handle<JSProxy> self(this); |
| 2334 | 2457 |
| 2335 if (IsJSFunctionProxy()) { | 2458 if (IsJSFunctionProxy()) { |
| 2336 isolate->factory()->BecomeJSFunction(self); | 2459 isolate->factory()->BecomeJSFunction(self); |
| 2337 // Code will be set on the JavaScript side. | 2460 // Code will be set on the JavaScript side. |
| 2338 } else { | 2461 } else { |
| 2339 isolate->factory()->BecomeJSObject(self); | 2462 isolate->factory()->BecomeJSObject(self); |
| 2340 } | 2463 } |
| 2341 ASSERT(self->IsJSObject()); | 2464 ASSERT(self->IsJSObject()); |
| 2342 } | 2465 } |
| 2343 | 2466 |
| 2344 | 2467 |
| 2345 MUST_USE_RESULT Handle<Object> JSProxy::CallTrap( | 2468 MUST_USE_RESULT Handle<Object> JSProxy::CallTrap( |
| 2346 const char* name, | 2469 const char* name, |
| 2347 Handle<Object> derived, | 2470 Handle<Object> derived, |
| 2348 int argc, | 2471 int argc, |
| 2349 Handle<Object> args[]) { | 2472 Handle<Object> args[]) { |
| 2350 Isolate* isolate = GetIsolate(); | 2473 Isolate* isolate = GetIsolate(); |
| 2351 Handle<Object> handler(this->handler()); | 2474 Handle<Object> handler(this->handler()); |
| 2352 | 2475 |
| 2353 Handle<String> trap_name = isolate->factory()->LookupAsciiSymbol(name); | 2476 Handle<String> trap_name = isolate->factory()->LookupAsciiSymbol(name); |
| 2354 Handle<Object> trap(v8::internal::GetProperty(handler, trap_name)); | 2477 Handle<Object> trap(v8::internal::GetProperty(handler, trap_name)); |
| 2355 if (isolate->has_pending_exception()) return trap; | 2478 if (isolate->has_pending_exception()) return trap; |
| 2356 | 2479 |
| 2357 if (trap->IsUndefined()) { | 2480 if (trap->IsUndefined()) { |
| 2358 if (*derived == NULL) { | 2481 if (derived.is_null()) { |
| 2359 Handle<Object> args[] = { handler, trap_name }; | 2482 Handle<Object> args[] = { handler, trap_name }; |
| 2360 Handle<Object> error = isolate->factory()->NewTypeError( | 2483 Handle<Object> error = isolate->factory()->NewTypeError( |
| 2361 "handler_trap_missing", HandleVector(args, ARRAY_SIZE(args))); | 2484 "handler_trap_missing", HandleVector(args, ARRAY_SIZE(args))); |
| 2362 isolate->Throw(*error); | 2485 isolate->Throw(*error); |
| 2363 return Handle<Object>(); | 2486 return Handle<Object>(); |
| 2364 } | 2487 } |
| 2365 trap = Handle<Object>(derived); | 2488 trap = Handle<Object>(derived); |
| 2366 } | 2489 } |
| 2367 | 2490 |
| 2368 Object*** argv = reinterpret_cast<Object***>(args); | 2491 Object*** argv = reinterpret_cast<Object***>(args); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2417 if (accessor_result.IsFound()) { | 2540 if (accessor_result.IsFound()) { |
| 2418 if (accessor_result.type() == CALLBACKS) { | 2541 if (accessor_result.type() == CALLBACKS) { |
| 2419 return SetPropertyWithCallback(accessor_result.GetCallbackObject(), | 2542 return SetPropertyWithCallback(accessor_result.GetCallbackObject(), |
| 2420 name, | 2543 name, |
| 2421 value, | 2544 value, |
| 2422 accessor_result.holder(), | 2545 accessor_result.holder(), |
| 2423 strict_mode); | 2546 strict_mode); |
| 2424 } else if (accessor_result.type() == HANDLER) { | 2547 } else if (accessor_result.type() == HANDLER) { |
| 2425 // There is a proxy in the prototype chain. Invoke its | 2548 // There is a proxy in the prototype chain. Invoke its |
| 2426 // getOwnPropertyDescriptor trap. | 2549 // getOwnPropertyDescriptor trap. |
| 2427 Isolate* isolate = heap->isolate(); | 2550 bool found = false; |
| 2428 Handle<JSObject> self(this); | 2551 Handle<JSObject> self(this); |
| 2429 Handle<String> hname(name); | 2552 Handle<String> hname(name); |
| 2430 Handle<Object> hvalue(value); | 2553 Handle<Object> hvalue(value); |
| 2431 Handle<JSProxy> proxy(accessor_result.proxy()); | 2554 MaybeObject* result = |
| 2432 Handle<Object> args[] = { hname }; | 2555 accessor_result.proxy()->SetPropertyWithHandlerIfDefiningSetter( |
| 2433 Handle<Object> result = proxy->CallTrap( | 2556 name, value, attributes, strict_mode, &found); |
| 2434 "getOwnPropertyDescriptor", Handle<Object>(), ARRAY_SIZE(args), args); | 2557 if (found) return result; |
| 2435 if (isolate->has_pending_exception()) return Failure::Exception(); | 2558 // The proxy does not define the property as an accessor. |
| 2436 | 2559 // Consequently, it has no effect on setting the receiver. |
| 2437 if (!result->IsUndefined()) { | 2560 return self->AddProperty(*hname, *hvalue, attributes, strict_mode); |
| 2438 // The proxy handler cares about this property. | |
| 2439 // Check whether it is virtualized as an accessor. | |
| 2440 Handle<String> getter_name = | |
| 2441 isolate->factory()->LookupAsciiSymbol("get"); | |
| 2442 Handle<Object> getter( | |
| 2443 v8::internal::GetProperty(result, getter_name)); | |
| 2444 if (isolate->has_pending_exception()) return Failure::Exception(); | |
| 2445 Handle<String> setter_name = | |
| 2446 isolate->factory()->LookupAsciiSymbol("set"); | |
| 2447 Handle<Object> setter( | |
| 2448 v8::internal::GetProperty(result, setter_name)); | |
| 2449 if (isolate->has_pending_exception()) return Failure::Exception(); | |
| 2450 | |
| 2451 if (!setter->IsUndefined()) { | |
| 2452 // We have a setter -- invoke it. | |
| 2453 if (setter->IsJSFunction()) { | |
| 2454 return proxy->SetPropertyWithDefinedSetter( | |
| 2455 JSFunction::cast(*setter), *hvalue); | |
| 2456 } | |
| 2457 Handle<Object> args[] = { setter }; | |
| 2458 Handle<Object> error = isolate->factory()->NewTypeError( | |
| 2459 "setter_must_be_callable", HandleVector(args, ARRAY_SIZE(args))); | |
| 2460 return isolate->Throw(*error); | |
| 2461 } else if (!getter->IsUndefined()) { | |
| 2462 // We have a getter but no setter -- the property may not be | |
| 2463 // written. In strict mode, throw an error. | |
| 2464 if (strict_mode == kNonStrictMode) return *hvalue; | |
| 2465 Handle<Object> args[] = { hname, proxy }; | |
| 2466 Handle<Object> error = isolate->factory()->NewTypeError( | |
| 2467 "no_setter_in_callback", HandleVector(args, ARRAY_SIZE(args))); | |
| 2468 return isolate->Throw(*error); | |
| 2469 } | |
| 2470 // The proxy does not define the property as an accessor. | |
| 2471 // Consequently, it has no effect on setting the receiver. | |
| 2472 return self->AddProperty(*hname, *hvalue, attributes, strict_mode); | |
| 2473 } | |
| 2474 } | 2561 } |
| 2475 } | 2562 } |
| 2476 } | 2563 } |
| 2477 | 2564 |
| 2478 // At this point, no GC should have happened, as this would invalidate | 2565 // At this point, no GC should have happened, as this would invalidate |
| 2479 // 'result', which we cannot handlify! | 2566 // 'result', which we cannot handlify! |
| 2480 | 2567 |
| 2481 if (!result->IsFound()) { | 2568 if (!result->IsFound()) { |
| 2482 // Neither properties nor transitions found. | 2569 // Neither properties nor transitions found. |
| 2483 return AddProperty(name, value, attributes, strict_mode); | 2570 return AddProperty(name, value, attributes, strict_mode); |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2710 *name_handle, | 2797 *name_handle, |
| 2711 continue_search); | 2798 continue_search); |
| 2712 } | 2799 } |
| 2713 | 2800 |
| 2714 | 2801 |
| 2715 PropertyAttributes JSReceiver::GetPropertyAttributeWithReceiver( | 2802 PropertyAttributes JSReceiver::GetPropertyAttributeWithReceiver( |
| 2716 JSReceiver* receiver, | 2803 JSReceiver* receiver, |
| 2717 String* key) { | 2804 String* key) { |
| 2718 uint32_t index = 0; | 2805 uint32_t index = 0; |
| 2719 if (IsJSObject() && key->AsArrayIndex(&index)) { | 2806 if (IsJSObject() && key->AsArrayIndex(&index)) { |
| 2720 if (JSObject::cast(this)->HasElementWithReceiver(receiver, index)) | 2807 return JSObject::cast(this)->HasElementWithReceiver(receiver, index) |
| 2721 return NONE; | 2808 ? NONE : ABSENT; |
| 2722 return ABSENT; | |
| 2723 } | 2809 } |
| 2724 // Named property. | 2810 // Named property. |
| 2725 LookupResult result; | 2811 LookupResult result; |
| 2726 Lookup(key, &result); | 2812 Lookup(key, &result); |
| 2727 return GetPropertyAttribute(receiver, &result, key, true); | 2813 return GetPropertyAttribute(receiver, &result, key, true); |
| 2728 } | 2814 } |
| 2729 | 2815 |
| 2730 | 2816 |
| 2731 PropertyAttributes JSReceiver::GetPropertyAttribute(JSReceiver* receiver, | 2817 PropertyAttributes JSReceiver::GetPropertyAttribute(JSReceiver* receiver, |
| 2732 LookupResult* result, | 2818 LookupResult* result, |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3245 mode = JSReceiver::FORCE_DELETION; | 3331 mode = JSReceiver::FORCE_DELETION; |
| 3246 } | 3332 } |
| 3247 | 3333 |
| 3248 return GetElementsAccessor()->Delete(this, index, mode); | 3334 return GetElementsAccessor()->Delete(this, index, mode); |
| 3249 } | 3335 } |
| 3250 | 3336 |
| 3251 | 3337 |
| 3252 MaybeObject* JSReceiver::DeleteProperty(String* name, DeleteMode mode) { | 3338 MaybeObject* JSReceiver::DeleteProperty(String* name, DeleteMode mode) { |
| 3253 if (IsJSProxy()) { | 3339 if (IsJSProxy()) { |
| 3254 return JSProxy::cast(this)->DeletePropertyWithHandler(name, mode); | 3340 return JSProxy::cast(this)->DeletePropertyWithHandler(name, mode); |
| 3255 } else { | |
| 3256 return JSObject::cast(this)->DeleteProperty(name, mode); | |
| 3257 } | 3341 } |
| 3342 return JSObject::cast(this)->DeleteProperty(name, mode); | |
| 3258 } | 3343 } |
| 3259 | 3344 |
| 3260 | 3345 |
| 3346 MaybeObject* JSReceiver::DeleteElement(uint32_t index, DeleteMode mode) { | |
| 3347 if (IsJSProxy()) { | |
| 3348 return JSProxy::cast(this)->DeleteElementWithHandler(index, mode); | |
| 3349 } | |
| 3350 return JSObject::cast(this)->DeleteElement(index, mode); | |
| 3351 } | |
| 3352 | |
| 3353 | |
| 3261 MaybeObject* JSObject::DeleteProperty(String* name, DeleteMode mode) { | 3354 MaybeObject* JSObject::DeleteProperty(String* name, DeleteMode mode) { |
| 3262 Isolate* isolate = GetIsolate(); | 3355 Isolate* isolate = GetIsolate(); |
| 3263 // ECMA-262, 3rd, 8.6.2.5 | 3356 // ECMA-262, 3rd, 8.6.2.5 |
| 3264 ASSERT(name->IsString()); | 3357 ASSERT(name->IsString()); |
| 3265 | 3358 |
| 3266 // Check access rights if needed. | 3359 // Check access rights if needed. |
| 3267 if (IsAccessCheckNeeded() && | 3360 if (IsAccessCheckNeeded() && |
| 3268 !isolate->MayNamedAccess(this, name, v8::ACCESS_DELETE)) { | 3361 !isolate->MayNamedAccess(this, name, v8::ACCESS_DELETE)) { |
| 3269 isolate->ReportFailedAccessCheck(this, v8::ACCESS_DELETE); | 3362 isolate->ReportFailedAccessCheck(this, v8::ACCESS_DELETE); |
| 3270 return isolate->heap()->false_value(); | 3363 return isolate->heap()->false_value(); |
| (...skipping 4609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7880 case NON_STRICT_ARGUMENTS_ELEMENTS: | 7973 case NON_STRICT_ARGUMENTS_ELEMENTS: |
| 7881 UNREACHABLE(); | 7974 UNREACHABLE(); |
| 7882 break; | 7975 break; |
| 7883 } | 7976 } |
| 7884 | 7977 |
| 7885 // Handle [] on String objects. | 7978 // Handle [] on String objects. |
| 7886 if (this->IsStringObjectWithCharacterAt(index)) return true; | 7979 if (this->IsStringObjectWithCharacterAt(index)) return true; |
| 7887 | 7980 |
| 7888 Object* pt = GetPrototype(); | 7981 Object* pt = GetPrototype(); |
| 7889 if (pt->IsNull()) return false; | 7982 if (pt->IsNull()) return false; |
| 7983 if (pt->IsJSProxy()) { | |
| 7984 // We need to follow the spec and simulate a call to [[GetOwnProperty]]. | |
| 7985 return JSProxy::cast(pt)->GetElementAttributeWithHandler( | |
| 7986 receiver, index) != ABSENT; | |
| 7987 } | |
| 7890 return JSObject::cast(pt)->HasElementWithReceiver(receiver, index); | 7988 return JSObject::cast(pt)->HasElementWithReceiver(receiver, index); |
| 7891 } | 7989 } |
| 7892 | 7990 |
| 7893 | 7991 |
| 7894 bool JSObject::HasElementWithInterceptor(JSReceiver* receiver, uint32_t index) { | 7992 bool JSObject::HasElementWithInterceptor(JSReceiver* receiver, uint32_t index) { |
| 7895 Isolate* isolate = GetIsolate(); | 7993 Isolate* isolate = GetIsolate(); |
| 7896 // Make sure that the top context does not change when doing | 7994 // Make sure that the top context does not change when doing |
| 7897 // callbacks or interceptor calls. | 7995 // callbacks or interceptor calls. |
| 7898 AssertNoContextChange ncc; | 7996 AssertNoContextChange ncc; |
| 7899 HandleScope scope(isolate); | 7997 HandleScope scope(isolate); |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8136 if (HasElementInElements(arguments, kind, index)) return true; | 8234 if (HasElementInElements(arguments, kind, index)) return true; |
| 8137 break; | 8235 break; |
| 8138 } | 8236 } |
| 8139 } | 8237 } |
| 8140 | 8238 |
| 8141 // Handle [] on String objects. | 8239 // Handle [] on String objects. |
| 8142 if (this->IsStringObjectWithCharacterAt(index)) return true; | 8240 if (this->IsStringObjectWithCharacterAt(index)) return true; |
| 8143 | 8241 |
| 8144 Object* pt = GetPrototype(); | 8242 Object* pt = GetPrototype(); |
| 8145 if (pt->IsNull()) return false; | 8243 if (pt->IsNull()) return false; |
| 8244 if (pt->IsJSProxy()) { | |
| 8245 // We need to follow the spec and simulate a call to [[GetOwnProperty]]. | |
| 8246 return JSProxy::cast(pt)->GetElementAttributeWithHandler( | |
| 8247 receiver, index) != ABSENT; | |
| 8248 } | |
| 8146 return JSObject::cast(pt)->HasElementWithReceiver(receiver, index); | 8249 return JSObject::cast(pt)->HasElementWithReceiver(receiver, index); |
| 8147 } | 8250 } |
| 8148 | 8251 |
| 8149 | 8252 |
| 8150 MaybeObject* JSObject::SetElementWithInterceptor(uint32_t index, | 8253 MaybeObject* JSObject::SetElementWithInterceptor(uint32_t index, |
| 8151 Object* value, | 8254 Object* value, |
| 8152 StrictModeFlag strict_mode, | 8255 StrictModeFlag strict_mode, |
| 8153 bool check_prototype) { | 8256 bool check_prototype) { |
| 8154 Isolate* isolate = GetIsolate(); | 8257 Isolate* isolate = GetIsolate(); |
| 8155 // Make sure that the top context does not change when doing | 8258 // Make sure that the top context does not change when doing |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8568 ASSERT(elements()->IsFixedDoubleArray()); | 8671 ASSERT(elements()->IsFixedDoubleArray()); |
| 8569 Object* obj; | 8672 Object* obj; |
| 8570 { MaybeObject* maybe_obj = NormalizeElements(); | 8673 { MaybeObject* maybe_obj = NormalizeElements(); |
| 8571 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 8674 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
| 8572 } | 8675 } |
| 8573 ASSERT(HasDictionaryElements()); | 8676 ASSERT(HasDictionaryElements()); |
| 8574 return SetElement(index, value, strict_mode, check_prototype); | 8677 return SetElement(index, value, strict_mode, check_prototype); |
| 8575 } | 8678 } |
| 8576 | 8679 |
| 8577 | 8680 |
| 8681 MaybeObject* JSReceiver::SetElement(uint32_t index, | |
| 8682 Object* value, | |
| 8683 StrictModeFlag strict_mode, | |
| 8684 bool check_proto) { | |
| 8685 return IsJSProxy() | |
| 8686 ? JSProxy::cast(this)->SetElementWithHandler(index, value, strict_mode) | |
| 8687 : JSObject::cast(this)->SetElement(index, value, strict_mode, check_proto) | |
| 8688 ; | |
| 8689 } | |
| 8690 | |
| 8691 | |
| 8578 MaybeObject* JSObject::SetElement(uint32_t index, | 8692 MaybeObject* JSObject::SetElement(uint32_t index, |
| 8579 Object* value, | 8693 Object* value, |
| 8580 StrictModeFlag strict_mode, | 8694 StrictModeFlag strict_mode, |
| 8581 bool check_prototype) { | 8695 bool check_prototype) { |
| 8582 // Check access rights if needed. | 8696 // Check access rights if needed. |
| 8583 if (IsAccessCheckNeeded()) { | 8697 if (IsAccessCheckNeeded()) { |
| 8584 Heap* heap = GetHeap(); | 8698 Heap* heap = GetHeap(); |
| 8585 if (!heap->isolate()->MayIndexedAccess(this, index, v8::ACCESS_SET)) { | 8699 if (!heap->isolate()->MayIndexedAccess(this, index, v8::ACCESS_SET)) { |
| 8586 HandleScope scope(heap->isolate()); | 8700 HandleScope scope(heap->isolate()); |
| 8587 Handle<Object> value_handle(value); | 8701 Handle<Object> value_handle(value); |
| (...skipping 3038 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11626 if (break_point_objects()->IsUndefined()) return 0; | 11740 if (break_point_objects()->IsUndefined()) return 0; |
| 11627 // Single break point. | 11741 // Single break point. |
| 11628 if (!break_point_objects()->IsFixedArray()) return 1; | 11742 if (!break_point_objects()->IsFixedArray()) return 1; |
| 11629 // Multiple break points. | 11743 // Multiple break points. |
| 11630 return FixedArray::cast(break_point_objects())->length(); | 11744 return FixedArray::cast(break_point_objects())->length(); |
| 11631 } | 11745 } |
| 11632 #endif | 11746 #endif |
| 11633 | 11747 |
| 11634 | 11748 |
| 11635 } } // namespace v8::internal | 11749 } } // namespace v8::internal |
| OLD | NEW |