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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 241 |
242 MaybeObject* JSProxy::GetElementWithHandler(Object* receiver, | 242 MaybeObject* JSProxy::GetElementWithHandler(Object* receiver, |
243 uint32_t index) { | 243 uint32_t index) { |
244 String* name; | 244 String* name; |
245 MaybeObject* maybe = GetHeap()->Uint32ToString(index); | 245 MaybeObject* maybe = GetHeap()->Uint32ToString(index); |
246 if (!maybe->To<String>(&name)) return maybe; | 246 if (!maybe->To<String>(&name)) return maybe; |
247 return GetPropertyWithHandler(receiver, name); | 247 return GetPropertyWithHandler(receiver, name); |
248 } | 248 } |
249 | 249 |
250 | 250 |
251 MaybeObject* JSProxy::SetElementWithHandler(uint32_t index, | 251 MaybeObject* JSProxy::SetElementWithHandler(JSReceiver* receiver, |
| 252 uint32_t index, |
252 Object* value, | 253 Object* value, |
253 StrictModeFlag strict_mode) { | 254 StrictModeFlag strict_mode) { |
254 String* name; | 255 String* name; |
255 MaybeObject* maybe = GetHeap()->Uint32ToString(index); | 256 MaybeObject* maybe = GetHeap()->Uint32ToString(index); |
256 if (!maybe->To<String>(&name)) return maybe; | 257 if (!maybe->To<String>(&name)) return maybe; |
257 return SetPropertyWithHandler(name, value, NONE, strict_mode); | 258 return SetPropertyWithHandler(receiver, name, value, NONE, strict_mode); |
258 } | 259 } |
259 | 260 |
260 | 261 |
261 bool JSProxy::HasElementWithHandler(uint32_t index) { | 262 bool JSProxy::HasElementWithHandler(uint32_t index) { |
262 String* name; | 263 String* name; |
263 MaybeObject* maybe = GetHeap()->Uint32ToString(index); | 264 MaybeObject* maybe = GetHeap()->Uint32ToString(index); |
264 if (!maybe->To<String>(&name)) return maybe; | 265 if (!maybe->To<String>(&name)) return maybe; |
265 return HasPropertyWithHandler(name); | 266 return HasPropertyWithHandler(name); |
266 } | 267 } |
267 | 268 |
(...skipping 1810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2078 pt != heap->null_value(); | 2079 pt != heap->null_value(); |
2079 pt = pt->GetPrototype()) { | 2080 pt = pt->GetPrototype()) { |
2080 if (pt->IsJSProxy()) { | 2081 if (pt->IsJSProxy()) { |
2081 String* name; | 2082 String* name; |
2082 MaybeObject* maybe = GetHeap()->Uint32ToString(index); | 2083 MaybeObject* maybe = GetHeap()->Uint32ToString(index); |
2083 if (!maybe->To<String>(&name)) { | 2084 if (!maybe->To<String>(&name)) { |
2084 *found = true; // Force abort | 2085 *found = true; // Force abort |
2085 return maybe; | 2086 return maybe; |
2086 } | 2087 } |
2087 return JSProxy::cast(pt)->SetPropertyWithHandlerIfDefiningSetter( | 2088 return JSProxy::cast(pt)->SetPropertyWithHandlerIfDefiningSetter( |
2088 name, value, NONE, strict_mode, found); | 2089 this, name, value, NONE, strict_mode, found); |
2089 } | 2090 } |
2090 if (!JSObject::cast(pt)->HasDictionaryElements()) { | 2091 if (!JSObject::cast(pt)->HasDictionaryElements()) { |
2091 continue; | 2092 continue; |
2092 } | 2093 } |
2093 SeededNumberDictionary* dictionary = | 2094 SeededNumberDictionary* dictionary = |
2094 JSObject::cast(pt)->element_dictionary(); | 2095 JSObject::cast(pt)->element_dictionary(); |
2095 int entry = dictionary->FindEntry(index); | 2096 int entry = dictionary->FindEntry(index); |
2096 if (entry != SeededNumberDictionary::kNotFound) { | 2097 if (entry != SeededNumberDictionary::kNotFound) { |
2097 PropertyDetails details = dictionary->DetailsAt(entry); | 2098 PropertyDetails details = dictionary->DetailsAt(entry); |
2098 if (details.type() == CALLBACKS) { | 2099 if (details.type() == CALLBACKS) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2133 // getPropertyDescriptor trap. | 2134 // getPropertyDescriptor trap. |
2134 bool found = false; | 2135 bool found = false; |
2135 // SetPropertyWithHandlerIfDefiningSetter can cause GC, | 2136 // SetPropertyWithHandlerIfDefiningSetter can cause GC, |
2136 // make sure to use the handlified references after calling | 2137 // make sure to use the handlified references after calling |
2137 // the function. | 2138 // the function. |
2138 Handle<JSObject> self(this); | 2139 Handle<JSObject> self(this); |
2139 Handle<String> hname(name); | 2140 Handle<String> hname(name); |
2140 Handle<Object> hvalue(value); | 2141 Handle<Object> hvalue(value); |
2141 MaybeObject* result = | 2142 MaybeObject* result = |
2142 accessor_result.proxy()->SetPropertyWithHandlerIfDefiningSetter( | 2143 accessor_result.proxy()->SetPropertyWithHandlerIfDefiningSetter( |
2143 name, value, attributes, strict_mode, &found); | 2144 this, name, value, attributes, strict_mode, &found); |
2144 if (found) return result; | 2145 if (found) return result; |
2145 // The proxy does not define the property as an accessor. | 2146 // The proxy does not define the property as an accessor. |
2146 // Consequently, it has no effect on setting the receiver. | 2147 // Consequently, it has no effect on setting the receiver. |
2147 return self->AddProperty(*hname, *hvalue, attributes, strict_mode); | 2148 return self->AddProperty(*hname, *hvalue, attributes, strict_mode); |
2148 } | 2149 } |
2149 } | 2150 } |
2150 *found = false; | 2151 *found = false; |
2151 return heap->the_hole_value(); | 2152 return heap->the_hole_value(); |
2152 } | 2153 } |
2153 | 2154 |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2617 } | 2618 } |
2618 | 2619 |
2619 | 2620 |
2620 MaybeObject* JSReceiver::SetProperty(LookupResult* result, | 2621 MaybeObject* JSReceiver::SetProperty(LookupResult* result, |
2621 String* key, | 2622 String* key, |
2622 Object* value, | 2623 Object* value, |
2623 PropertyAttributes attributes, | 2624 PropertyAttributes attributes, |
2624 StrictModeFlag strict_mode) { | 2625 StrictModeFlag strict_mode) { |
2625 if (result->IsFound() && result->type() == HANDLER) { | 2626 if (result->IsFound() && result->type() == HANDLER) { |
2626 return result->proxy()->SetPropertyWithHandler( | 2627 return result->proxy()->SetPropertyWithHandler( |
2627 key, value, attributes, strict_mode); | 2628 this, key, value, attributes, strict_mode); |
2628 } else { | 2629 } else { |
2629 return JSObject::cast(this)->SetPropertyForResult( | 2630 return JSObject::cast(this)->SetPropertyForResult( |
2630 result, key, value, attributes, strict_mode); | 2631 result, key, value, attributes, strict_mode); |
2631 } | 2632 } |
2632 } | 2633 } |
2633 | 2634 |
2634 | 2635 |
2635 bool JSProxy::HasPropertyWithHandler(String* name_raw) { | 2636 bool JSProxy::HasPropertyWithHandler(String* name_raw) { |
2636 Isolate* isolate = GetIsolate(); | 2637 Isolate* isolate = GetIsolate(); |
2637 HandleScope scope(isolate); | 2638 HandleScope scope(isolate); |
2638 Handle<Object> receiver(this); | 2639 Handle<Object> receiver(this); |
2639 Handle<Object> name(name_raw); | 2640 Handle<Object> name(name_raw); |
2640 | 2641 |
2641 Handle<Object> args[] = { name }; | 2642 Handle<Object> args[] = { name }; |
2642 Handle<Object> result = CallTrap( | 2643 Handle<Object> result = CallTrap( |
2643 "has", isolate->derived_has_trap(), ARRAY_SIZE(args), args); | 2644 "has", isolate->derived_has_trap(), ARRAY_SIZE(args), args); |
2644 if (isolate->has_pending_exception()) return Failure::Exception(); | 2645 if (isolate->has_pending_exception()) return Failure::Exception(); |
2645 | 2646 |
2646 return result->ToBoolean()->IsTrue(); | 2647 return result->ToBoolean()->IsTrue(); |
2647 } | 2648 } |
2648 | 2649 |
2649 | 2650 |
2650 MUST_USE_RESULT MaybeObject* JSProxy::SetPropertyWithHandler( | 2651 MUST_USE_RESULT MaybeObject* JSProxy::SetPropertyWithHandler( |
| 2652 JSReceiver* receiver_raw, |
2651 String* name_raw, | 2653 String* name_raw, |
2652 Object* value_raw, | 2654 Object* value_raw, |
2653 PropertyAttributes attributes, | 2655 PropertyAttributes attributes, |
2654 StrictModeFlag strict_mode) { | 2656 StrictModeFlag strict_mode) { |
2655 Isolate* isolate = GetIsolate(); | 2657 Isolate* isolate = GetIsolate(); |
2656 HandleScope scope(isolate); | 2658 HandleScope scope(isolate); |
2657 Handle<Object> receiver(this); | 2659 Handle<JSReceiver> receiver(receiver_raw); |
2658 Handle<Object> name(name_raw); | 2660 Handle<Object> name(name_raw); |
2659 Handle<Object> value(value_raw); | 2661 Handle<Object> value(value_raw); |
2660 | 2662 |
2661 Handle<Object> args[] = { receiver, name, value }; | 2663 Handle<Object> args[] = { receiver, name, value }; |
2662 CallTrap("set", isolate->derived_set_trap(), ARRAY_SIZE(args), args); | 2664 CallTrap("set", isolate->derived_set_trap(), ARRAY_SIZE(args), args); |
2663 if (isolate->has_pending_exception()) return Failure::Exception(); | 2665 if (isolate->has_pending_exception()) return Failure::Exception(); |
2664 | 2666 |
2665 return *value; | 2667 return *value; |
2666 } | 2668 } |
2667 | 2669 |
2668 | 2670 |
2669 MUST_USE_RESULT MaybeObject* JSProxy::SetPropertyWithHandlerIfDefiningSetter( | 2671 MUST_USE_RESULT MaybeObject* JSProxy::SetPropertyWithHandlerIfDefiningSetter( |
| 2672 JSReceiver* receiver_raw, |
2670 String* name_raw, | 2673 String* name_raw, |
2671 Object* value_raw, | 2674 Object* value_raw, |
2672 PropertyAttributes attributes, | 2675 PropertyAttributes attributes, |
2673 StrictModeFlag strict_mode, | 2676 StrictModeFlag strict_mode, |
2674 bool* found) { | 2677 bool* found) { |
2675 *found = true; // except where defined otherwise... | 2678 *found = true; // except where defined otherwise... |
2676 Isolate* isolate = GetHeap()->isolate(); | 2679 Isolate* isolate = GetHeap()->isolate(); |
| 2680 Handle<JSReceiver> receiver(receiver_raw); |
2677 Handle<JSProxy> proxy(this); | 2681 Handle<JSProxy> proxy(this); |
2678 Handle<Object> handler(this->handler()); // Trap might morph proxy. | 2682 Handle<Object> handler(this->handler()); // Trap might morph proxy. |
2679 Handle<String> name(name_raw); | 2683 Handle<String> name(name_raw); |
2680 Handle<Object> value(value_raw); | 2684 Handle<Object> value(value_raw); |
2681 Handle<Object> args[] = { name }; | 2685 Handle<Object> args[] = { name }; |
2682 Handle<Object> result = proxy->CallTrap( | 2686 Handle<Object> result = proxy->CallTrap( |
2683 "getPropertyDescriptor", Handle<Object>(), ARRAY_SIZE(args), args); | 2687 "getPropertyDescriptor", Handle<Object>(), ARRAY_SIZE(args), args); |
2684 if (isolate->has_pending_exception()) return Failure::Exception(); | 2688 if (isolate->has_pending_exception()) return Failure::Exception(); |
2685 | 2689 |
2686 if (!result->IsUndefined()) { | 2690 if (!result->IsUndefined()) { |
(...skipping 21 matching lines...) Expand all Loading... |
2708 } | 2712 } |
2709 ASSERT(configurable->IsTrue()); | 2713 ASSERT(configurable->IsTrue()); |
2710 | 2714 |
2711 // Check for AccessorDescriptor. | 2715 // Check for AccessorDescriptor. |
2712 Handle<String> set_name = isolate->factory()->LookupAsciiSymbol("set_"); | 2716 Handle<String> set_name = isolate->factory()->LookupAsciiSymbol("set_"); |
2713 Handle<Object> setter(v8::internal::GetProperty(desc, set_name)); | 2717 Handle<Object> setter(v8::internal::GetProperty(desc, set_name)); |
2714 ASSERT(!isolate->has_pending_exception()); | 2718 ASSERT(!isolate->has_pending_exception()); |
2715 if (!setter->IsUndefined()) { | 2719 if (!setter->IsUndefined()) { |
2716 // We have a setter -- invoke it. | 2720 // We have a setter -- invoke it. |
2717 // TODO(rossberg): nicer would be to cast to some JSCallable here... | 2721 // TODO(rossberg): nicer would be to cast to some JSCallable here... |
2718 return proxy->SetPropertyWithDefinedSetter( | 2722 return receiver->SetPropertyWithDefinedSetter( |
2719 JSReceiver::cast(*setter), *value); | 2723 JSReceiver::cast(*setter), *value); |
2720 } else { | 2724 } else { |
2721 Handle<String> get_name = isolate->factory()->LookupAsciiSymbol("get_"); | 2725 Handle<String> get_name = isolate->factory()->LookupAsciiSymbol("get_"); |
2722 Handle<Object> getter(v8::internal::GetProperty(desc, get_name)); | 2726 Handle<Object> getter(v8::internal::GetProperty(desc, get_name)); |
2723 ASSERT(!isolate->has_pending_exception()); | 2727 ASSERT(!isolate->has_pending_exception()); |
2724 if (!getter->IsUndefined()) { | 2728 if (!getter->IsUndefined()) { |
2725 // We have a getter but no setter -- the property may not be | 2729 // We have a getter but no setter -- the property may not be |
2726 // written. In strict mode, throw an error. | 2730 // written. In strict mode, throw an error. |
2727 if (strict_mode == kNonStrictMode) return *value; | 2731 if (strict_mode == kNonStrictMode) return *value; |
2728 Handle<Object> args[] = { name, proxy }; | 2732 Handle<Object> args[] = { name, proxy }; |
(...skipping 6915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9644 } | 9648 } |
9645 | 9649 |
9646 | 9650 |
9647 MaybeObject* JSReceiver::SetElement(uint32_t index, | 9651 MaybeObject* JSReceiver::SetElement(uint32_t index, |
9648 Object* value, | 9652 Object* value, |
9649 PropertyAttributes attributes, | 9653 PropertyAttributes attributes, |
9650 StrictModeFlag strict_mode, | 9654 StrictModeFlag strict_mode, |
9651 bool check_proto) { | 9655 bool check_proto) { |
9652 if (IsJSProxy()) { | 9656 if (IsJSProxy()) { |
9653 return JSProxy::cast(this)->SetElementWithHandler( | 9657 return JSProxy::cast(this)->SetElementWithHandler( |
9654 index, value, strict_mode); | 9658 this, index, value, strict_mode); |
9655 } else { | 9659 } else { |
9656 return JSObject::cast(this)->SetElement( | 9660 return JSObject::cast(this)->SetElement( |
9657 index, value, attributes, strict_mode, check_proto); | 9661 index, value, attributes, strict_mode, check_proto); |
9658 } | 9662 } |
9659 } | 9663 } |
9660 | 9664 |
9661 | 9665 |
9662 Handle<Object> JSObject::SetOwnElement(Handle<JSObject> object, | 9666 Handle<Object> JSObject::SetOwnElement(Handle<JSObject> object, |
9663 uint32_t index, | 9667 uint32_t index, |
9664 Handle<Object> value, | 9668 Handle<Object> value, |
(...skipping 3530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13195 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); | 13199 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); |
13196 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); | 13200 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); |
13197 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); | 13201 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); |
13198 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); | 13202 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); |
13199 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); | 13203 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); |
13200 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); | 13204 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); |
13201 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); | 13205 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); |
13202 } | 13206 } |
13203 | 13207 |
13204 } } // namespace v8::internal | 13208 } } // namespace v8::internal |
OLD | NEW |