14514f5e3Sopenharmony_ci/* 24514f5e3Sopenharmony_ci * Copyright (c) 2021-2024 Huawei Device Co., Ltd. 34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License. 54514f5e3Sopenharmony_ci * You may obtain a copy of the License at 64514f5e3Sopenharmony_ci * 74514f5e3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84514f5e3Sopenharmony_ci * 94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and 134514f5e3Sopenharmony_ci * limitations under the License. 144514f5e3Sopenharmony_ci */ 154514f5e3Sopenharmony_ci 164514f5e3Sopenharmony_ci#include "ecmascript/js_arguments.h" 174514f5e3Sopenharmony_ci 184514f5e3Sopenharmony_ci#include "ecmascript/js_tagged_value-inl.h" 194514f5e3Sopenharmony_ci#include "ecmascript/object_factory.h" 204514f5e3Sopenharmony_ci 214514f5e3Sopenharmony_cinamespace panda::ecmascript { 224514f5e3Sopenharmony_cibool JSArguments::GetOwnProperty(JSThread *thread, const JSHandle<JSArguments> &args, 234514f5e3Sopenharmony_ci const JSHandle<JSTaggedValue> &key, PropertyDescriptor &desc) 244514f5e3Sopenharmony_ci{ 254514f5e3Sopenharmony_ci // 1 ~ 3 Let desc be OrdinaryGetOwnProperty(args, P). 264514f5e3Sopenharmony_ci JSObject::OrdinaryGetOwnProperty(thread, JSHandle<JSObject>(args), key, desc); 274514f5e3Sopenharmony_ci if (desc.IsEmpty()) { 284514f5e3Sopenharmony_ci return true; 294514f5e3Sopenharmony_ci } 304514f5e3Sopenharmony_ci 314514f5e3Sopenharmony_ci // 8.If IsDataDescriptor(desc) is true and P is "caller" and desc.[[Value]] is a strict mode Function object, 324514f5e3Sopenharmony_ci // throw a TypeError exception. 334514f5e3Sopenharmony_ci JSHandle<EcmaString> caller = thread->GetEcmaVM()->GetFactory()->NewFromASCII("caller"); 344514f5e3Sopenharmony_ci if (desc.IsDataDescriptor() && JSTaggedValue::SameValue(key.GetTaggedValue(), caller.GetTaggedValue()) && 354514f5e3Sopenharmony_ci desc.GetValue()->IsJSFunction()) { 364514f5e3Sopenharmony_ci THROW_TYPE_ERROR_AND_RETURN(thread, "Arguments GetOwnProperty: type error", false); 374514f5e3Sopenharmony_ci } 384514f5e3Sopenharmony_ci // 9.Return desc. 394514f5e3Sopenharmony_ci return true; 404514f5e3Sopenharmony_ci} 414514f5e3Sopenharmony_ci 424514f5e3Sopenharmony_cibool JSArguments::DefineOwnProperty(JSThread *thread, const JSHandle<JSArguments> &args, 434514f5e3Sopenharmony_ci const JSHandle<JSTaggedValue> &key, const PropertyDescriptor &desc) 444514f5e3Sopenharmony_ci{ 454514f5e3Sopenharmony_ci // 4.Let allowed be OrdinaryDefineOwnProperty(args, P, Desc). 464514f5e3Sopenharmony_ci bool allowed = JSObject::OrdinaryDefineOwnProperty(thread, JSHandle<JSObject>(args), key, desc); 474514f5e3Sopenharmony_ci 484514f5e3Sopenharmony_ci // 5.ReturnIfAbrupt(allowed). 494514f5e3Sopenharmony_ci RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, allowed); 504514f5e3Sopenharmony_ci 514514f5e3Sopenharmony_ci // 8.Return true. 524514f5e3Sopenharmony_ci return true; 534514f5e3Sopenharmony_ci} 544514f5e3Sopenharmony_ci 554514f5e3Sopenharmony_ciOperationResult JSArguments::GetProperty(JSThread *thread, const JSHandle<JSArguments> &args, 564514f5e3Sopenharmony_ci const JSHandle<JSTaggedValue> &key, const JSHandle<JSTaggedValue> &receiver) 574514f5e3Sopenharmony_ci{ 584514f5e3Sopenharmony_ci // 5.If the value of isMapped is false, then 594514f5e3Sopenharmony_ci // a.Return the result of calling the default ordinary object [[Get]] internal method (9.1.8) 604514f5e3Sopenharmony_ci // on args passing P and Receiver as the arguments. 614514f5e3Sopenharmony_ci return JSTaggedValue::GetProperty(thread, JSHandle<JSTaggedValue>::Cast(args), key, receiver); 624514f5e3Sopenharmony_ci} 634514f5e3Sopenharmony_ci 644514f5e3Sopenharmony_cibool JSArguments::SetProperty(JSThread *thread, const JSHandle<JSArguments> &args, const JSHandle<JSTaggedValue> &key, 654514f5e3Sopenharmony_ci const JSHandle<JSTaggedValue> &value, const JSHandle<JSTaggedValue> &receiver) 664514f5e3Sopenharmony_ci{ 674514f5e3Sopenharmony_ci // 5.Return the result of calling the default ordinary object [[Set]] internal method (9.1.9) 684514f5e3Sopenharmony_ci // on args passing P, V and Receiver as the arguments. 694514f5e3Sopenharmony_ci return JSTaggedValue::SetProperty(thread, JSHandle<JSTaggedValue>::Cast(args), key, value, receiver); 704514f5e3Sopenharmony_ci} 714514f5e3Sopenharmony_ci 724514f5e3Sopenharmony_cibool JSArguments::DeleteProperty(JSThread *thread, const JSHandle<JSArguments> &args, 734514f5e3Sopenharmony_ci const JSHandle<JSTaggedValue> &key) 744514f5e3Sopenharmony_ci{ 754514f5e3Sopenharmony_ci // 4.Let result be the result of calling the default [[Delete]] internal method for ordinary objects (9.1.10) 764514f5e3Sopenharmony_ci // on the arguments object passing P as the argument. 774514f5e3Sopenharmony_ci bool result = JSTaggedValue::DeleteProperty(thread, JSHandle<JSTaggedValue>(args), key); 784514f5e3Sopenharmony_ci 794514f5e3Sopenharmony_ci // 5.ReturnIfAbrupt(result). 804514f5e3Sopenharmony_ci RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, result); 814514f5e3Sopenharmony_ci 824514f5e3Sopenharmony_ci // 7.Return result. 834514f5e3Sopenharmony_ci return result; 844514f5e3Sopenharmony_ci} 854514f5e3Sopenharmony_ci} // namespace panda::ecmascript 86