11cb0ef41Sopenharmony_ci// Copyright 2019 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci// JSReceiver corresponds to objects in the JS sense.
61cb0ef41Sopenharmony_ci@abstract
71cb0ef41Sopenharmony_ci@highestInstanceTypeWithinParentClassRange
81cb0ef41Sopenharmony_ciextern class JSReceiver extends HeapObject {
91cb0ef41Sopenharmony_ci  properties_or_hash: SwissNameDictionary|FixedArrayBase|PropertyArray|Smi;
101cb0ef41Sopenharmony_ci}
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_citype Constructor extends JSReceiver;
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci@apiExposedInstanceTypeValue(0x421)
151cb0ef41Sopenharmony_ci@highestInstanceTypeWithinParentClassRange
161cb0ef41Sopenharmony_ciextern class JSObject extends JSReceiver {
171cb0ef41Sopenharmony_ci  // [elements]: The elements (properties with names that are integers).
181cb0ef41Sopenharmony_ci  //
191cb0ef41Sopenharmony_ci  // Elements can be in two general modes: fast and slow. Each mode
201cb0ef41Sopenharmony_ci  // corresponds to a set of object representations of elements that
211cb0ef41Sopenharmony_ci  // have something in common.
221cb0ef41Sopenharmony_ci  //
231cb0ef41Sopenharmony_ci  // In the fast mode elements is a FixedArray and so each element can be
241cb0ef41Sopenharmony_ci  // quickly accessed. The elements array can have one of several maps in this
251cb0ef41Sopenharmony_ci  // mode: fixed_array_map, fixed_double_array_map,
261cb0ef41Sopenharmony_ci  // sloppy_arguments_elements_map or fixed_cow_array_map (for copy-on-write
271cb0ef41Sopenharmony_ci  // arrays). In the latter case the elements array may be shared by a few
281cb0ef41Sopenharmony_ci  // objects and so before writing to any element the array must be copied. Use
291cb0ef41Sopenharmony_ci  // EnsureWritableFastElements in this case.
301cb0ef41Sopenharmony_ci  //
311cb0ef41Sopenharmony_ci  // In the slow mode the elements is either a NumberDictionary or a
321cb0ef41Sopenharmony_ci  // FixedArray parameter map for a (sloppy) arguments object.
331cb0ef41Sopenharmony_ci  elements: FixedArrayBase;
341cb0ef41Sopenharmony_ci}
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_cimacro NewJSObject(implicit context: Context)(): JSObject {
371cb0ef41Sopenharmony_ci  const objectFunction: JSFunction = GetObjectFunction();
381cb0ef41Sopenharmony_ci  const map: Map = Cast<Map>(objectFunction.prototype_or_initial_map)
391cb0ef41Sopenharmony_ci      otherwise unreachable;
401cb0ef41Sopenharmony_ci  return AllocateJSObjectFromMap(map);
411cb0ef41Sopenharmony_ci}
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ciextern class JSExternalObject extends JSObject { value: ExternalPointer; }
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ci// A JSObject that may contain EmbedderDataSlots.
461cb0ef41Sopenharmony_ci@abstract
471cb0ef41Sopenharmony_ciextern class JSObjectWithEmbedderSlots extends JSObject {
481cb0ef41Sopenharmony_ci}
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ci@abstract
511cb0ef41Sopenharmony_ci@lowestInstanceTypeWithinParentClassRange
521cb0ef41Sopenharmony_ciextern class JSCustomElementsObject extends JSObject {
531cb0ef41Sopenharmony_ci}
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ci// These may also contain EmbedderDataSlots but can't be a child class of
561cb0ef41Sopenharmony_ci// JSObjectWithEmbedderSlots due to type id constraints.
571cb0ef41Sopenharmony_ci@abstract
581cb0ef41Sopenharmony_ci@lowestInstanceTypeWithinParentClassRange
591cb0ef41Sopenharmony_ciextern class JSSpecialObject extends JSCustomElementsObject {
601cb0ef41Sopenharmony_ci}
611cb0ef41Sopenharmony_ci
621cb0ef41Sopenharmony_cimacro GetDerivedMap(implicit context: Context)(
631cb0ef41Sopenharmony_ci    target: JSFunction, newTarget: JSReceiver): Map {
641cb0ef41Sopenharmony_ci  try {
651cb0ef41Sopenharmony_ci    const constructor =
661cb0ef41Sopenharmony_ci        Cast<JSFunctionWithPrototypeSlot>(newTarget) otherwise SlowPath;
671cb0ef41Sopenharmony_ci    dcheck(IsConstructor(constructor));
681cb0ef41Sopenharmony_ci    const map =
691cb0ef41Sopenharmony_ci        Cast<Map>(constructor.prototype_or_initial_map) otherwise SlowPath;
701cb0ef41Sopenharmony_ci    if (LoadConstructorOrBackPointer(map) != target) {
711cb0ef41Sopenharmony_ci      goto SlowPath;
721cb0ef41Sopenharmony_ci    }
731cb0ef41Sopenharmony_ci
741cb0ef41Sopenharmony_ci    return map;
751cb0ef41Sopenharmony_ci  } label SlowPath {
761cb0ef41Sopenharmony_ci    return runtime::GetDerivedMap(context, target, newTarget, FalseConstant());
771cb0ef41Sopenharmony_ci  }
781cb0ef41Sopenharmony_ci}
791cb0ef41Sopenharmony_ci
801cb0ef41Sopenharmony_cimacro GetDerivedRabGsabMap(implicit context: Context)(
811cb0ef41Sopenharmony_ci    target: JSFunction, newTarget: JSReceiver): Map {
821cb0ef41Sopenharmony_ci  return runtime::GetDerivedMap(context, target, newTarget, TrueConstant());
831cb0ef41Sopenharmony_ci}
841cb0ef41Sopenharmony_ci
851cb0ef41Sopenharmony_cimacro AllocateFastOrSlowJSObjectFromMap(implicit context: Context)(map: Map):
861cb0ef41Sopenharmony_ci    JSObject {
871cb0ef41Sopenharmony_ci  let properties: EmptyFixedArray|NameDictionary|SwissNameDictionary =
881cb0ef41Sopenharmony_ci      kEmptyFixedArray;
891cb0ef41Sopenharmony_ci  if (IsDictionaryMap(map)) {
901cb0ef41Sopenharmony_ci    @if(V8_ENABLE_SWISS_NAME_DICTIONARY) {
911cb0ef41Sopenharmony_ci      properties =
921cb0ef41Sopenharmony_ci          AllocateSwissNameDictionary(kSwissNameDictionaryInitialCapacity);
931cb0ef41Sopenharmony_ci    }
941cb0ef41Sopenharmony_ci    @ifnot(V8_ENABLE_SWISS_NAME_DICTIONARY) {
951cb0ef41Sopenharmony_ci      properties = AllocateNameDictionary(kNameDictionaryInitialCapacity);
961cb0ef41Sopenharmony_ci    }
971cb0ef41Sopenharmony_ci  }
981cb0ef41Sopenharmony_ci  return AllocateJSObjectFromMap(
991cb0ef41Sopenharmony_ci      map, properties, kEmptyFixedArray, AllocationFlag::kNone,
1001cb0ef41Sopenharmony_ci      SlackTrackingMode::kWithSlackTracking);
1011cb0ef41Sopenharmony_ci}
1021cb0ef41Sopenharmony_ci
1031cb0ef41Sopenharmony_ciextern class JSGlobalProxy extends JSSpecialObject {
1041cb0ef41Sopenharmony_ci  // [native_context]: the owner native context of this global proxy object.
1051cb0ef41Sopenharmony_ci  // It is null value if this object is not used by any context.
1061cb0ef41Sopenharmony_ci  native_context: Object;
1071cb0ef41Sopenharmony_ci}
1081cb0ef41Sopenharmony_ci
1091cb0ef41Sopenharmony_ciextern class JSGlobalObject extends JSSpecialObject {
1101cb0ef41Sopenharmony_ci  // [native context]: the natives corresponding to this global object.
1111cb0ef41Sopenharmony_ci  native_context: NativeContext;
1121cb0ef41Sopenharmony_ci
1131cb0ef41Sopenharmony_ci  // [global proxy]: the global proxy object of the context
1141cb0ef41Sopenharmony_ci  global_proxy: JSGlobalProxy;
1151cb0ef41Sopenharmony_ci}
1161cb0ef41Sopenharmony_ci
1171cb0ef41Sopenharmony_ciextern class JSPrimitiveWrapper extends JSCustomElementsObject { value: JSAny; }
1181cb0ef41Sopenharmony_ci
1191cb0ef41Sopenharmony_ciextern class JSMessageObject extends JSObject {
1201cb0ef41Sopenharmony_ci  // Tagged fields.
1211cb0ef41Sopenharmony_ci  message_type: Smi;
1221cb0ef41Sopenharmony_ci  // [argument]: the arguments for formatting the error message.
1231cb0ef41Sopenharmony_ci  argument: Object;
1241cb0ef41Sopenharmony_ci  // [script]: the script from which the error message originated.
1251cb0ef41Sopenharmony_ci  script: Script;
1261cb0ef41Sopenharmony_ci  // [stack_frames]: an array of stack frames for this error object.
1271cb0ef41Sopenharmony_ci  stack_frames: Object;
1281cb0ef41Sopenharmony_ci  shared_info: SharedFunctionInfo|Undefined;
1291cb0ef41Sopenharmony_ci
1301cb0ef41Sopenharmony_ci  // Raw data fields.
1311cb0ef41Sopenharmony_ci  // TODO(ishell): store as int32 instead of Smi.
1321cb0ef41Sopenharmony_ci  bytecode_offset: Smi;
1331cb0ef41Sopenharmony_ci  start_position: Smi;
1341cb0ef41Sopenharmony_ci  end_position: Smi;
1351cb0ef41Sopenharmony_ci  error_level: Smi;
1361cb0ef41Sopenharmony_ci}
1371cb0ef41Sopenharmony_ci
1381cb0ef41Sopenharmony_ciextern class JSDate extends JSObject {
1391cb0ef41Sopenharmony_ci  // If one component is NaN, all of them are, indicating a NaN time value.
1401cb0ef41Sopenharmony_ci
1411cb0ef41Sopenharmony_ci  // The time value.
1421cb0ef41Sopenharmony_ci  value: NumberOrUndefined;
1431cb0ef41Sopenharmony_ci
1441cb0ef41Sopenharmony_ci  // Cached values:
1451cb0ef41Sopenharmony_ci  year: Undefined|Smi|NaN;
1461cb0ef41Sopenharmony_ci  month: Undefined|Smi|NaN;
1471cb0ef41Sopenharmony_ci  day: Undefined|Smi|NaN;
1481cb0ef41Sopenharmony_ci  weekday: Undefined|Smi|NaN;
1491cb0ef41Sopenharmony_ci  hour: Undefined|Smi|NaN;
1501cb0ef41Sopenharmony_ci  min: Undefined|Smi|NaN;
1511cb0ef41Sopenharmony_ci  sec: Undefined|Smi|NaN;
1521cb0ef41Sopenharmony_ci
1531cb0ef41Sopenharmony_ci  // Sample of the date cache stamp at the moment when chached fields were
1541cb0ef41Sopenharmony_ci  // cached.
1551cb0ef41Sopenharmony_ci  cache_stamp: Undefined|Smi|NaN;
1561cb0ef41Sopenharmony_ci}
1571cb0ef41Sopenharmony_ci
1581cb0ef41Sopenharmony_ciextern class JSAsyncFromSyncIterator extends JSObject {
1591cb0ef41Sopenharmony_ci  sync_iterator: JSReceiver;
1601cb0ef41Sopenharmony_ci  // The "next" method is loaded during GetIterator, and is not reloaded for
1611cb0ef41Sopenharmony_ci  // subsequent "next" invocations.
1621cb0ef41Sopenharmony_ci  next: Object;
1631cb0ef41Sopenharmony_ci}
1641cb0ef41Sopenharmony_ci
1651cb0ef41Sopenharmony_ciextern class JSStringIterator extends JSObject {
1661cb0ef41Sopenharmony_ci  // The [[IteratedString]] slot.
1671cb0ef41Sopenharmony_ci  string: String;
1681cb0ef41Sopenharmony_ci  // The [[StringIteratorNextIndex]] slot.
1691cb0ef41Sopenharmony_ci  index: Smi;
1701cb0ef41Sopenharmony_ci}
1711cb0ef41Sopenharmony_ci
1721cb0ef41Sopenharmony_ciextern macro AllocateJSObjectFromMap(Map): JSObject;
1731cb0ef41Sopenharmony_ciextern macro AllocateJSObjectFromMap(
1741cb0ef41Sopenharmony_ci    Map,
1751cb0ef41Sopenharmony_ci    NameDictionary | SwissNameDictionary | EmptyFixedArray |
1761cb0ef41Sopenharmony_ci        PropertyArray): JSObject;
1771cb0ef41Sopenharmony_ciextern macro AllocateJSObjectFromMap(
1781cb0ef41Sopenharmony_ci    Map, NameDictionary | SwissNameDictionary | EmptyFixedArray | PropertyArray,
1791cb0ef41Sopenharmony_ci    FixedArray, constexpr AllocationFlag,
1801cb0ef41Sopenharmony_ci    constexpr SlackTrackingMode): JSObject;
181