• 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
5namespace runtime {
6extern transitioning runtime
7ObjectIsExtensible(implicit context: Context)(JSAny): JSAny;
8
9extern transitioning runtime
10JSReceiverPreventExtensionsThrow(implicit context: Context)(JSReceiver): JSAny;
11
12extern transitioning runtime
13JSReceiverPreventExtensionsDontThrow(implicit context: Context)(JSReceiver):
14    JSAny;
15
16extern transitioning runtime
17JSReceiverGetPrototypeOf(implicit context: Context)(JSReceiver): JSAny;
18
19extern transitioning runtime
20JSReceiverSetPrototypeOfThrow(implicit context: Context)(
21    JSReceiver, JSAny): JSAny;
22
23extern transitioning runtime
24JSReceiverSetPrototypeOfDontThrow(implicit context: Context)(
25    JSReceiver, JSAny): JSAny;
26
27extern transitioning runtime ObjectCreate(implicit context: Context)(
28    JSAny, JSAny): JSAny;
29}  // namespace runtime
30
31namespace object {
32transitioning macro
33ObjectIsExtensibleImpl(implicit context: Context)(object: JSAny): JSAny {
34  const objectJSReceiver = Cast<JSReceiver>(object) otherwise return False;
35  const objectJSProxy = Cast<JSProxy>(objectJSReceiver)
36      otherwise return runtime::ObjectIsExtensible(objectJSReceiver);
37  return proxy::ProxyIsExtensible(objectJSProxy);
38}
39
40transitioning macro
41ObjectPreventExtensionsThrow(implicit context: Context)(object: JSAny): JSAny {
42  const objectJSReceiver = Cast<JSReceiver>(object) otherwise return object;
43  const objectJSProxy = Cast<JSProxy>(objectJSReceiver)
44      otherwise return runtime::JSReceiverPreventExtensionsThrow(objectJSReceiver);
45  proxy::ProxyPreventExtensions(objectJSProxy, True);
46  return objectJSReceiver;
47}
48
49transitioning macro
50ObjectPreventExtensionsDontThrow(implicit context: Context)(object: JSAny):
51    JSAny {
52  const objectJSReceiver = Cast<JSReceiver>(object) otherwise return False;
53  const objectJSProxy = Cast<JSProxy>(objectJSReceiver)
54      otherwise return runtime::JSReceiverPreventExtensionsDontThrow(
55      objectJSReceiver);
56  return proxy::ProxyPreventExtensions(objectJSProxy, False);
57}
58
59transitioning macro
60ObjectGetPrototypeOfImpl(implicit context: Context)(object: JSAny): JSAny {
61  const objectJSReceiver: JSReceiver = ToObject_Inline(context, object);
62  return object::JSReceiverGetPrototypeOf(objectJSReceiver);
63}
64
65transitioning macro
66JSReceiverGetPrototypeOf(implicit context: Context)(object: JSReceiver): JSAny {
67  const objectJSProxy = Cast<JSProxy>(object)
68      otherwise return runtime::JSReceiverGetPrototypeOf(object);
69  return proxy::ProxyGetPrototypeOf(objectJSProxy);
70}
71
72transitioning macro
73ObjectSetPrototypeOfThrow(implicit context: Context)(
74    object: JSAny, proto: JSReceiver|Null): JSAny {
75  const objectJSReceiver = Cast<JSReceiver>(object) otherwise return object;
76  const objectJSProxy = Cast<JSProxy>(objectJSReceiver)
77      otherwise return runtime::JSReceiverSetPrototypeOfThrow(
78      objectJSReceiver, proto);
79  proxy::ProxySetPrototypeOf(objectJSProxy, proto, True);
80  return objectJSReceiver;
81}
82
83transitioning macro
84ObjectSetPrototypeOfDontThrow(implicit context: Context)(
85    object: JSAny, proto: JSReceiver|Null): JSAny {
86  const objectJSReceiver = Cast<JSReceiver>(object) otherwise return False;
87  const objectJSProxy = Cast<JSProxy>(objectJSReceiver)
88      otherwise return runtime::JSReceiverSetPrototypeOfDontThrow(
89      objectJSReceiver, proto);
90  return proxy::ProxySetPrototypeOf(objectJSProxy, proto, False);
91}
92
93transitioning builtin CreateObjectWithoutProperties(implicit context: Context)(
94    prototype: JSAny): JSAny {
95  try {
96    let map: Map;
97    let properties: NameDictionary|SwissNameDictionary|EmptyFixedArray;
98    typeswitch (prototype) {
99      case (Null): {
100        map = *NativeContextSlot(
101            ContextSlot::SLOW_OBJECT_WITH_NULL_PROTOTYPE_MAP);
102        @if(V8_ENABLE_SWISS_NAME_DICTIONARY) {
103          properties =
104              AllocateSwissNameDictionary(kSwissNameDictionaryInitialCapacity);
105        }
106        @ifnot(V8_ENABLE_SWISS_NAME_DICTIONARY) {
107          properties = AllocateNameDictionary(kNameDictionaryInitialCapacity);
108        }
109      }
110      case (prototype: JSReceiver): {
111        properties = kEmptyFixedArray;
112        const objectFunction =
113            *NativeContextSlot(ContextSlot::OBJECT_FUNCTION_INDEX);
114        map = UnsafeCast<Map>(objectFunction.prototype_or_initial_map);
115        if (prototype != map.prototype) {
116          const prototypeInfo = prototype.map.PrototypeInfo() otherwise Runtime;
117          typeswitch (prototypeInfo.object_create_map) {
118            case (Undefined): {
119              goto Runtime;
120            }
121            case (weak_map: Weak<Map>): {
122              map = WeakToStrong(weak_map) otherwise Runtime;
123            }
124          }
125        }
126      }
127      case (JSAny): {
128        goto Runtime;
129      }
130    }
131    return AllocateJSObjectFromMap(map, properties);
132  } label Runtime deferred {
133    return runtime::ObjectCreate(prototype, Undefined);
134  }
135}
136
137// ES6 section 19.1.2.11 Object.isExtensible ( O )
138transitioning javascript builtin
139ObjectIsExtensible(js-implicit context: NativeContext)(object: JSAny): JSAny {
140  return object::ObjectIsExtensibleImpl(object);
141}
142
143// ES6 section 19.1.2.18 Object.preventExtensions ( O )
144transitioning javascript builtin
145ObjectPreventExtensions(js-implicit context: NativeContext)(object: JSAny):
146    JSAny {
147  return object::ObjectPreventExtensionsThrow(object);
148}
149
150// ES6 section 19.1.2.9 Object.getPrototypeOf ( O )
151transitioning javascript builtin
152ObjectGetPrototypeOf(js-implicit context: NativeContext)(object: JSAny): JSAny {
153  return object::ObjectGetPrototypeOfImpl(object);
154}
155
156// ES6 section 19.1.2.21 Object.setPrototypeOf ( O, proto )
157transitioning javascript builtin ObjectSetPrototypeOf(
158    js-implicit context: NativeContext)(object: JSAny, proto: JSAny): JSAny {
159  // 1. Set O to ? RequireObjectCoercible(O).
160  RequireObjectCoercible(object, 'Object.setPrototypeOf');
161
162  // 2. If Type(proto) is neither Object nor Null, throw a TypeError
163  // exception.
164  // 3. If Type(O) is not Object, return O.
165  // 4. Let status be ? O.[[SetPrototypeOf]](proto).
166  // 5. If status is false, throw a TypeError exception.
167  // 6. Return O.
168  typeswitch (proto) {
169    case (proto: JSReceiver|Null): {
170      return object::ObjectSetPrototypeOfThrow(object, proto);
171    }
172    case (JSAny): {
173      ThrowTypeError(MessageTemplate::kProtoObjectOrNull, proto);
174    }
175  }
176}
177
178// ES #sec-object.prototype.tostring
179transitioning javascript builtin ObjectPrototypeToString(
180    js-implicit context: Context, receiver: JSAny)(): String {
181  return ObjectToString(context, receiver);
182}
183
184// ES #sec-object.prototype.valueof
185transitioning javascript builtin ObjectPrototypeValueOf(
186    js-implicit context: Context, receiver: JSAny)(): JSReceiver {
187  // 1. Return ? ToObject(this value).
188  return ToObject_Inline(context, receiver);
189}
190
191// ES #sec-object.prototype.tolocalestring
192transitioning javascript builtin ObjectPrototypeToLocaleString(
193    js-implicit context: Context, receiver: JSAny)(): JSAny {
194  // 1. Let O be the this value.
195  // 2. Return ? Invoke(O, "toString").
196  if (receiver == Null || receiver == Undefined) deferred {
197      ThrowTypeError(
198          MessageTemplate::kCalledOnNullOrUndefined,
199          'Object.prototype.toLocaleString');
200    }
201  const method = GetProperty(receiver, 'toString');
202  return Call(context, method, receiver);
203}
204}  // namespace object
205