• 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 reflect {
6// ES6 section 26.1.10 Reflect.isExtensible
7transitioning javascript builtin
8ReflectIsExtensible(js-implicit context: NativeContext)(object: JSAny): JSAny {
9  const objectJSReceiver = Cast<JSReceiver>(object)
10      otherwise ThrowTypeError(
11      MessageTemplate::kCalledOnNonObject, 'Reflect.isExtensible');
12  return object::ObjectIsExtensibleImpl(objectJSReceiver);
13}
14
15// ES6 section 26.1.12 Reflect.preventExtensions
16transitioning javascript builtin
17ReflectPreventExtensions(js-implicit context: NativeContext)(object: JSAny):
18    JSAny {
19  const objectJSReceiver = Cast<JSReceiver>(object)
20      otherwise ThrowTypeError(
21      MessageTemplate::kCalledOnNonObject, 'Reflect.preventExtensions');
22  return object::ObjectPreventExtensionsDontThrow(objectJSReceiver);
23}
24
25// ES6 section 26.1.8 Reflect.getPrototypeOf
26transitioning javascript builtin
27ReflectGetPrototypeOf(js-implicit context: NativeContext)(object: JSAny):
28    JSAny {
29  const objectJSReceiver = Cast<JSReceiver>(object)
30      otherwise ThrowTypeError(
31      MessageTemplate::kCalledOnNonObject, 'Reflect.getPrototypeOf');
32  return object::JSReceiverGetPrototypeOf(objectJSReceiver);
33}
34
35// ES6 section 26.1.14 Reflect.setPrototypeOf
36transitioning javascript builtin ReflectSetPrototypeOf(
37    js-implicit context: NativeContext)(object: JSAny, proto: JSAny): JSAny {
38  const objectJSReceiver = Cast<JSReceiver>(object)
39      otherwise ThrowTypeError(
40      MessageTemplate::kCalledOnNonObject, 'Reflect.setPrototypeOf');
41  typeswitch (proto) {
42    case (proto: JSReceiver|Null): {
43      return object::ObjectSetPrototypeOfDontThrow(objectJSReceiver, proto);
44    }
45    case (JSAny): {
46      ThrowTypeError(MessageTemplate::kProtoObjectOrNull, proto);
47    }
48  }
49}
50
51extern transitioning builtin ToName(implicit context: Context)(JSAny): AnyName;
52type OnNonExistent constexpr 'OnNonExistent';
53const kReturnUndefined: constexpr OnNonExistent
54    generates 'OnNonExistent::kReturnUndefined';
55extern macro SmiConstant(constexpr OnNonExistent): Smi;
56extern transitioning builtin GetPropertyWithReceiver(implicit context: Context)(
57    JSAny, Name, JSAny, Smi): JSAny;
58
59// ES6 section 26.1.6 Reflect.get
60transitioning javascript builtin
61ReflectGet(js-implicit context: NativeContext)(...arguments): JSAny {
62  const object: JSAny = arguments[0];
63  const objectJSReceiver = Cast<JSReceiver>(object)
64      otherwise ThrowTypeError(MessageTemplate::kCalledOnNonObject, 'Reflect.get');
65  const propertyKey: JSAny = arguments[1];
66  const name: AnyName = ToName(propertyKey);
67  const receiver: JSAny =
68      arguments.length > 2 ? arguments[2] : objectJSReceiver;
69  return GetPropertyWithReceiver(
70      objectJSReceiver, name, receiver, SmiConstant(kReturnUndefined));
71}
72
73// ES6 section 26.1.4 Reflect.deleteProperty
74transitioning javascript builtin ReflectDeleteProperty(
75    js-implicit context: NativeContext)(object: JSAny, key: JSAny): JSAny {
76  const objectJSReceiver = Cast<JSReceiver>(object)
77      otherwise ThrowTypeError(
78      MessageTemplate::kCalledOnNonObject, 'Reflect.deleteProperty');
79  return DeleteProperty(objectJSReceiver, key, LanguageMode::kSloppy);
80}
81
82// ES section #sec-reflect.has
83transitioning javascript builtin
84ReflectHas(js-implicit context: NativeContext)(
85    object: JSAny, key: JSAny): JSAny {
86  const objectJSReceiver = Cast<JSReceiver>(object)
87      otherwise ThrowTypeError(MessageTemplate::kCalledOnNonObject, 'Reflect.has');
88  return HasProperty(objectJSReceiver, key);
89}
90}  // namespace reflect
91