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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 ASSERT(Isolate::Current()->context()->global_context()->number_function()-> | 93 ASSERT(Isolate::Current()->context()->global_context()->number_function()-> |
94 has_initial_map()); | 94 has_initial_map()); |
95 Map* number_map = Isolate::Current()->context()->global_context()-> | 95 Map* number_map = Isolate::Current()->context()->global_context()-> |
96 number_function()->initial_map(); | 96 number_function()->initial_map(); |
97 if (wrapper->map() == number_map) return wrapper->value(); | 97 if (wrapper->map() == number_map) return wrapper->value(); |
98 return value; | 98 return value; |
99 } | 99 } |
100 | 100 |
101 | 101 |
102 MaybeObject* Accessors::ArraySetLength(JSObject* object, Object* value, void*) { | 102 MaybeObject* Accessors::ArraySetLength(JSObject* object, Object* value, void*) { |
| 103 Isolate* isolate = object->GetIsolate(); |
103 value = FlattenNumber(value); | 104 value = FlattenNumber(value); |
104 | 105 |
105 // Need to call methods that may trigger GC. | 106 // Need to call methods that may trigger GC. |
106 HandleScope scope; | 107 HandleScope scope(isolate); |
107 | 108 |
108 // Protect raw pointers. | 109 // Protect raw pointers. |
109 Handle<JSObject> object_handle(object); | 110 Handle<JSObject> object_handle(object, isolate); |
110 Handle<Object> value_handle(value); | 111 Handle<Object> value_handle(value, isolate); |
111 | 112 |
112 bool has_exception; | 113 bool has_exception; |
113 Handle<Object> uint32_v = Execution::ToUint32(value_handle, &has_exception); | 114 Handle<Object> uint32_v = Execution::ToUint32(value_handle, &has_exception); |
114 if (has_exception) return Failure::Exception(); | 115 if (has_exception) return Failure::Exception(); |
115 Handle<Object> number_v = Execution::ToNumber(value_handle, &has_exception); | 116 Handle<Object> number_v = Execution::ToNumber(value_handle, &has_exception); |
116 if (has_exception) return Failure::Exception(); | 117 if (has_exception) return Failure::Exception(); |
117 | 118 |
118 // Restore raw pointers, | 119 // Restore raw pointers, |
119 object = *object_handle; | 120 object = *object_handle; |
120 value = *value_handle; | 121 value = *value_handle; |
121 | 122 |
122 if (uint32_v->Number() == number_v->Number()) { | 123 if (uint32_v->Number() == number_v->Number()) { |
123 if (object->IsJSArray()) { | 124 if (object->IsJSArray()) { |
124 return JSArray::cast(object)->SetElementsLength(*uint32_v); | 125 return JSArray::cast(object)->SetElementsLength(*uint32_v); |
125 } else { | 126 } else { |
126 // This means one of the object's prototypes is a JSArray and | 127 // This means one of the object's prototypes is a JSArray and |
127 // the object does not have a 'length' property. | 128 // the object does not have a 'length' property. |
128 // Calling SetProperty causes an infinite loop. | 129 // Calling SetProperty causes an infinite loop. |
129 return object->SetLocalPropertyIgnoreAttributes(HEAP->length_symbol(), | 130 return object->SetLocalPropertyIgnoreAttributes( |
130 value, NONE); | 131 isolate->heap()->length_symbol(), value, NONE); |
131 } | 132 } |
132 } | 133 } |
133 return Isolate::Current()->Throw( | 134 return isolate->Throw( |
134 *FACTORY->NewRangeError("invalid_array_length", | 135 *isolate->factory()->NewRangeError("invalid_array_length", |
135 HandleVector<Object>(NULL, 0))); | 136 HandleVector<Object>(NULL, 0))); |
136 } | 137 } |
137 | 138 |
138 | 139 |
139 const AccessorDescriptor Accessors::ArrayLength = { | 140 const AccessorDescriptor Accessors::ArrayLength = { |
140 ArrayGetLength, | 141 ArrayGetLength, |
141 ArraySetLength, | 142 ArraySetLength, |
142 0 | 143 0 |
143 }; | 144 }; |
144 | 145 |
145 | 146 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 0 | 309 0 |
309 }; | 310 }; |
310 | 311 |
311 | 312 |
312 // | 313 // |
313 // Accessors::ScriptGetLineEnds | 314 // Accessors::ScriptGetLineEnds |
314 // | 315 // |
315 | 316 |
316 | 317 |
317 MaybeObject* Accessors::ScriptGetLineEnds(Object* object, void*) { | 318 MaybeObject* Accessors::ScriptGetLineEnds(Object* object, void*) { |
318 HandleScope scope; | 319 JSValue* wrapper = JSValue::cast(object); |
319 Handle<Script> script(Script::cast(JSValue::cast(object)->value())); | 320 Isolate* isolate = wrapper->GetIsolate(); |
| 321 HandleScope scope(isolate); |
| 322 Handle<Script> script(Script::cast(wrapper->value()), isolate); |
320 InitScriptLineEnds(script); | 323 InitScriptLineEnds(script); |
321 ASSERT(script->line_ends()->IsFixedArray()); | 324 ASSERT(script->line_ends()->IsFixedArray()); |
322 Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends())); | 325 Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends())); |
323 // We do not want anyone to modify this array from JS. | 326 // We do not want anyone to modify this array from JS. |
324 ASSERT(*line_ends == HEAP->empty_fixed_array() || | 327 ASSERT(*line_ends == isolate->heap()->empty_fixed_array() || |
325 line_ends->map() == HEAP->fixed_cow_array_map()); | 328 line_ends->map() == isolate->heap()->fixed_cow_array_map()); |
326 Handle<JSArray> js_array = FACTORY->NewJSArrayWithElements(line_ends); | 329 Handle<JSArray> js_array = |
| 330 isolate->factory()->NewJSArrayWithElements(line_ends); |
327 return *js_array; | 331 return *js_array; |
328 } | 332 } |
329 | 333 |
330 | 334 |
331 const AccessorDescriptor Accessors::ScriptLineEnds = { | 335 const AccessorDescriptor Accessors::ScriptLineEnds = { |
332 ScriptGetLineEnds, | 336 ScriptGetLineEnds, |
333 IllegalSetter, | 337 IllegalSetter, |
334 0 | 338 0 |
335 }; | 339 }; |
336 | 340 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 0 | 441 0 |
438 }; | 442 }; |
439 | 443 |
440 | 444 |
441 // | 445 // |
442 // Accessors::FunctionPrototype | 446 // Accessors::FunctionPrototype |
443 // | 447 // |
444 | 448 |
445 | 449 |
446 MaybeObject* Accessors::FunctionGetPrototype(Object* object, void*) { | 450 MaybeObject* Accessors::FunctionGetPrototype(Object* object, void*) { |
| 451 Heap* heap = Isolate::Current()->heap(); |
447 bool found_it = false; | 452 bool found_it = false; |
448 JSFunction* function = FindInPrototypeChain<JSFunction>(object, &found_it); | 453 JSFunction* function = FindInPrototypeChain<JSFunction>(object, &found_it); |
449 if (!found_it) return HEAP->undefined_value(); | 454 if (!found_it) return heap->undefined_value(); |
450 while (!function->should_have_prototype()) { | 455 while (!function->should_have_prototype()) { |
451 found_it = false; | 456 found_it = false; |
452 function = FindInPrototypeChain<JSFunction>(object->GetPrototype(), | 457 function = FindInPrototypeChain<JSFunction>(object->GetPrototype(), |
453 &found_it); | 458 &found_it); |
454 // There has to be one because we hit the getter. | 459 // There has to be one because we hit the getter. |
455 ASSERT(found_it); | 460 ASSERT(found_it); |
456 } | 461 } |
457 | 462 |
458 if (!function->has_prototype()) { | 463 if (!function->has_prototype()) { |
459 Object* prototype; | 464 Object* prototype; |
460 { MaybeObject* maybe_prototype = HEAP->AllocateFunctionPrototype(function); | 465 { MaybeObject* maybe_prototype = heap->AllocateFunctionPrototype(function); |
461 if (!maybe_prototype->ToObject(&prototype)) return maybe_prototype; | 466 if (!maybe_prototype->ToObject(&prototype)) return maybe_prototype; |
462 } | 467 } |
463 Object* result; | 468 Object* result; |
464 { MaybeObject* maybe_result = function->SetPrototype(prototype); | 469 { MaybeObject* maybe_result = function->SetPrototype(prototype); |
465 if (!maybe_result->ToObject(&result)) return maybe_result; | 470 if (!maybe_result->ToObject(&result)) return maybe_result; |
466 } | 471 } |
467 } | 472 } |
468 return function->prototype(); | 473 return function->prototype(); |
469 } | 474 } |
470 | 475 |
471 | 476 |
472 MaybeObject* Accessors::FunctionSetPrototype(JSObject* object, | 477 MaybeObject* Accessors::FunctionSetPrototype(JSObject* object, |
473 Object* value, | 478 Object* value, |
474 void*) { | 479 void*) { |
| 480 Heap* heap = object->GetHeap(); |
475 bool found_it = false; | 481 bool found_it = false; |
476 JSFunction* function = FindInPrototypeChain<JSFunction>(object, &found_it); | 482 JSFunction* function = FindInPrototypeChain<JSFunction>(object, &found_it); |
477 if (!found_it) return HEAP->undefined_value(); | 483 if (!found_it) return heap->undefined_value(); |
478 if (!function->should_have_prototype()) { | 484 if (!function->should_have_prototype()) { |
479 // Since we hit this accessor, object will have no prototype property. | 485 // Since we hit this accessor, object will have no prototype property. |
480 return object->SetLocalPropertyIgnoreAttributes(HEAP->prototype_symbol(), | 486 return object->SetLocalPropertyIgnoreAttributes(heap->prototype_symbol(), |
481 value, | 487 value, |
482 NONE); | 488 NONE); |
483 } | 489 } |
484 | 490 |
485 if (function->has_initial_map()) { | 491 if (function->has_initial_map()) { |
486 // If the function has allocated the initial map | 492 // If the function has allocated the initial map |
487 // replace it with a copy containing the new prototype. | 493 // replace it with a copy containing the new prototype. |
488 Object* new_map; | 494 Object* new_map; |
489 { MaybeObject* maybe_new_map = | 495 { MaybeObject* maybe_new_map = |
490 function->initial_map()->CopyDropTransitions(); | 496 function->initial_map()->CopyDropTransitions(); |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 } | 921 } |
916 | 922 |
917 | 923 |
918 const AccessorDescriptor Accessors::ObjectPrototype = { | 924 const AccessorDescriptor Accessors::ObjectPrototype = { |
919 ObjectGetPrototype, | 925 ObjectGetPrototype, |
920 ObjectSetPrototype, | 926 ObjectSetPrototype, |
921 0 | 927 0 |
922 }; | 928 }; |
923 | 929 |
924 } } // namespace v8::internal | 930 } } // namespace v8::internal |
OLD | NEW |