14514f5e3Sopenharmony_ci/* 24514f5e3Sopenharmony_ci * Copyright (c) 2021 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#ifndef ECMASCRIPT_JSPROXY_H 174514f5e3Sopenharmony_ci#define ECMASCRIPT_JSPROXY_H 184514f5e3Sopenharmony_ci 194514f5e3Sopenharmony_ci#include "ecmascript/ecma_runtime_call_info.h" 204514f5e3Sopenharmony_ci#include "ecmascript/js_object.h" 214514f5e3Sopenharmony_ci#include "ecmascript/tagged_array.h" 224514f5e3Sopenharmony_ci 234514f5e3Sopenharmony_cinamespace panda::ecmascript { 244514f5e3Sopenharmony_ciclass JSProxy final : public ECMAObject { 254514f5e3Sopenharmony_cipublic: 264514f5e3Sopenharmony_ci CAST_CHECK(JSProxy, IsJSProxy); 274514f5e3Sopenharmony_ci 284514f5e3Sopenharmony_ci // ES6 9.5.15 ProxyCreate(target, handler) 294514f5e3Sopenharmony_ci static JSHandle<JSProxy> ProxyCreate(JSThread *thread, const JSHandle<JSTaggedValue> &target, 304514f5e3Sopenharmony_ci const JSHandle<JSTaggedValue> &handler); 314514f5e3Sopenharmony_ci // ES6 9.5.1 [[GetPrototypeOf]] ( ) 324514f5e3Sopenharmony_ci static JSTaggedValue GetPrototype(JSThread *thread, const JSHandle<JSProxy> &proxy); 334514f5e3Sopenharmony_ci // ES6 9.5.2 [[SetPrototypeOf]] (V) 344514f5e3Sopenharmony_ci static bool SetPrototype(JSThread *thread, const JSHandle<JSProxy> &proxy, const JSHandle<JSTaggedValue> &proto); 354514f5e3Sopenharmony_ci // ES6 9.5.3 [[IsExtensible]] ( ) 364514f5e3Sopenharmony_ci static bool IsExtensible(JSThread *thread, const JSHandle<JSProxy> &proxy); 374514f5e3Sopenharmony_ci // ES6 9.5.4 [[PreventExtensions]] ( ) 384514f5e3Sopenharmony_ci static bool PreventExtensions(JSThread *thread, const JSHandle<JSProxy> &proxy); 394514f5e3Sopenharmony_ci // ES6 9.5.5 [[GetOwnProperty]] (P) 404514f5e3Sopenharmony_ci static bool GetOwnProperty(JSThread *thread, const JSHandle<JSProxy> &proxy, const JSHandle<JSTaggedValue> &key, 414514f5e3Sopenharmony_ci PropertyDescriptor &desc); 424514f5e3Sopenharmony_ci // ES6 9.5.6 [[DefineOwnProperty]] (P, Desc) 434514f5e3Sopenharmony_ci static bool DefineOwnProperty(JSThread *thread, const JSHandle<JSProxy> &proxy, const JSHandle<JSTaggedValue> &key, 444514f5e3Sopenharmony_ci const PropertyDescriptor &desc); 454514f5e3Sopenharmony_ci // ES6 9.5.7 [[HasProperty]] (P) 464514f5e3Sopenharmony_ci static bool HasProperty(JSThread *thread, const JSHandle<JSProxy> &proxy, const JSHandle<JSTaggedValue> &key); 474514f5e3Sopenharmony_ci // ES6 9.5.8 [[Get]] (P, Receiver) 484514f5e3Sopenharmony_ci static inline OperationResult GetProperty(JSThread *thread, const JSHandle<JSProxy> &proxy, 494514f5e3Sopenharmony_ci const JSHandle<JSTaggedValue> &key) 504514f5e3Sopenharmony_ci { 514514f5e3Sopenharmony_ci return GetProperty(thread, proxy, key, JSHandle<JSTaggedValue>::Cast(proxy)); 524514f5e3Sopenharmony_ci } 534514f5e3Sopenharmony_ci static OperationResult GetProperty(JSThread *thread, const JSHandle<JSProxy> &proxy, 544514f5e3Sopenharmony_ci const JSHandle<JSTaggedValue> &key, const JSHandle<JSTaggedValue> &receiver); 554514f5e3Sopenharmony_ci // ES6 9.5.9 [[Set]] ( P, V, Receiver) 564514f5e3Sopenharmony_ci static inline bool SetProperty(JSThread *thread, const JSHandle<JSProxy> &proxy, const JSHandle<JSTaggedValue> &key, 574514f5e3Sopenharmony_ci const JSHandle<JSTaggedValue> &value, bool mayThrow = false) 584514f5e3Sopenharmony_ci { 594514f5e3Sopenharmony_ci return SetProperty(thread, proxy, key, value, JSHandle<JSTaggedValue>::Cast(proxy), mayThrow); 604514f5e3Sopenharmony_ci } 614514f5e3Sopenharmony_ci static bool SetProperty(JSThread *thread, const JSHandle<JSProxy> &proxy, const JSHandle<JSTaggedValue> &key, 624514f5e3Sopenharmony_ci const JSHandle<JSTaggedValue> &value, const JSHandle<JSTaggedValue> &receiver, 634514f5e3Sopenharmony_ci bool mayThrow = false); 644514f5e3Sopenharmony_ci // ES6 9.5.10 [[Delete]] (P) 654514f5e3Sopenharmony_ci static bool DeleteProperty(JSThread *thread, const JSHandle<JSProxy> &proxy, const JSHandle<JSTaggedValue> &key); 664514f5e3Sopenharmony_ci 674514f5e3Sopenharmony_ci // ES6 9.5.12 [[OwnPropertyKeys]] () 684514f5e3Sopenharmony_ci static JSHandle<TaggedArray> OwnPropertyKeys(JSThread *thread, const JSHandle<JSProxy> &proxy); 694514f5e3Sopenharmony_ci 704514f5e3Sopenharmony_ci static JSHandle<TaggedArray> GetAllPropertyKeys(JSThread *thread, const JSHandle<JSProxy> &proxy, uint32_t filter); 714514f5e3Sopenharmony_ci 724514f5e3Sopenharmony_ci void SetCallable(bool callable) const 734514f5e3Sopenharmony_ci { 744514f5e3Sopenharmony_ci GetClass()->SetCallable(callable); 754514f5e3Sopenharmony_ci } 764514f5e3Sopenharmony_ci 774514f5e3Sopenharmony_ci void SetConstructor(bool constructor) const 784514f5e3Sopenharmony_ci { 794514f5e3Sopenharmony_ci GetClass()->SetConstructor(constructor); 804514f5e3Sopenharmony_ci } 814514f5e3Sopenharmony_ci 824514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> GetSourceTarget(JSThread *thread) const; 834514f5e3Sopenharmony_ci 844514f5e3Sopenharmony_ci // ES6 9.5.13 [[Call]] (thisArgument, argumentsList) 854514f5e3Sopenharmony_ci static JSTaggedValue CallInternal(EcmaRuntimeCallInfo *info); 864514f5e3Sopenharmony_ci // ES6 9.5.14 [[Construct]] ( argumentsList, newTarget) 874514f5e3Sopenharmony_ci static JSTaggedValue ConstructInternal(EcmaRuntimeCallInfo *info); 884514f5e3Sopenharmony_ci 894514f5e3Sopenharmony_ci bool PUBLIC_API IsArray(JSThread *thread) const; 904514f5e3Sopenharmony_ci 914514f5e3Sopenharmony_ci static constexpr size_t TARGET_OFFSET = ECMAObject::SIZE; 924514f5e3Sopenharmony_ci ACCESSORS(Target, TARGET_OFFSET, HANDLER_OFFSET) 934514f5e3Sopenharmony_ci ACCESSORS(Handler, HANDLER_OFFSET, METHOD_OFFSET) 944514f5e3Sopenharmony_ci ACCESSORS(Method, METHOD_OFFSET, PRIVATE_FIELD_OFFSET) 954514f5e3Sopenharmony_ci ACCESSORS(PrivateField, PRIVATE_FIELD_OFFSET, BIT_FIELD_OFFSET) 964514f5e3Sopenharmony_ci ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET) 974514f5e3Sopenharmony_ci DEFINE_ALIGN_SIZE(LAST_OFFSET); 984514f5e3Sopenharmony_ci 994514f5e3Sopenharmony_ci // define BitField 1004514f5e3Sopenharmony_ci static constexpr size_t IS_REVOKED_BITS = 1; 1014514f5e3Sopenharmony_ci FIRST_BIT_FIELD(BitField, IsRevoked, bool, IS_REVOKED_BITS) 1024514f5e3Sopenharmony_ci 1034514f5e3Sopenharmony_ci DECL_DUMP() 1044514f5e3Sopenharmony_ci 1054514f5e3Sopenharmony_ci DECL_VISIT_OBJECT(TARGET_OFFSET, BIT_FIELD_OFFSET) 1064514f5e3Sopenharmony_ci}; 1074514f5e3Sopenharmony_ci} // namespace panda::ecmascript 1084514f5e3Sopenharmony_ci 1094514f5e3Sopenharmony_ci#endif // ECMASCRIPT_JSPROXY_H 110