summaryrefslogtreecommitdiff
path: root/deps/v8/src/builtins/collections.tq
blob: 47d9ec664a65f4ebee4195fe1c1077df21e1d33c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include 'src/builtins/builtins-collections-gen.h'

namespace collections {
  @export
  macro LoadKeyValuePairNoSideEffects(implicit context: Context)(o: JSAny):
      KeyValuePair labels MayHaveSideEffects {
    typeswitch (o) {
      case (a: FastJSArray): {
        const length: Smi = a.length;
        typeswitch (a.elements) {
          case (elements: FixedArray): {
            return KeyValuePair{
              key: length > 0 ? array::LoadElementOrUndefined(elements, 0) :
                                Undefined,
              value: length > 1 ? array::LoadElementOrUndefined(elements, 1) :
                                  Undefined
            };
          }
          case (elements: FixedDoubleArray): {
            return KeyValuePair{
              key: length > 0 ? array::LoadElementOrUndefined(elements, 0) :
                                Undefined,
              value: length > 1 ? array::LoadElementOrUndefined(elements, 1) :
                                  Undefined
            };
          }
          case (FixedArrayBase): deferred {
            unreachable;
          }
        }
      }
      case (JSReceiver): {
        goto MayHaveSideEffects;
      }
      case (o: JSAny): deferred {
        ThrowTypeError(kIteratorValueNotAnObject, o);
      }
    }
  }

  @export
  transitioning macro LoadKeyValuePair(implicit context: Context)(o: JSAny):
      KeyValuePair {
    try {
      return LoadKeyValuePairNoSideEffects(o) otherwise Generic;
    }
    label Generic {
      return KeyValuePair{
        key: GetProperty(o, Convert<Smi>(0)),
        value: GetProperty(o, Convert<Smi>(1))
      };
    }
  }
}