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_MODULE_JS_MODULE_NAMESPACE_H
174514f5e3Sopenharmony_ci#define ECMASCRIPT_MODULE_JS_MODULE_NAMESPACE_H
184514f5e3Sopenharmony_ci
194514f5e3Sopenharmony_ci#include "ecmascript/js_object.h"
204514f5e3Sopenharmony_ci#include "ecmascript/js_tagged_value.h"
214514f5e3Sopenharmony_ci
224514f5e3Sopenharmony_cinamespace panda::ecmascript {
234514f5e3Sopenharmony_ciclass ModuleNamespace final : public JSObject {
244514f5e3Sopenharmony_cipublic:
254514f5e3Sopenharmony_ci    CAST_CHECK(ModuleNamespace, IsModuleNamespace);
264514f5e3Sopenharmony_ci
274514f5e3Sopenharmony_ci    static JSHandle<JSTaggedValue> CreateSortedExports(JSThread *thread, const JSHandle<TaggedArray> &exports);
284514f5e3Sopenharmony_ci
294514f5e3Sopenharmony_ci    static void SetModuleDeregisterProcession(JSThread *thread, const JSHandle<ModuleNamespace> &nameSpace,
304514f5e3Sopenharmony_ci        const NativePointerCallback &callback);
314514f5e3Sopenharmony_ci
324514f5e3Sopenharmony_ci    // 9.4.6.11ModuleNamespaceCreate ( module, exports )
334514f5e3Sopenharmony_ci    static JSHandle<ModuleNamespace> ModuleNamespaceCreate(JSThread *thread, const JSHandle<JSTaggedValue> &module,
344514f5e3Sopenharmony_ci                                                           const JSHandle<TaggedArray> &exports);
354514f5e3Sopenharmony_ci    // 9.4.6.1[[SetPrototypeOf]]
364514f5e3Sopenharmony_ci    static bool SetPrototype(const JSHandle<JSTaggedValue> &obj,
374514f5e3Sopenharmony_ci                             const JSHandle<JSTaggedValue> &proto);
384514f5e3Sopenharmony_ci    // 9.4.6.3[[PreventExtensions]]
394514f5e3Sopenharmony_ci    static bool PreventExtensions();
404514f5e3Sopenharmony_ci    // 9.4.6.4[[GetOwnProperty]]
414514f5e3Sopenharmony_ci    static bool GetOwnProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj, const JSHandle<JSTaggedValue> &key,
424514f5e3Sopenharmony_ci                               PropertyDescriptor &desc);
434514f5e3Sopenharmony_ci    // 9.4.6.5[[DefineOwnProperty]] ( P, Desc )
444514f5e3Sopenharmony_ci    static bool DefineOwnProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
454514f5e3Sopenharmony_ci                                  const JSHandle<JSTaggedValue> &key, PropertyDescriptor desc);
464514f5e3Sopenharmony_ci    // 9.4.6.6[[HasProperty]]
474514f5e3Sopenharmony_ci    static bool HasProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj, const JSHandle<JSTaggedValue> &key);
484514f5e3Sopenharmony_ci    // 9.4.6.7[[Get]] ( P, Receiver )
494514f5e3Sopenharmony_ci    static OperationResult GetProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
504514f5e3Sopenharmony_ci                                       const JSHandle<JSTaggedValue> &key);
514514f5e3Sopenharmony_ci    // 9.4.6.8[[Set]] ( P, V, Receiver )
524514f5e3Sopenharmony_ci    static bool SetProperty(JSThread *thread, bool mayThrow);
534514f5e3Sopenharmony_ci    // 9.4.6.9[[Delete]] ( P )
544514f5e3Sopenharmony_ci    static bool DeleteProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
554514f5e3Sopenharmony_ci                               const JSHandle<JSTaggedValue> &key);
564514f5e3Sopenharmony_ci    // 9.4.6.10[[OwnPropertyKeys]]
574514f5e3Sopenharmony_ci    static JSHandle<TaggedArray> OwnPropertyKeys(JSThread *thread, const JSHandle<JSTaggedValue> &proxy);
584514f5e3Sopenharmony_ci
594514f5e3Sopenharmony_ci    static JSHandle<TaggedArray> OwnEnumPropertyKeys(JSThread *thread, const JSHandle<JSTaggedValue> &obj);
604514f5e3Sopenharmony_ci
614514f5e3Sopenharmony_ci    bool ValidateKeysAvailable(JSThread *thread, const JSHandle<TaggedArray> &exports);
624514f5e3Sopenharmony_ci
634514f5e3Sopenharmony_ci    static constexpr size_t MODULE_OFFSET = JSObject::SIZE;
644514f5e3Sopenharmony_ci    ACCESSORS(Module, MODULE_OFFSET, EXPORTS_OFFSET)
654514f5e3Sopenharmony_ci    ACCESSORS(Exports, EXPORTS_OFFSET, DEREGISTER_PROCESSION_OFFSET)
664514f5e3Sopenharmony_ci    ACCESSORS(DeregisterProcession, DEREGISTER_PROCESSION_OFFSET, SIZE)
674514f5e3Sopenharmony_ci
684514f5e3Sopenharmony_ci    DECL_DUMP()
694514f5e3Sopenharmony_ci    DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, MODULE_OFFSET, SIZE)
704514f5e3Sopenharmony_ci};
714514f5e3Sopenharmony_ci}  // namespace panda::ecmascript
724514f5e3Sopenharmony_ci#endif  // ECMASCRIPT_MODULE_JS_MODULE_NAMESPACE_H
73