1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ECMASCRIPT_MODULE_JS_MODULE_NAMESPACE_H 17 #define ECMASCRIPT_MODULE_JS_MODULE_NAMESPACE_H 18 19 #include "ecmascript/js_object.h" 20 #include "ecmascript/js_tagged_value.h" 21 22 namespace panda::ecmascript { 23 class ModuleNamespace final : public JSObject { 24 public: 25 CAST_CHECK(ModuleNamespace, IsModuleNamespace); 26 27 static void SetModuleDeregisterProcession(JSThread *thread, const JSHandle<ModuleNamespace> &nameSpace, 28 const DeleteEntryPoint &callback); 29 30 // 9.4.6.11ModuleNamespaceCreate ( module, exports ) 31 static JSHandle<ModuleNamespace> ModuleNamespaceCreate(JSThread *thread, const JSHandle<JSTaggedValue> &module, 32 const JSHandle<TaggedArray> &exports); 33 // 9.4.6.1[[SetPrototypeOf]] 34 static bool SetPrototype(const JSHandle<JSTaggedValue> &obj, 35 const JSHandle<JSTaggedValue> &proto); 36 // 9.4.6.3[[PreventExtensions]] 37 static bool PreventExtensions(); 38 // 9.4.6.4[[GetOwnProperty]] 39 static bool GetOwnProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj, const JSHandle<JSTaggedValue> &key, 40 PropertyDescriptor &desc); 41 // 9.4.6.5[[DefineOwnProperty]] ( P, Desc ) 42 static bool DefineOwnProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj, 43 const JSHandle<JSTaggedValue> &key, PropertyDescriptor desc); 44 // 9.4.6.6[[HasProperty]] 45 static bool HasProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj, const JSHandle<JSTaggedValue> &key); 46 // 9.4.6.7[[Get]] ( P, Receiver ) 47 static OperationResult GetProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj, 48 const JSHandle<JSTaggedValue> &key); 49 // 9.4.6.8[[Set]] ( P, V, Receiver ) 50 static bool SetProperty(JSThread *thread, bool mayThrow); 51 // 9.4.6.9[[Delete]] ( P ) 52 static bool DeleteProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj, 53 const JSHandle<JSTaggedValue> &key); 54 // 9.4.6.10[[OwnPropertyKeys]] 55 static JSHandle<TaggedArray> OwnPropertyKeys(JSThread *thread, const JSHandle<JSTaggedValue> &proxy); 56 57 static JSHandle<TaggedArray> OwnEnumPropertyKeys(JSThread *thread, const JSHandle<JSTaggedValue> &obj); 58 59 bool ValidateKeysAvailable(JSThread *thread, const JSHandle<TaggedArray> &exports); 60 61 static constexpr size_t MODULE_OFFSET = JSObject::SIZE; 62 ACCESSORS(Module, MODULE_OFFSET, EXPORTS_OFFSET) 63 ACCESSORS(Exports, EXPORTS_OFFSET, DEREGISTER_PROCESSION_OFFSET) 64 ACCESSORS(DeregisterProcession, DEREGISTER_PROCESSION_OFFSET, SIZE) 65 66 DECL_DUMP() 67 DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, MODULE_OFFSET, SIZE) 68 }; 69 } // namespace panda::ecmascript 70 #endif // ECMASCRIPT_MODULE_JS_MODULE_NAMESPACE_H 71