• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 JSHandle<JSTaggedValue> CreateSortedExports(JSThread *thread, const JSHandle<TaggedArray> &exports);
28 
29     static void SetModuleDeregisterProcession(JSThread *thread, const JSHandle<ModuleNamespace> &nameSpace,
30         const NativePointerCallback &callback);
31 
32     // 9.4.6.11ModuleNamespaceCreate ( module, exports )
33     static JSHandle<ModuleNamespace> ModuleNamespaceCreate(JSThread *thread, const JSHandle<JSTaggedValue> &module,
34                                                            const JSHandle<TaggedArray> &exports);
35     // 9.4.6.1[[SetPrototypeOf]]
36     static bool SetPrototype(const JSHandle<JSTaggedValue> &obj,
37                              const JSHandle<JSTaggedValue> &proto);
38     // 9.4.6.3[[PreventExtensions]]
39     static bool PreventExtensions();
40     // 9.4.6.4[[GetOwnProperty]]
41     static bool GetOwnProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj, const JSHandle<JSTaggedValue> &key,
42                                PropertyDescriptor &desc);
43     // 9.4.6.5[[DefineOwnProperty]] ( P, Desc )
44     static bool DefineOwnProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
45                                   const JSHandle<JSTaggedValue> &key, PropertyDescriptor desc);
46     // 9.4.6.6[[HasProperty]]
47     static bool HasProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj, const JSHandle<JSTaggedValue> &key);
48     // 9.4.6.7[[Get]] ( P, Receiver )
49     static OperationResult GetProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
50                                        const JSHandle<JSTaggedValue> &key);
51     // 9.4.6.8[[Set]] ( P, V, Receiver )
52     static bool SetProperty(JSThread *thread, bool mayThrow);
53     // 9.4.6.9[[Delete]] ( P )
54     static bool DeleteProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
55                                const JSHandle<JSTaggedValue> &key);
56     // 9.4.6.10[[OwnPropertyKeys]]
57     static JSHandle<TaggedArray> OwnPropertyKeys(JSThread *thread, const JSHandle<JSTaggedValue> &proxy);
58 
59     static JSHandle<TaggedArray> OwnEnumPropertyKeys(JSThread *thread, const JSHandle<JSTaggedValue> &obj);
60 
61     static bool ValidateKeysAvailable(JSThread *thread, const JSHandle<ModuleNamespace> &moduleNamespace,
62                                       const JSHandle<TaggedArray> &exports);
63 
64     static constexpr size_t MODULE_OFFSET = JSObject::SIZE;
65     ACCESSORS(Module, MODULE_OFFSET, EXPORTS_OFFSET)
66     ACCESSORS(Exports, EXPORTS_OFFSET, DEREGISTER_PROCESSION_OFFSET)
67     ACCESSORS(DeregisterProcession, DEREGISTER_PROCESSION_OFFSET, SIZE)
68 
69     DECL_DUMP()
70     DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, MODULE_OFFSET, SIZE)
71 };
72 }  // namespace panda::ecmascript
73 #endif  // ECMASCRIPT_MODULE_JS_MODULE_NAMESPACE_H
74