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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 MaybeObject* Accessors::ArrayGetLength(Isolate* isolate, | 141 MaybeObject* Accessors::ArrayGetLength(Isolate* isolate, |
142 Object* object, | 142 Object* object, |
143 void*) { | 143 void*) { |
144 // Traverse the prototype chain until we reach an array. | 144 // Traverse the prototype chain until we reach an array. |
145 JSArray* holder = FindInstanceOf<JSArray>(isolate, object); | 145 JSArray* holder = FindInstanceOf<JSArray>(isolate, object); |
146 return holder == NULL ? Smi::FromInt(0) : holder->length(); | 146 return holder == NULL ? Smi::FromInt(0) : holder->length(); |
147 } | 147 } |
148 | 148 |
149 | 149 |
150 // The helper function will 'flatten' Number objects. | 150 // The helper function will 'flatten' Number objects. |
151 Object* Accessors::FlattenNumber(Isolate* isolate, Object* value) { | 151 Handle<Object> Accessors::FlattenNumber(Isolate* isolate, |
| 152 Handle<Object> value) { |
152 if (value->IsNumber() || !value->IsJSValue()) return value; | 153 if (value->IsNumber() || !value->IsJSValue()) return value; |
153 JSValue* wrapper = JSValue::cast(value); | 154 Handle<JSValue> wrapper = Handle<JSValue>::cast(value); |
154 ASSERT(wrapper->GetIsolate()->context()->native_context()->number_function()-> | 155 ASSERT(wrapper->GetIsolate()->context()->native_context()->number_function()-> |
155 has_initial_map()); | 156 has_initial_map()); |
156 Map* number_map = isolate->context()->native_context()-> | 157 if (wrapper->map() == |
157 number_function()->initial_map(); | 158 isolate->context()->native_context()->number_function()->initial_map()) { |
158 if (wrapper->map() == number_map) return wrapper->value(); | 159 return handle(wrapper->value(), isolate); |
| 160 } |
| 161 |
159 return value; | 162 return value; |
160 } | 163 } |
161 | 164 |
162 | 165 |
163 MaybeObject* Accessors::ArraySetLength(Isolate* isolate, | 166 MaybeObject* Accessors::ArraySetLength(Isolate* isolate, |
164 JSObject* object, | 167 JSObject* object_raw, |
165 Object* value, | 168 Object* value_raw, |
166 void*) { | 169 void*) { |
| 170 HandleScope scope(isolate); |
| 171 Handle<JSObject> object(object_raw, isolate); |
| 172 Handle<Object> value(value_raw, isolate); |
| 173 |
167 // This means one of the object's prototypes is a JSArray and the | 174 // This means one of the object's prototypes is a JSArray and the |
168 // object does not have a 'length' property. Calling SetProperty | 175 // object does not have a 'length' property. Calling SetProperty |
169 // causes an infinite loop. | 176 // causes an infinite loop. |
170 if (!object->IsJSArray()) { | 177 if (!object->IsJSArray()) { |
171 return object->SetLocalPropertyIgnoreAttributesTrampoline( | 178 Handle<Object> result = JSObject::SetLocalPropertyIgnoreAttributes(object, |
172 isolate->heap()->length_string(), value, NONE); | 179 isolate->factory()->length_string(), value, NONE); |
| 180 RETURN_IF_EMPTY_HANDLE(isolate, result); |
| 181 return *result; |
173 } | 182 } |
174 | 183 |
175 value = FlattenNumber(isolate, value); | 184 value = FlattenNumber(isolate, value); |
176 | 185 |
177 // Need to call methods that may trigger GC. | 186 Handle<JSArray> array_handle = Handle<JSArray>::cast(object); |
178 HandleScope scope(isolate); | |
179 | |
180 // Protect raw pointers. | |
181 Handle<JSArray> array_handle(JSArray::cast(object), isolate); | |
182 Handle<Object> value_handle(value, isolate); | |
183 | 187 |
184 bool has_exception; | 188 bool has_exception; |
185 Handle<Object> uint32_v = | 189 Handle<Object> uint32_v = |
186 Execution::ToUint32(isolate, value_handle, &has_exception); | 190 Execution::ToUint32(isolate, value, &has_exception); |
187 if (has_exception) return Failure::Exception(); | 191 if (has_exception) return Failure::Exception(); |
188 Handle<Object> number_v = | 192 Handle<Object> number_v = |
189 Execution::ToNumber(isolate, value_handle, &has_exception); | 193 Execution::ToNumber(isolate, value, &has_exception); |
190 if (has_exception) return Failure::Exception(); | 194 if (has_exception) return Failure::Exception(); |
191 | 195 |
192 if (uint32_v->Number() == number_v->Number()) { | 196 if (uint32_v->Number() == number_v->Number()) { |
193 return array_handle->SetElementsLength(*uint32_v); | 197 return array_handle->SetElementsLength(*uint32_v); |
194 } | 198 } |
195 return isolate->Throw( | 199 return isolate->Throw( |
196 *isolate->factory()->NewRangeError("invalid_array_length", | 200 *isolate->factory()->NewRangeError("invalid_array_length", |
197 HandleVector<Object>(NULL, 0))); | 201 HandleVector<Object>(NULL, 0))); |
198 } | 202 } |
199 | 203 |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 Handle<JSFunction> function(function_raw); | 575 Handle<JSFunction> function(function_raw); |
572 Handle<Object> proto = isolate->factory()->NewFunctionPrototype(function); | 576 Handle<Object> proto = isolate->factory()->NewFunctionPrototype(function); |
573 JSFunction::SetPrototype(function, proto); | 577 JSFunction::SetPrototype(function, proto); |
574 function_raw = *function; | 578 function_raw = *function; |
575 } | 579 } |
576 return function_raw->prototype(); | 580 return function_raw->prototype(); |
577 } | 581 } |
578 | 582 |
579 | 583 |
580 MaybeObject* Accessors::FunctionSetPrototype(Isolate* isolate, | 584 MaybeObject* Accessors::FunctionSetPrototype(Isolate* isolate, |
581 JSObject* object, | 585 JSObject* object_raw, |
582 Object* value_raw, | 586 Object* value_raw, |
583 void*) { | 587 void*) { |
584 Heap* heap = isolate->heap(); | 588 JSFunction* function_raw = FindInstanceOf<JSFunction>(isolate, object_raw); |
585 JSFunction* function_raw = FindInstanceOf<JSFunction>(isolate, object); | 589 if (function_raw == NULL) return isolate->heap()->undefined_value(); |
586 if (function_raw == NULL) return heap->undefined_value(); | |
587 if (!function_raw->should_have_prototype()) { | |
588 // Since we hit this accessor, object will have no prototype property. | |
589 return object->SetLocalPropertyIgnoreAttributesTrampoline( | |
590 heap->prototype_string(), value_raw, NONE); | |
591 } | |
592 | 590 |
593 HandleScope scope(isolate); | 591 HandleScope scope(isolate); |
594 Handle<JSFunction> function(function_raw, isolate); | 592 Handle<JSFunction> function(function_raw, isolate); |
| 593 Handle<JSObject> object(object_raw, isolate); |
595 Handle<Object> value(value_raw, isolate); | 594 Handle<Object> value(value_raw, isolate); |
| 595 if (!function->should_have_prototype()) { |
| 596 // Since we hit this accessor, object will have no prototype property. |
| 597 Handle<Object> result = JSObject::SetLocalPropertyIgnoreAttributes(object, |
| 598 isolate->factory()->prototype_string(), value, NONE); |
| 599 RETURN_IF_EMPTY_HANDLE(isolate, result); |
| 600 return *result; |
| 601 } |
596 | 602 |
597 Handle<Object> old_value; | 603 Handle<Object> old_value; |
598 bool is_observed = | 604 bool is_observed = |
599 FLAG_harmony_observation && | 605 FLAG_harmony_observation && |
600 *function == object && | 606 *function == *object && |
601 function->map()->is_observed(); | 607 function->map()->is_observed(); |
602 if (is_observed) { | 608 if (is_observed) { |
603 if (function->has_prototype()) | 609 if (function->has_prototype()) |
604 old_value = handle(function->prototype(), isolate); | 610 old_value = handle(function->prototype(), isolate); |
605 else | 611 else |
606 old_value = isolate->factory()->NewFunctionPrototype(function); | 612 old_value = isolate->factory()->NewFunctionPrototype(function); |
607 } | 613 } |
608 | 614 |
609 JSFunction::SetPrototype(function, value); | 615 JSFunction::SetPrototype(function, value); |
610 ASSERT(function->prototype() == *value); | 616 ASSERT(function->prototype() == *value); |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 info->set_data(Smi::FromInt(index)); | 968 info->set_data(Smi::FromInt(index)); |
963 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport); | 969 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport); |
964 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport); | 970 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport); |
965 info->set_getter(*getter); | 971 info->set_getter(*getter); |
966 if (!(attributes & ReadOnly)) info->set_setter(*setter); | 972 if (!(attributes & ReadOnly)) info->set_setter(*setter); |
967 return info; | 973 return info; |
968 } | 974 } |
969 | 975 |
970 | 976 |
971 } } // namespace v8::internal | 977 } } // namespace v8::internal |
OLD | NEW |