1// Copyright 2018 the V8 project authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include 'src/builtins/builtins-collections-gen.h' 6 7namespace collections { 8@export 9macro LoadKeyValuePairNoSideEffects(implicit context: Context)(o: JSAny): 10 KeyValuePair labels MayHaveSideEffects { 11 typeswitch (o) { 12 case (a: FastJSArray): { 13 const length: Smi = a.length; 14 typeswitch (a.elements) { 15 case (elements: FixedArray): { 16 return KeyValuePair{ 17 key: length > 0 ? array::LoadElementOrUndefined(elements, 0) : 18 Undefined, 19 value: length > 1 ? array::LoadElementOrUndefined(elements, 1) : 20 Undefined 21 }; 22 } 23 case (elements: FixedDoubleArray): { 24 return KeyValuePair{ 25 key: length > 0 ? array::LoadElementOrUndefined(elements, 0) : 26 Undefined, 27 value: length > 1 ? array::LoadElementOrUndefined(elements, 1) : 28 Undefined 29 }; 30 } 31 case (FixedArrayBase): deferred { 32 unreachable; 33 } 34 } 35 } 36 case (JSReceiver): { 37 goto MayHaveSideEffects; 38 } 39 case (o: JSAny): deferred { 40 ThrowTypeError(MessageTemplate::kIteratorValueNotAnObject, o); 41 } 42 } 43} 44 45@export 46transitioning macro LoadKeyValuePair(implicit context: Context)(o: JSAny): 47 KeyValuePair { 48 try { 49 return LoadKeyValuePairNoSideEffects(o) otherwise Generic; 50 } label Generic { 51 return KeyValuePair{ 52 key: GetProperty(o, Convert<Smi>(0)), 53 value: GetProperty(o, Convert<Smi>(1)) 54 }; 55 } 56} 57} 58