• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 (JSAny): {
37      goto MayHaveSideEffects;
38    }
39  }
40}
41
42@export
43transitioning macro LoadKeyValuePair(implicit context: Context)(o: JSAny):
44    KeyValuePair {
45  try {
46    return LoadKeyValuePairNoSideEffects(o) otherwise Generic;
47  } label Generic {
48    const o = Cast<JSReceiver>(o)
49        otherwise ThrowTypeError(MessageTemplate::kIteratorValueNotAnObject, o);
50    return KeyValuePair{
51      key: GetProperty(o, Convert<Smi>(0)),
52      value: GetProperty(o, Convert<Smi>(1))
53    };
54  }
55}
56}
57