js-objects.tq 5.91 KB
Newer Older
Tobias Tebbi's avatar
Tobias Tebbi committed
1 2 3 4 5 6 7 8
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// JSReceiver corresponds to objects in the JS sense.
@abstract
@highestInstanceTypeWithinParentClassRange
extern class JSReceiver extends HeapObject {
9
  properties_or_hash: SwissNameDictionary|FixedArrayBase|PropertyArray|Smi;
Tobias Tebbi's avatar
Tobias Tebbi committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
}

type Constructor extends JSReceiver;

@apiExposedInstanceTypeValue(0x421)
@highestInstanceTypeWithinParentClassRange
extern class JSObject extends JSReceiver {
  // [elements]: The elements (properties with names that are integers).
  //
  // Elements can be in two general modes: fast and slow. Each mode
  // corresponds to a set of object representations of elements that
  // have something in common.
  //
  // In the fast mode elements is a FixedArray and so each element can be
  // quickly accessed. The elements array can have one of several maps in this
  // mode: fixed_array_map, fixed_double_array_map,
  // sloppy_arguments_elements_map or fixed_cow_array_map (for copy-on-write
  // arrays). In the latter case the elements array may be shared by a few
  // objects and so before writing to any element the array must be copied. Use
  // EnsureWritableFastElements in this case.
  //
  // In the slow mode the elements is either a NumberDictionary or a
  // FixedArray parameter map for a (sloppy) arguments object.
  elements: FixedArrayBase;
}

macro NewJSObject(implicit context: Context)(): JSObject {
  const objectFunction: JSFunction = GetObjectFunction();
  const map: Map = Cast<Map>(objectFunction.prototype_or_initial_map)
      otherwise unreachable;
40
  return AllocateJSObjectFromMap(map);
Tobias Tebbi's avatar
Tobias Tebbi committed
41 42
}

Leszek Swirski's avatar
Leszek Swirski committed
43 44 45
extern class JSExternalObject extends JSObject {
  value: ExternalPointer;
}
46

47 48 49 50 51
// A JSObject that may contain EmbedderDataSlots.
@abstract
extern class JSObjectWithEmbedderSlots extends JSObject {
}

Tobias Tebbi's avatar
Tobias Tebbi committed
52 53 54 55 56
@abstract
@lowestInstanceTypeWithinParentClassRange
extern class JSCustomElementsObject extends JSObject {
}

57 58
// These may also contain EmbedderDataSlots but can't be a child class of
// JSObjectWithEmbedderSlots due to type id constraints.
Tobias Tebbi's avatar
Tobias Tebbi committed
59 60 61 62 63 64 65 66
@abstract
@lowestInstanceTypeWithinParentClassRange
extern class JSSpecialObject extends JSCustomElementsObject {
}

macro GetDerivedMap(implicit context: Context)(
    target: JSFunction, newTarget: JSReceiver): Map {
  try {
67 68
    const constructor =
        Cast<JSFunctionWithPrototypeSlot>(newTarget) otherwise SlowPath;
69
    dcheck(IsConstructor(constructor));
Tobias Tebbi's avatar
Tobias Tebbi committed
70 71 72 73 74 75 76
    const map =
        Cast<Map>(constructor.prototype_or_initial_map) otherwise SlowPath;
    if (LoadConstructorOrBackPointer(map) != target) {
      goto SlowPath;
    }

    return map;
77
  } label SlowPath {
78
    return runtime::GetDerivedMap(context, target, newTarget, FalseConstant());
Tobias Tebbi's avatar
Tobias Tebbi committed
79 80 81
  }
}

82 83 84 85 86
macro GetDerivedRabGsabMap(implicit context: Context)(
    target: JSFunction, newTarget: JSReceiver): Map {
  return runtime::GetDerivedMap(context, target, newTarget, TrueConstant());
}

Tobias Tebbi's avatar
Tobias Tebbi committed
87 88
macro AllocateFastOrSlowJSObjectFromMap(implicit context: Context)(map: Map):
    JSObject {
89
  let properties: EmptyFixedArray|NameDictionary|SwissNameDictionary =
90
      kEmptyFixedArray;
Tobias Tebbi's avatar
Tobias Tebbi committed
91
  if (IsDictionaryMap(map)) {
92
    @if(V8_ENABLE_SWISS_NAME_DICTIONARY) {
93
      properties =
94
          AllocateSwissNameDictionary(kSwissNameDictionaryInitialCapacity);
95 96
    }
    @ifnot(V8_ENABLE_SWISS_NAME_DICTIONARY) {
97 98
      properties = AllocateNameDictionary(kNameDictionaryInitialCapacity);
    }
Tobias Tebbi's avatar
Tobias Tebbi committed
99 100
  }
  return AllocateJSObjectFromMap(
101 102
      map, properties, kEmptyFixedArray, AllocationFlag::kNone,
      SlackTrackingMode::kWithSlackTracking);
Tobias Tebbi's avatar
Tobias Tebbi committed
103 104 105 106 107 108 109 110 111
}

extern class JSGlobalProxy extends JSSpecialObject {
  // [native_context]: the owner native context of this global proxy object.
  // It is null value if this object is not used by any context.
  native_context: Object;
}

extern class JSGlobalObject extends JSSpecialObject {
112
  // [native context]: the natives corresponding to this global object.
Tobias Tebbi's avatar
Tobias Tebbi committed
113
  native_context: NativeContext;
114 115

  // [global proxy]: the global proxy object of the context
Tobias Tebbi's avatar
Tobias Tebbi committed
116 117 118
  global_proxy: JSGlobalProxy;
}

Leszek Swirski's avatar
Leszek Swirski committed
119 120 121
extern class JSPrimitiveWrapper extends JSCustomElementsObject {
  value: JSAny;
}
Tobias Tebbi's avatar
Tobias Tebbi committed
122 123 124 125

extern class JSMessageObject extends JSObject {
  // Tagged fields.
  message_type: Smi;
126 127 128
  // [argument]: the arguments for formatting the error message.
  argument: Object;
  // [script]: the script from which the error message originated.
Tobias Tebbi's avatar
Tobias Tebbi committed
129
  script: Script;
130
  // [stack_frames]: an array of stack frames for this error object.
Tobias Tebbi's avatar
Tobias Tebbi committed
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
  stack_frames: Object;
  shared_info: SharedFunctionInfo|Undefined;

  // Raw data fields.
  // TODO(ishell): store as int32 instead of Smi.
  bytecode_offset: Smi;
  start_position: Smi;
  end_position: Smi;
  error_level: Smi;
}

extern class JSDate extends JSObject {
  // If one component is NaN, all of them are, indicating a NaN time value.

  // The time value.
  value: NumberOrUndefined;

  // Cached values:
  year: Undefined|Smi|NaN;
  month: Undefined|Smi|NaN;
  day: Undefined|Smi|NaN;
  weekday: Undefined|Smi|NaN;
  hour: Undefined|Smi|NaN;
  min: Undefined|Smi|NaN;
  sec: Undefined|Smi|NaN;

  // Sample of the date cache stamp at the moment when chached fields were
  // cached.
  cache_stamp: Undefined|Smi|NaN;
}

extern class JSAsyncFromSyncIterator extends JSObject {
  sync_iterator: JSReceiver;
  // The "next" method is loaded during GetIterator, and is not reloaded for
  // subsequent "next" invocations.
  next: Object;
}

extern class JSStringIterator extends JSObject {
170
  // The [[IteratedString]] slot.
Tobias Tebbi's avatar
Tobias Tebbi committed
171
  string: String;
172
  // The [[StringIteratorNextIndex]] slot.
Tobias Tebbi's avatar
Tobias Tebbi committed
173 174 175 176 177
  index: Smi;
}

extern macro AllocateJSObjectFromMap(Map): JSObject;
extern macro AllocateJSObjectFromMap(
178
    Map,
179
    NameDictionary | SwissNameDictionary | EmptyFixedArray |
180
        PropertyArray): JSObject;
Tobias Tebbi's avatar
Tobias Tebbi committed
181
extern macro AllocateJSObjectFromMap(
182
    Map, NameDictionary | SwissNameDictionary | EmptyFixedArray | PropertyArray,
183 184
    FixedArray, constexpr AllocationFlag,
    constexpr SlackTrackingMode): JSObject;