• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2020 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 internal {
6
7namespace runtime {
8extern runtime GetTemplateObject(implicit context: Context)(
9    TemplateObjectDescription, SharedFunctionInfo, Smi): JSAny;
10}
11
12builtin GetTemplateObject(
13    context: Context, shared: SharedFunctionInfo,
14    description: TemplateObjectDescription, slot: uintptr,
15    maybeFeedbackVector: Undefined|FeedbackVector): JSArray {
16  // TODO(jgruber): Consider merging with the GetTemplateObject bytecode
17  // handler; the current advantage of the split implementation is that the
18  // bytecode can skip most work if feedback exists.
19
20  // TODO(v8:9891): Remove this dcheck once all callers are ported to Torque.
21  // This dcheck ensures correctness of maybeFeedbackVector's type which can
22  // be easily broken for calls from CSA.
23  dcheck(
24      IsUndefined(maybeFeedbackVector) ||
25      Is<FeedbackVector>(maybeFeedbackVector));
26  try {
27    const vector =
28        Cast<FeedbackVector>(maybeFeedbackVector) otherwise CallRuntime;
29    return Cast<JSArray>(ic::LoadFeedbackVectorSlot(vector, slot))
30        otherwise CallRuntime;
31  } label CallRuntime deferred {
32    const result = UnsafeCast<JSArray>(runtime::GetTemplateObject(
33        description, shared, Convert<Smi>(Signed(slot))));
34    const vector =
35        Cast<FeedbackVector>(maybeFeedbackVector) otherwise return result;
36    ic::StoreFeedbackVectorSlot(vector, slot, result);
37    return result;
38  }
39}
40
41extern transitioning builtin ForInFilter(implicit context: Context)(
42    JSAny, HeapObject): JSAny;
43extern enum ForInFeedback extends uint31 { kAny, ...}
44extern macro UpdateFeedback(
45    SmiTagged<ForInFeedback>, Undefined | FeedbackVector, uintptr,
46    constexpr UpdateFeedbackMode): void;
47
48@export
49transitioning macro ForInNextSlow(
50    context: Context, slot: uintptr, receiver: JSAnyNotSmi, key: JSAny,
51    cacheType: Object, maybeFeedbackVector: Undefined|FeedbackVector,
52    guaranteedFeedback: constexpr UpdateFeedbackMode): JSAny {
53  dcheck(receiver.map != cacheType);  // Handled on the fast path.
54  UpdateFeedback(
55      SmiTag<ForInFeedback>(ForInFeedback::kAny), maybeFeedbackVector, slot,
56      guaranteedFeedback);
57  return ForInFilter(key, receiver);
58}
59
60// Note: the untagged {slot} parameter must be in the first couple of args to
61// guarantee it's allocated in a register.
62transitioning builtin ForInNext(
63    context: Context, slot: uintptr, receiver: JSAnyNotSmi,
64    cacheArray: FixedArray, cacheType: Object, cacheIndex: Smi,
65    feedbackVector: FeedbackVector): JSAny {
66  // Load the next key from the enumeration array.
67  const key = UnsafeCast<JSAny>(cacheArray.objects[cacheIndex]);
68
69  if (receiver.map == cacheType) {
70    // The enum cache is in use for {receiver}, the {key} is definitely valid.
71    return key;
72  }
73
74  return ForInNextSlow(
75      context, slot, receiver, key, cacheType, feedbackVector,
76      UpdateFeedbackMode::kGuaranteedFeedback);
77}
78
79extern macro GetImportMetaObject(Context): Object;
80extern macro LoadContextFromBaseline(): Context;
81
82builtin GetImportMetaObjectBaseline(): Object {
83  const context: Context = LoadContextFromBaseline();
84  return GetImportMetaObject(context);
85}
86
87}  // namespace internal
88