• 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
5#include "src/ast/ast.h"
6
7namespace runtime {
8extern runtime CreateArrayLiteral(
9    Context, Undefined | FeedbackVector, TaggedIndex,
10    ArrayBoilerplateDescription, Smi): HeapObject;
11extern runtime CreateObjectLiteral(
12    Context, Undefined | FeedbackVector, TaggedIndex,
13    ObjectBoilerplateDescription, Smi): HeapObject;
14}
15
16namespace constructor {
17
18extern builtin FastNewClosure(
19    Context, SharedFunctionInfo, FeedbackCell): JSFunction;
20extern builtin FastNewObject(Context, JSFunction, JSReceiver): JSObject;
21
22extern enum AllocationSiteMode {
23  DONT_TRACK_ALLOCATION_SITE,
24  TRACK_ALLOCATION_SITE
25}
26
27const kIsShallow: constexpr int31
28    generates 'AggregateLiteral::Flags::kIsShallow';
29const kEvalScope: constexpr ScopeType generates 'ScopeType::EVAL_SCOPE';
30const kFunctionScope:
31    constexpr ScopeType generates 'ScopeType::FUNCTION_SCOPE';
32
33extern macro ConstructorBuiltinsAssembler::FastNewFunctionContext(
34    ScopeInfo, uint32, Context, constexpr ScopeType): Context;
35extern macro ConstructorBuiltinsAssembler::CreateRegExpLiteral(
36    HeapObject, TaggedIndex, Object, Smi, Context): JSRegExp;
37extern macro ConstructorBuiltinsAssembler::CreateShallowArrayLiteral(
38    FeedbackVector, TaggedIndex, Context,
39    constexpr AllocationSiteMode): HeapObject labels CallRuntime;
40extern macro ConstructorBuiltinsAssembler::CreateEmptyArrayLiteral(
41    FeedbackVector, TaggedIndex, Context): HeapObject;
42extern macro ConstructorBuiltinsAssembler::CreateShallowObjectLiteral(
43    FeedbackVector, TaggedIndex): HeapObject labels CallRuntime;
44extern macro ConstructorBuiltinsAssembler::CreateEmptyObjectLiteral(Context):
45    JSObject;
46
47extern macro LoadContextFromBaseline(): Context;
48
49builtin FastNewClosureBaseline(
50    sharedFunctionInfo: SharedFunctionInfo,
51    feedbackCell: FeedbackCell): JSFunction {
52  const context = LoadContextFromBaseline();
53  tail FastNewClosure(context, sharedFunctionInfo, feedbackCell);
54}
55
56builtin FastNewFunctionContextEval(implicit context: Context)(
57    scopeInfo: ScopeInfo, slots: uint32): Context {
58  return FastNewFunctionContext(scopeInfo, slots, context, kEvalScope);
59}
60
61builtin FastNewFunctionContextFunction(implicit context: Context)(
62    scopeInfo: ScopeInfo, slots: uint32): Context {
63  return FastNewFunctionContext(scopeInfo, slots, context, kFunctionScope);
64}
65
66builtin CreateRegExpLiteral(implicit context: Context)(
67    maybeFeedbackVector: HeapObject, slot: TaggedIndex, pattern: Object,
68    flags: Smi): JSRegExp {
69  return CreateRegExpLiteral(
70      maybeFeedbackVector, slot, pattern, flags, context);
71}
72
73builtin CreateShallowArrayLiteral(implicit context: Context)(
74    maybeFeedbackVector: Undefined|FeedbackVector, slot: TaggedIndex,
75    constantElements: ArrayBoilerplateDescription, flags: Smi): HeapObject {
76  try {
77    const vector = Cast<FeedbackVector>(maybeFeedbackVector)
78        otherwise CallRuntime;
79    return CreateShallowArrayLiteral(
80        vector, slot, context, AllocationSiteMode::TRACK_ALLOCATION_SITE)
81        otherwise CallRuntime;
82  } label CallRuntime deferred {
83    tail runtime::CreateArrayLiteral(
84        context, maybeFeedbackVector, slot, constantElements, flags);
85  }
86}
87
88builtin CreateEmptyArrayLiteral(implicit context: Context)(
89    feedbackVector: FeedbackVector, slot: TaggedIndex): HeapObject {
90  return CreateEmptyArrayLiteral(feedbackVector, slot, context);
91}
92
93builtin CreateShallowObjectLiteral(implicit context: Context)(
94    maybeFeedbackVector: Undefined|FeedbackVector, slot: TaggedIndex,
95    desc: ObjectBoilerplateDescription, flags: Smi): HeapObject {
96  try {
97    const feedbackVector = Cast<FeedbackVector>(maybeFeedbackVector)
98        otherwise CallRuntime;
99    return CreateShallowObjectLiteral(feedbackVector, slot)
100        otherwise CallRuntime;
101  } label CallRuntime deferred {
102    tail runtime::CreateObjectLiteral(
103        context, maybeFeedbackVector, slot, desc, flags);
104  }
105}
106
107// ES #sec-object-constructor
108transitioning javascript builtin
109ObjectConstructor(
110    js-implicit context: NativeContext, receiver: JSAny, newTarget: JSAny,
111    target: JSFunction)(...arguments): JSAny {
112  if (newTarget == Undefined || newTarget == target) {
113    // Not Subclass.
114    const value = arguments[0];
115    if (arguments.length <= 0 || value == Undefined || value == Null) {
116      // New object.
117      return CreateEmptyObjectLiteral(context);
118    } else {
119      return ToObject(context, value);
120    }
121  } else {
122    // Subclass.
123    return FastNewObject(context, target, UnsafeCast<JSReceiver>(newTarget));
124  }
125}
126
127builtin CreateEmptyLiteralObject(implicit context: Context)(): JSAny {
128  return CreateEmptyObjectLiteral(context);
129}
130
131// ES #sec-number-constructor
132transitioning javascript builtin
133NumberConstructor(
134    js-implicit context: NativeContext, receiver: JSAny, newTarget: JSAny,
135    target: JSFunction)(...arguments): JSAny {
136  // 1. If no arguments were passed to this function invocation, let n be +0.
137  let n: Number = 0;
138  if (arguments.length > 0) {
139    // 2. Else,
140    //    a. Let prim be ? ToNumeric(value).
141    //    b. If Type(prim) is BigInt, let n be the Number value for prim.
142    //    c. Otherwise, let n be prim.
143    const value = arguments[0];
144    n = ToNumber(value, BigIntHandling::kConvertToNumber);
145  }
146
147  // 3. If NewTarget is undefined, return n.
148  if (newTarget == Undefined) return n;
149
150  // 4. Let O be ? OrdinaryCreateFromConstructor(NewTarget,
151  //    "%NumberPrototype%", « [[NumberData]] »).
152  // 5. Set O.[[NumberData]] to n.
153  // 6. Return O.
154
155  // We ignore the normal target parameter and load the value from the
156  // current frame here in order to reduce register pressure on the fast path.
157  const target: JSFunction = LoadTargetFromFrame();
158  const result = UnsafeCast<JSPrimitiveWrapper>(
159      FastNewObject(context, target, UnsafeCast<JSReceiver>(newTarget)));
160  result.value = n;
161  return result;
162}
163
164javascript builtin
165GenericLazyDeoptContinuation(js-implicit context: NativeContext)(result: JSAny):
166    JSAny {
167  return result;
168}
169
170}  // namespace constructor
171