OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 13 matching lines...) Expand all Loading... |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #include "v8.h" | 28 #include "v8.h" |
29 | 29 |
30 #include "accessors.h" | 30 #include "accessors.h" |
31 #include "execution.h" | 31 #include "execution.h" |
32 #include "factory.h" | 32 #include "factory.h" |
33 #include "scopeinfo.h" | 33 #include "scopeinfo.h" |
34 #include "top.h" | |
35 | 34 |
36 namespace v8 { | 35 namespace v8 { |
37 namespace internal { | 36 namespace internal { |
38 | 37 |
39 | 38 |
40 template <class C> | 39 template <class C> |
41 static C* FindInPrototypeChain(Object* obj, bool* found_it) { | 40 static C* FindInPrototypeChain(Object* obj, bool* found_it) { |
42 ASSERT(!*found_it); | 41 ASSERT(!*found_it); |
43 while (!Is<C>(obj)) { | 42 while (!Is<C>(obj)) { |
44 if (obj == HEAP->null_value()) return NULL; | 43 if (obj == HEAP->null_value()) return NULL; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 JSArray* holder = FindInPrototypeChain<JSArray>(object, &found_it); | 79 JSArray* holder = FindInPrototypeChain<JSArray>(object, &found_it); |
81 if (!found_it) return Smi::FromInt(0); | 80 if (!found_it) return Smi::FromInt(0); |
82 return holder->length(); | 81 return holder->length(); |
83 } | 82 } |
84 | 83 |
85 | 84 |
86 // The helper function will 'flatten' Number objects. | 85 // The helper function will 'flatten' Number objects. |
87 Object* Accessors::FlattenNumber(Object* value) { | 86 Object* Accessors::FlattenNumber(Object* value) { |
88 if (value->IsNumber() || !value->IsJSValue()) return value; | 87 if (value->IsNumber() || !value->IsJSValue()) return value; |
89 JSValue* wrapper = JSValue::cast(value); | 88 JSValue* wrapper = JSValue::cast(value); |
90 ASSERT( | 89 ASSERT(Isolate::Current()->context()->global_context()->number_function()-> |
91 Top::context()->global_context()->number_function()->has_initial_map()); | 90 has_initial_map()); |
92 Map* number_map = | 91 Map* number_map = Isolate::Current()->context()->global_context()-> |
93 Top::context()->global_context()->number_function()->initial_map(); | 92 number_function()->initial_map(); |
94 if (wrapper->map() == number_map) return wrapper->value(); | 93 if (wrapper->map() == number_map) return wrapper->value(); |
95 return value; | 94 return value; |
96 } | 95 } |
97 | 96 |
98 | 97 |
99 Object* Accessors::ArraySetLength(JSObject* object, Object* value, void*) { | 98 Object* Accessors::ArraySetLength(JSObject* object, Object* value, void*) { |
100 value = FlattenNumber(value); | 99 value = FlattenNumber(value); |
101 | 100 |
102 // Need to call methods that may trigger GC. | 101 // Need to call methods that may trigger GC. |
103 HandleScope scope; | 102 HandleScope scope; |
(...skipping 16 matching lines...) Expand all Loading... |
120 if (object->IsJSArray()) { | 119 if (object->IsJSArray()) { |
121 return JSArray::cast(object)->SetElementsLength(*uint32_v); | 120 return JSArray::cast(object)->SetElementsLength(*uint32_v); |
122 } else { | 121 } else { |
123 // This means one of the object's prototypes is a JSArray and | 122 // This means one of the object's prototypes is a JSArray and |
124 // the object does not have a 'length' property. | 123 // the object does not have a 'length' property. |
125 // Calling SetProperty causes an infinite loop. | 124 // Calling SetProperty causes an infinite loop. |
126 return object->IgnoreAttributesAndSetLocalProperty(HEAP->length_symbol(), | 125 return object->IgnoreAttributesAndSetLocalProperty(HEAP->length_symbol(), |
127 value, NONE); | 126 value, NONE); |
128 } | 127 } |
129 } | 128 } |
130 return Top::Throw(*Factory::NewRangeError("invalid_array_length", | 129 return Isolate::Current()->Throw( |
131 HandleVector<Object>(NULL, 0))); | 130 *Factory::NewRangeError("invalid_array_length", |
| 131 HandleVector<Object>(NULL, 0))); |
132 } | 132 } |
133 | 133 |
134 | 134 |
135 const AccessorDescriptor Accessors::ArrayLength = { | 135 const AccessorDescriptor Accessors::ArrayLength = { |
136 ArrayGetLength, | 136 ArrayGetLength, |
137 ArraySetLength, | 137 ArraySetLength, |
138 0 | 138 0 |
139 }; | 139 }; |
140 | 140 |
141 | 141 |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 } | 652 } |
653 | 653 |
654 | 654 |
655 const AccessorDescriptor Accessors::ObjectPrototype = { | 655 const AccessorDescriptor Accessors::ObjectPrototype = { |
656 ObjectGetPrototype, | 656 ObjectGetPrototype, |
657 ObjectSetPrototype, | 657 ObjectSetPrototype, |
658 0 | 658 0 |
659 }; | 659 }; |
660 | 660 |
661 } } // namespace v8::internal | 661 } } // namespace v8::internal |
OLD | NEW |