OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/builtins.h" | 5 #include "src/builtins.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/api-arguments.h" | 8 #include "src/api-arguments.h" |
9 #include "src/api-natives.h" | 9 #include "src/api-natives.h" |
10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 } else if (object->IsBoolean()) { | 200 } else if (object->IsBoolean()) { |
201 *out = object->IsTrue(); | 201 *out = object->IsTrue(); |
202 return true; | 202 return true; |
203 } | 203 } |
204 return false; | 204 return false; |
205 } | 205 } |
206 | 206 |
207 | 207 |
208 inline bool GetSloppyArgumentsLength(Isolate* isolate, Handle<JSObject> object, | 208 inline bool GetSloppyArgumentsLength(Isolate* isolate, Handle<JSObject> object, |
209 int* out) { | 209 int* out) { |
210 Map* arguments_map = isolate->native_context()->sloppy_arguments_map(); | 210 Context* context = *isolate->native_context(); |
211 if (object->map() != arguments_map) return false; | 211 Map* map = object->map(); |
212 DCHECK(object->HasFastElements()); | 212 if (map != context->sloppy_arguments_map() && |
213 map != context->strict_arguments_map() && | |
214 map != context->fast_aliased_arguments_map()) { | |
215 return false; | |
216 } | |
217 DCHECK(object->HasFastElements() || object->HasFastArgumentsElements()); | |
213 Object* len_obj = object->InObjectPropertyAt(JSArgumentsObject::kLengthIndex); | 218 Object* len_obj = object->InObjectPropertyAt(JSArgumentsObject::kLengthIndex); |
214 if (!len_obj->IsSmi()) return false; | 219 if (!len_obj->IsSmi()) return false; |
215 *out = Max(0, Smi::cast(len_obj)->value()); | 220 *out = Max(0, Smi::cast(len_obj)->value()); |
216 return *out <= object->elements()->length(); | 221 return *out <= object->elements()->length(); |
217 } | 222 } |
218 | 223 |
219 inline bool PrototypeHasNoElements(Isolate* isolate, JSObject* object) { | 224 inline bool PrototypeHasNoElements(Isolate* isolate, JSObject* object) { |
220 DisallowHeapAllocation no_gc; | 225 DisallowHeapAllocation no_gc; |
221 HeapObject* prototype = HeapObject::cast(object->map()->prototype()); | 226 HeapObject* prototype = HeapObject::cast(object->map()->prototype()); |
222 HeapObject* null = isolate->heap()->null_value(); | 227 HeapObject* null = isolate->heap()->null_value(); |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
663 !isolate->IsArraySpeciesLookupChainIntact() || | 668 !isolate->IsArraySpeciesLookupChainIntact() || |
664 // If this is a subclass of Array, then call out to JS | 669 // If this is a subclass of Array, then call out to JS |
665 !array->map()->new_target_is_base()) { | 670 !array->map()->new_target_is_base()) { |
666 AllowHeapAllocation allow_allocation; | 671 AllowHeapAllocation allow_allocation; |
667 return CallJsIntrinsic(isolate, isolate->array_slice(), args); | 672 return CallJsIntrinsic(isolate, isolate->array_slice(), args); |
668 } | 673 } |
669 len = Smi::cast(array->length())->value(); | 674 len = Smi::cast(array->length())->value(); |
670 } else if (receiver->IsJSObject() && | 675 } else if (receiver->IsJSObject() && |
671 GetSloppyArgumentsLength(isolate, Handle<JSObject>::cast(receiver), | 676 GetSloppyArgumentsLength(isolate, Handle<JSObject>::cast(receiver), |
672 &len)) { | 677 &len)) { |
673 DCHECK_EQ(FAST_ELEMENTS, JSObject::cast(*receiver)->GetElementsKind()); | 678 // Array.prototype.slice.call(arguments, ...) is quite a common idiom |
674 // Array.prototype.slice(arguments, ...) is quite a common idiom | |
675 // (notably more than 50% of invocations in Web apps). | 679 // (notably more than 50% of invocations in Web apps). |
676 // Treat it in C++ as well. | 680 // Treat it in C++ as well.S |
Jakob Kummerow
2016/04/06 11:02:02
s/S//
| |
681 DCHECK(JSObject::cast(*receiver)->HasFastElements() || | |
682 JSObject::cast(*receiver)->HasFastArgumentsElements()); | |
677 } else { | 683 } else { |
678 AllowHeapAllocation allow_allocation; | 684 AllowHeapAllocation allow_allocation; |
679 return CallJsIntrinsic(isolate, isolate->array_slice(), args); | 685 return CallJsIntrinsic(isolate, isolate->array_slice(), args); |
680 } | 686 } |
681 DCHECK_LE(0, len); | 687 DCHECK_LE(0, len); |
682 int argument_count = args.length() - 1; | 688 int argument_count = args.length() - 1; |
683 // Note carefully chosen defaults---if argument is missing, | 689 // Note carefully chosen defaults---if argument is missing, |
684 // it's undefined which gets converted to 0 for relative_start | 690 // it's undefined which gets converted to 0 for relative_start |
685 // and to len for relative_end. | 691 // and to len for relative_end. |
686 relative_start = 0; | 692 relative_start = 0; |
(...skipping 4154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4841 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) | 4847 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) |
4842 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 4848 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
4843 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 4849 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
4844 #undef DEFINE_BUILTIN_ACCESSOR_C | 4850 #undef DEFINE_BUILTIN_ACCESSOR_C |
4845 #undef DEFINE_BUILTIN_ACCESSOR_A | 4851 #undef DEFINE_BUILTIN_ACCESSOR_A |
4846 #undef DEFINE_BUILTIN_ACCESSOR_T | 4852 #undef DEFINE_BUILTIN_ACCESSOR_T |
4847 #undef DEFINE_BUILTIN_ACCESSOR_H | 4853 #undef DEFINE_BUILTIN_ACCESSOR_H |
4848 | 4854 |
4849 } // namespace internal | 4855 } // namespace internal |
4850 } // namespace v8 | 4856 } // namespace v8 |
OLD | NEW |