OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
9 #include "src/conversions-inl.h" | 9 #include "src/conversions-inl.h" |
10 #include "src/elements.h" | 10 #include "src/elements.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 HandleScope scope(isolate); | 21 HandleScope scope(isolate); |
22 DCHECK(args.length() == 1); | 22 DCHECK(args.length() == 1); |
23 CONVERT_ARG_HANDLE_CHECKED(JSArray, prototype, 0); | 23 CONVERT_ARG_HANDLE_CHECKED(JSArray, prototype, 0); |
24 Object* length = prototype->length(); | 24 Object* length = prototype->length(); |
25 CHECK(length->IsSmi()); | 25 CHECK(length->IsSmi()); |
26 CHECK(Smi::cast(length)->value() == 0); | 26 CHECK(Smi::cast(length)->value() == 0); |
27 CHECK(prototype->HasFastSmiOrObjectElements()); | 27 CHECK(prototype->HasFastSmiOrObjectElements()); |
28 // This is necessary to enable fast checks for absence of elements | 28 // This is necessary to enable fast checks for absence of elements |
29 // on Array.prototype and below. | 29 // on Array.prototype and below. |
30 prototype->set_elements(isolate->heap()->empty_fixed_array()); | 30 prototype->set_elements(isolate->heap()->empty_fixed_array()); |
31 return Smi::kZero; | 31 return Smi::FromInt(0); |
32 } | 32 } |
33 | 33 |
34 static void InstallCode(Isolate* isolate, Handle<JSObject> holder, | 34 static void InstallCode(Isolate* isolate, Handle<JSObject> holder, |
35 const char* name, Handle<Code> code, int argc = -1) { | 35 const char* name, Handle<Code> code, int argc = -1) { |
36 Handle<String> key = isolate->factory()->InternalizeUtf8String(name); | 36 Handle<String> key = isolate->factory()->InternalizeUtf8String(name); |
37 Handle<JSFunction> optimized = | 37 Handle<JSFunction> optimized = |
38 isolate->factory()->NewFunctionWithoutPrototype(key, code); | 38 isolate->factory()->NewFunctionWithoutPrototype(key, code); |
39 if (argc < 0) { | 39 if (argc < 0) { |
40 optimized->shared()->DontAdaptArguments(); | 40 optimized->shared()->DontAdaptArguments(); |
41 } else { | 41 } else { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 JSObject::ValidateElements(from); | 133 JSObject::ValidateElements(from); |
134 JSObject::ValidateElements(to); | 134 JSObject::ValidateElements(to); |
135 | 135 |
136 Handle<FixedArrayBase> new_elements(from->elements()); | 136 Handle<FixedArrayBase> new_elements(from->elements()); |
137 ElementsKind from_kind = from->GetElementsKind(); | 137 ElementsKind from_kind = from->GetElementsKind(); |
138 Handle<Map> new_map = JSObject::GetElementsTransitionMap(to, from_kind); | 138 Handle<Map> new_map = JSObject::GetElementsTransitionMap(to, from_kind); |
139 JSObject::SetMapAndElements(to, new_map, new_elements); | 139 JSObject::SetMapAndElements(to, new_map, new_elements); |
140 to->set_length(from->length()); | 140 to->set_length(from->length()); |
141 | 141 |
142 JSObject::ResetElements(from); | 142 JSObject::ResetElements(from); |
143 from->set_length(Smi::kZero); | 143 from->set_length(Smi::FromInt(0)); |
144 | 144 |
145 JSObject::ValidateElements(to); | 145 JSObject::ValidateElements(to); |
146 return *to; | 146 return *to; |
147 } | 147 } |
148 | 148 |
149 | 149 |
150 // How many elements does this object/array have? | 150 // How many elements does this object/array have? |
151 RUNTIME_FUNCTION(Runtime_EstimateNumberOfElements) { | 151 RUNTIME_FUNCTION(Runtime_EstimateNumberOfElements) { |
152 HandleScope scope(isolate); | 152 HandleScope scope(isolate); |
153 DCHECK(args.length() == 1); | 153 DCHECK(args.length() == 1); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 | 369 |
370 if (key < 0) { | 370 if (key < 0) { |
371 return object->elements(); | 371 return object->elements(); |
372 } | 372 } |
373 | 373 |
374 uint32_t capacity = static_cast<uint32_t>(object->elements()->length()); | 374 uint32_t capacity = static_cast<uint32_t>(object->elements()->length()); |
375 uint32_t index = static_cast<uint32_t>(key); | 375 uint32_t index = static_cast<uint32_t>(key); |
376 | 376 |
377 if (index >= capacity) { | 377 if (index >= capacity) { |
378 if (!object->GetElementsAccessor()->GrowCapacity(object, index)) { | 378 if (!object->GetElementsAccessor()->GrowCapacity(object, index)) { |
379 return Smi::kZero; | 379 return Smi::FromInt(0); |
380 } | 380 } |
381 } | 381 } |
382 | 382 |
383 // On success, return the fixed array elements. | 383 // On success, return the fixed array elements. |
384 return object->elements(); | 384 return object->elements(); |
385 } | 385 } |
386 | 386 |
387 | 387 |
388 RUNTIME_FUNCTION(Runtime_HasComplexElements) { | 388 RUNTIME_FUNCTION(Runtime_HasComplexElements) { |
389 HandleScope scope(isolate); | 389 HandleScope scope(isolate); |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 if (search_element->StrictEquals(*element_k)) { | 634 if (search_element->StrictEquals(*element_k)) { |
635 return *index_obj; | 635 return *index_obj; |
636 } | 636 } |
637 } | 637 } |
638 } | 638 } |
639 return Smi::FromInt(-1); | 639 return Smi::FromInt(-1); |
640 } | 640 } |
641 | 641 |
642 } // namespace internal | 642 } // namespace internal |
643 } // namespace v8 | 643 } // namespace v8 |
OLD | NEW |