• 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
5namespace object {
6
7transitioning macro ObjectFromEntriesFastCase(implicit context: Context)(
8    iterable: JSAny): JSObject labels IfSlow {
9  typeswitch (iterable) {
10    case (array: FastJSArrayWithNoCustomIteration): {
11      const elements: FixedArray =
12          Cast<FixedArray>(array.elements) otherwise IfSlow;
13      const length: Smi = array.length;
14      const result: JSObject = NewJSObject();
15
16      for (let k: Smi = 0; k < length; ++k) {
17        const value: JSAny = array::LoadElementOrUndefined(elements, k);
18        const pair: KeyValuePair =
19            collections::LoadKeyValuePairNoSideEffects(value)
20            otherwise IfSlow;
21        // Bail out if ToPropertyKey will attempt to load and call
22        // Symbol.toPrimitive, toString, and valueOf, which could
23        // invalidate assumptions about the iterable.
24        if (Is<JSReceiver>(pair.key)) goto IfSlow;
25        FastCreateDataProperty(result, pair.key, pair.value);
26      }
27      return result;
28    }
29    case (JSAny): {
30      goto IfSlow;
31    }
32  }
33}
34
35transitioning javascript builtin
36ObjectFromEntries(
37    js-implicit context: NativeContext, receiver: JSAny)(...arguments): JSAny {
38  const iterable: JSAny = arguments[0];
39  try {
40    if (IsNullOrUndefined(iterable)) goto Throw;
41    return ObjectFromEntriesFastCase(iterable) otherwise IfSlow;
42  } label IfSlow {
43    const result: JSObject = NewJSObject();
44    const fastIteratorResultMap: Map = GetIteratorResultMap();
45    let i: iterator::IteratorRecord = iterator::GetIterator(iterable);
46    try {
47      assert(!IsNullOrUndefined(i.object));
48      while (true) {
49        const step: JSReceiver =
50            iterator::IteratorStep(i, fastIteratorResultMap)
51            otherwise return result;
52        const iteratorValue: JSAny =
53            iterator::IteratorValue(step, fastIteratorResultMap);
54        const pair: KeyValuePair = collections::LoadKeyValuePair(iteratorValue);
55        FastCreateDataProperty(result, pair.key, pair.value);
56      }
57      return result;
58    } catch (e) deferred {
59      iterator::IteratorCloseOnException(i);
60      ReThrow(context, e);
61    }
62  } label Throw deferred {
63    ThrowTypeError(MessageTemplate::kNotIterable);
64  }
65}
66}  // namespace object
67