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_cinamespace reflect { 61cb0ef41Sopenharmony_ci// ES6 section 26.1.10 Reflect.isExtensible 71cb0ef41Sopenharmony_citransitioning javascript builtin 81cb0ef41Sopenharmony_ciReflectIsExtensible(js-implicit context: NativeContext)(object: JSAny): JSAny { 91cb0ef41Sopenharmony_ci const objectJSReceiver = Cast<JSReceiver>(object) 101cb0ef41Sopenharmony_ci otherwise ThrowTypeError( 111cb0ef41Sopenharmony_ci MessageTemplate::kCalledOnNonObject, 'Reflect.isExtensible'); 121cb0ef41Sopenharmony_ci return object::ObjectIsExtensibleImpl(objectJSReceiver); 131cb0ef41Sopenharmony_ci} 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci// ES6 section 26.1.12 Reflect.preventExtensions 161cb0ef41Sopenharmony_citransitioning javascript builtin 171cb0ef41Sopenharmony_ciReflectPreventExtensions(js-implicit context: NativeContext)(object: JSAny): 181cb0ef41Sopenharmony_ci JSAny { 191cb0ef41Sopenharmony_ci const objectJSReceiver = Cast<JSReceiver>(object) 201cb0ef41Sopenharmony_ci otherwise ThrowTypeError( 211cb0ef41Sopenharmony_ci MessageTemplate::kCalledOnNonObject, 'Reflect.preventExtensions'); 221cb0ef41Sopenharmony_ci return object::ObjectPreventExtensionsDontThrow(objectJSReceiver); 231cb0ef41Sopenharmony_ci} 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci// ES6 section 26.1.8 Reflect.getPrototypeOf 261cb0ef41Sopenharmony_citransitioning javascript builtin 271cb0ef41Sopenharmony_ciReflectGetPrototypeOf(js-implicit context: NativeContext)(object: JSAny): 281cb0ef41Sopenharmony_ci JSAny { 291cb0ef41Sopenharmony_ci const objectJSReceiver = Cast<JSReceiver>(object) 301cb0ef41Sopenharmony_ci otherwise ThrowTypeError( 311cb0ef41Sopenharmony_ci MessageTemplate::kCalledOnNonObject, 'Reflect.getPrototypeOf'); 321cb0ef41Sopenharmony_ci return object::JSReceiverGetPrototypeOf(objectJSReceiver); 331cb0ef41Sopenharmony_ci} 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci// ES6 section 26.1.14 Reflect.setPrototypeOf 361cb0ef41Sopenharmony_citransitioning javascript builtin ReflectSetPrototypeOf( 371cb0ef41Sopenharmony_ci js-implicit context: NativeContext)(object: JSAny, proto: JSAny): JSAny { 381cb0ef41Sopenharmony_ci const objectJSReceiver = Cast<JSReceiver>(object) 391cb0ef41Sopenharmony_ci otherwise ThrowTypeError( 401cb0ef41Sopenharmony_ci MessageTemplate::kCalledOnNonObject, 'Reflect.setPrototypeOf'); 411cb0ef41Sopenharmony_ci typeswitch (proto) { 421cb0ef41Sopenharmony_ci case (proto: JSReceiver|Null): { 431cb0ef41Sopenharmony_ci return object::ObjectSetPrototypeOfDontThrow(objectJSReceiver, proto); 441cb0ef41Sopenharmony_ci } 451cb0ef41Sopenharmony_ci case (JSAny): { 461cb0ef41Sopenharmony_ci ThrowTypeError(MessageTemplate::kProtoObjectOrNull, proto); 471cb0ef41Sopenharmony_ci } 481cb0ef41Sopenharmony_ci } 491cb0ef41Sopenharmony_ci} 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ciextern transitioning builtin ToName(implicit context: Context)(JSAny): AnyName; 521cb0ef41Sopenharmony_citype OnNonExistent constexpr 'OnNonExistent'; 531cb0ef41Sopenharmony_ciconst kReturnUndefined: constexpr OnNonExistent 541cb0ef41Sopenharmony_ci generates 'OnNonExistent::kReturnUndefined'; 551cb0ef41Sopenharmony_ciextern macro SmiConstant(constexpr OnNonExistent): Smi; 561cb0ef41Sopenharmony_ciextern transitioning builtin GetPropertyWithReceiver(implicit context: Context)( 571cb0ef41Sopenharmony_ci JSAny, Name, JSAny, Smi): JSAny; 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ci// ES6 section 26.1.6 Reflect.get 601cb0ef41Sopenharmony_citransitioning javascript builtin 611cb0ef41Sopenharmony_ciReflectGet(js-implicit context: NativeContext)(...arguments): JSAny { 621cb0ef41Sopenharmony_ci const object: JSAny = arguments[0]; 631cb0ef41Sopenharmony_ci const objectJSReceiver = Cast<JSReceiver>(object) 641cb0ef41Sopenharmony_ci otherwise ThrowTypeError(MessageTemplate::kCalledOnNonObject, 'Reflect.get'); 651cb0ef41Sopenharmony_ci const propertyKey: JSAny = arguments[1]; 661cb0ef41Sopenharmony_ci const name: AnyName = ToName(propertyKey); 671cb0ef41Sopenharmony_ci const receiver: JSAny = 681cb0ef41Sopenharmony_ci arguments.length > 2 ? arguments[2] : objectJSReceiver; 691cb0ef41Sopenharmony_ci return GetPropertyWithReceiver( 701cb0ef41Sopenharmony_ci objectJSReceiver, name, receiver, SmiConstant(kReturnUndefined)); 711cb0ef41Sopenharmony_ci} 721cb0ef41Sopenharmony_ci 731cb0ef41Sopenharmony_ci// ES6 section 26.1.4 Reflect.deleteProperty 741cb0ef41Sopenharmony_citransitioning javascript builtin ReflectDeleteProperty( 751cb0ef41Sopenharmony_ci js-implicit context: NativeContext)(object: JSAny, key: JSAny): JSAny { 761cb0ef41Sopenharmony_ci const objectJSReceiver = Cast<JSReceiver>(object) 771cb0ef41Sopenharmony_ci otherwise ThrowTypeError( 781cb0ef41Sopenharmony_ci MessageTemplate::kCalledOnNonObject, 'Reflect.deleteProperty'); 791cb0ef41Sopenharmony_ci return DeleteProperty(objectJSReceiver, key, LanguageMode::kSloppy); 801cb0ef41Sopenharmony_ci} 811cb0ef41Sopenharmony_ci 821cb0ef41Sopenharmony_ci// ES section #sec-reflect.has 831cb0ef41Sopenharmony_citransitioning javascript builtin 841cb0ef41Sopenharmony_ciReflectHas(js-implicit context: NativeContext)( 851cb0ef41Sopenharmony_ci object: JSAny, key: JSAny): JSAny { 861cb0ef41Sopenharmony_ci const objectJSReceiver = Cast<JSReceiver>(object) 871cb0ef41Sopenharmony_ci otherwise ThrowTypeError(MessageTemplate::kCalledOnNonObject, 'Reflect.has'); 881cb0ef41Sopenharmony_ci return HasProperty(objectJSReceiver, key); 891cb0ef41Sopenharmony_ci} 901cb0ef41Sopenharmony_ci} // namespace reflect 91