• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2019 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// JSReceiver corresponds to objects in the JS sense.
6@abstract
7@highestInstanceTypeWithinParentClassRange
8extern class JSReceiver extends HeapObject {
9  properties_or_hash: SwissNameDictionary|FixedArrayBase|PropertyArray|Smi;
10}
11
12type Constructor extends JSReceiver;
13
14@apiExposedInstanceTypeValue(0x421)
15@highestInstanceTypeWithinParentClassRange
16extern class JSObject extends JSReceiver {
17  // [elements]: The elements (properties with names that are integers).
18  //
19  // Elements can be in two general modes: fast and slow. Each mode
20  // corresponds to a set of object representations of elements that
21  // have something in common.
22  //
23  // In the fast mode elements is a FixedArray and so each element can be
24  // quickly accessed. The elements array can have one of several maps in this
25  // mode: fixed_array_map, fixed_double_array_map,
26  // sloppy_arguments_elements_map or fixed_cow_array_map (for copy-on-write
27  // arrays). In the latter case the elements array may be shared by a few
28  // objects and so before writing to any element the array must be copied. Use
29  // EnsureWritableFastElements in this case.
30  //
31  // In the slow mode the elements is either a NumberDictionary or a
32  // FixedArray parameter map for a (sloppy) arguments object.
33  elements: FixedArrayBase;
34}
35
36macro NewJSObject(implicit context: Context)(): JSObject {
37  const objectFunction: JSFunction = GetObjectFunction();
38  const map: Map = Cast<Map>(objectFunction.prototype_or_initial_map)
39      otherwise unreachable;
40  return AllocateJSObjectFromMap(map);
41}
42
43extern class JSExternalObject extends JSObject { value: ExternalPointer; }
44
45// A JSObject that may contain EmbedderDataSlots.
46@abstract
47extern class JSObjectWithEmbedderSlots extends JSObject {
48}
49
50@abstract
51@lowestInstanceTypeWithinParentClassRange
52extern class JSCustomElementsObject extends JSObject {
53}
54
55// These may also contain EmbedderDataSlots but can't be a child class of
56// JSObjectWithEmbedderSlots due to type id constraints.
57@abstract
58@lowestInstanceTypeWithinParentClassRange
59extern class JSSpecialObject extends JSCustomElementsObject {
60}
61
62macro GetDerivedMap(implicit context: Context)(
63    target: JSFunction, newTarget: JSReceiver): Map {
64  try {
65    const constructor =
66        Cast<JSFunctionWithPrototypeSlot>(newTarget) otherwise SlowPath;
67    dcheck(IsConstructor(constructor));
68    const map =
69        Cast<Map>(constructor.prototype_or_initial_map) otherwise SlowPath;
70    if (LoadConstructorOrBackPointer(map) != target) {
71      goto SlowPath;
72    }
73
74    return map;
75  } label SlowPath {
76    return runtime::GetDerivedMap(context, target, newTarget, FalseConstant());
77  }
78}
79
80macro GetDerivedRabGsabMap(implicit context: Context)(
81    target: JSFunction, newTarget: JSReceiver): Map {
82  return runtime::GetDerivedMap(context, target, newTarget, TrueConstant());
83}
84
85macro AllocateFastOrSlowJSObjectFromMap(implicit context: Context)(map: Map):
86    JSObject {
87  let properties: EmptyFixedArray|NameDictionary|SwissNameDictionary =
88      kEmptyFixedArray;
89  if (IsDictionaryMap(map)) {
90    @if(V8_ENABLE_SWISS_NAME_DICTIONARY) {
91      properties =
92          AllocateSwissNameDictionary(kSwissNameDictionaryInitialCapacity);
93    }
94    @ifnot(V8_ENABLE_SWISS_NAME_DICTIONARY) {
95      properties = AllocateNameDictionary(kNameDictionaryInitialCapacity);
96    }
97  }
98  return AllocateJSObjectFromMap(
99      map, properties, kEmptyFixedArray, AllocationFlag::kNone,
100      SlackTrackingMode::kWithSlackTracking);
101}
102
103extern class JSGlobalProxy extends JSSpecialObject {
104  // [native_context]: the owner native context of this global proxy object.
105  // It is null value if this object is not used by any context.
106  native_context: Object;
107}
108
109extern class JSGlobalObject extends JSSpecialObject {
110  // [native context]: the natives corresponding to this global object.
111  native_context: NativeContext;
112
113  // [global proxy]: the global proxy object of the context
114  global_proxy: JSGlobalProxy;
115}
116
117extern class JSPrimitiveWrapper extends JSCustomElementsObject { value: JSAny; }
118
119extern class JSMessageObject extends JSObject {
120  // Tagged fields.
121  message_type: Smi;
122  // [argument]: the arguments for formatting the error message.
123  argument: Object;
124  // [script]: the script from which the error message originated.
125  script: Script;
126  // [stack_frames]: an array of stack frames for this error object.
127  stack_frames: Object;
128  shared_info: SharedFunctionInfo|Undefined;
129
130  // Raw data fields.
131  // TODO(ishell): store as int32 instead of Smi.
132  bytecode_offset: Smi;
133  start_position: Smi;
134  end_position: Smi;
135  error_level: Smi;
136}
137
138extern class JSDate extends JSObject {
139  // If one component is NaN, all of them are, indicating a NaN time value.
140
141  // The time value.
142  value: NumberOrUndefined;
143
144  // Cached values:
145  year: Undefined|Smi|NaN;
146  month: Undefined|Smi|NaN;
147  day: Undefined|Smi|NaN;
148  weekday: Undefined|Smi|NaN;
149  hour: Undefined|Smi|NaN;
150  min: Undefined|Smi|NaN;
151  sec: Undefined|Smi|NaN;
152
153  // Sample of the date cache stamp at the moment when chached fields were
154  // cached.
155  cache_stamp: Undefined|Smi|NaN;
156}
157
158extern class JSAsyncFromSyncIterator extends JSObject {
159  sync_iterator: JSReceiver;
160  // The "next" method is loaded during GetIterator, and is not reloaded for
161  // subsequent "next" invocations.
162  next: Object;
163}
164
165extern class JSStringIterator extends JSObject {
166  // The [[IteratedString]] slot.
167  string: String;
168  // The [[StringIteratorNextIndex]] slot.
169  index: Smi;
170}
171
172extern macro AllocateJSObjectFromMap(Map): JSObject;
173extern macro AllocateJSObjectFromMap(
174    Map,
175    NameDictionary | SwissNameDictionary | EmptyFixedArray |
176        PropertyArray): JSObject;
177extern macro AllocateJSObjectFromMap(
178    Map, NameDictionary | SwissNameDictionary | EmptyFixedArray | PropertyArray,
179    FixedArray, constexpr AllocationFlag,
180    constexpr SlackTrackingMode): JSObject;
181