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