mirror of
https://github.com/openharmony/ark_js_runtime.git
synced 2026-08-27 10:41:15 -04:00
!366 Add ark container macro switch and add arraylist in runtime_call_id
Merge pull request !366 from xliu/fixArrayList
This commit is contained in:
@@ -21,6 +21,7 @@ namespace panda::ecmascript {
|
||||
#define ARK_NOINLINE __attribute__((noinline))
|
||||
|
||||
#define ECMASCRIPT_ENABLE_DEBUG_MODE 0
|
||||
#define ECMASCRIPT_ENABLE_ARK_CONTAINER 0
|
||||
#define ECMASCRIPT_ENABLE_RUNTIME_STAT 0 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
|
||||
|
||||
/*
|
||||
|
||||
@@ -313,9 +313,11 @@ void Builtins::InitializeGlobalObject(const JSHandle<GlobalEnv> &env, const JSHa
|
||||
SetConstantObject(globalObject, "ArkTools", arkTools);
|
||||
}
|
||||
|
||||
#if ECMASCRIPT_ENABLE_ARK_CONTAINER
|
||||
// Set ArkPrivate
|
||||
JSHandle<JSTaggedValue> arkPrivate(InitializeArkPrivate(env));
|
||||
SetConstantObject(globalObject, "ArkPrivate", arkPrivate);
|
||||
#endif
|
||||
|
||||
// Global object function
|
||||
SetFunction(env, globalObject, "eval", Global::NotSupportEval, FunctionLength::ONE);
|
||||
@@ -2769,6 +2771,19 @@ JSHandle<JSObject> Builtins::InitializeArkPrivate(const JSHandle<GlobalEnv> &env
|
||||
JSHandle<JSObject> arkPrivate = factory_->NewEmptyJSObject();
|
||||
SetFrozenFunction(env, arkPrivate, "Load", ContainersPrivate::Load, FunctionLength::ZERO);
|
||||
SetConstant(arkPrivate, "ArrayList", JSTaggedValue(static_cast<int>(containers::ContainerTag::ArrayList)));
|
||||
SetConstant(arkPrivate, "Queue", JSTaggedValue(static_cast<int>(containers::ContainerTag::Queue)));
|
||||
SetConstant(arkPrivate, "Deque", JSTaggedValue(static_cast<int>(containers::ContainerTag::Deque)));
|
||||
SetConstant(arkPrivate, "Stack", JSTaggedValue(static_cast<int>(containers::ContainerTag::Stack)));
|
||||
SetConstant(arkPrivate, "Vector", JSTaggedValue(static_cast<int>(containers::ContainerTag::Vector)));
|
||||
SetConstant(arkPrivate, "List", JSTaggedValue(static_cast<int>(containers::ContainerTag::List)));
|
||||
SetConstant(arkPrivate, "LinkedList", JSTaggedValue(static_cast<int>(containers::ContainerTag::LinkedList)));
|
||||
SetConstant(arkPrivate, "TreeMap", JSTaggedValue(static_cast<int>(containers::ContainerTag::TreeMap)));
|
||||
SetConstant(arkPrivate, "TreeSet", JSTaggedValue(static_cast<int>(containers::ContainerTag::TreeSet)));
|
||||
SetConstant(arkPrivate, "HashMap", JSTaggedValue(static_cast<int>(containers::ContainerTag::HashMap)));
|
||||
SetConstant(arkPrivate, "HashSet", JSTaggedValue(static_cast<int>(containers::ContainerTag::HashSet)));
|
||||
SetConstant(arkPrivate, "LightWightMap", JSTaggedValue(static_cast<int>(containers::ContainerTag::LightWightMap)));
|
||||
SetConstant(arkPrivate, "LightWightSet", JSTaggedValue(static_cast<int>(containers::ContainerTag::LightWightSet)));
|
||||
SetConstant(arkPrivate, "PlainArray", JSTaggedValue(static_cast<int>(containers::ContainerTag::PlainArray)));
|
||||
return arkPrivate;
|
||||
}
|
||||
} // namespace panda::ecmascript
|
||||
|
||||
@@ -20,7 +20,23 @@
|
||||
|
||||
namespace panda::ecmascript::containers {
|
||||
enum FuncLength : uint8_t { ZERO = 0, ONE, TWO, THREE, FOUR };
|
||||
enum ContainerTag : uint8_t { ArrayList = 0, Queue, END };
|
||||
enum ContainerTag : uint8_t {
|
||||
ArrayList = 0,
|
||||
Queue,
|
||||
Deque,
|
||||
Stack,
|
||||
Vector,
|
||||
List,
|
||||
LinkedList,
|
||||
TreeMap,
|
||||
TreeSet,
|
||||
HashMap,
|
||||
HashSet,
|
||||
LightWightMap,
|
||||
LightWightSet,
|
||||
PlainArray,
|
||||
END
|
||||
};
|
||||
// Using Lazy-loading container, including ArrayList, Queue, Stack, Vector, List, LinkedList, Deque,
|
||||
// TreeMap, TreeSet, HashMap, HashSet, LightWightMap, LightWightSet, PlainArray.
|
||||
// Use through ArkPrivate.Load([ContainerTag]) in js, ContainTag was declaerd in ArkPrivate like ArkPrivate::ArrayList.
|
||||
|
||||
@@ -516,7 +516,10 @@ namespace panda::ecmascript {
|
||||
V(WeakSet, Constructor) \
|
||||
V(WeakSet, Delete) \
|
||||
V(WeakSet, Add) \
|
||||
V(WeakSet, Has)
|
||||
V(WeakSet, Has) \
|
||||
V(ArrayList, Constructor) \
|
||||
V(ArrayList, Add) \
|
||||
V(ArrayList, Iterator)
|
||||
|
||||
#define ABSTRACT_OPERATION_LIST(V) \
|
||||
V(JSTaggedValue, ToString) \
|
||||
|
||||
@@ -16,15 +16,15 @@
|
||||
var fastarray = undefined;
|
||||
if (globalThis["ArkPrivate"] != undefined) {
|
||||
fastarray = ArkPrivate.Load(ArkPrivate.ArrayList);
|
||||
let arr = new fastarray();
|
||||
arr.add(1);
|
||||
arr.add(2);
|
||||
print(arr[0]);
|
||||
|
||||
try {
|
||||
arr["aa"] = 3;
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
}
|
||||
|
||||
let arr = new fastarray();
|
||||
arr.add(1);
|
||||
arr.add(2);
|
||||
print(arr[0]);
|
||||
|
||||
try {
|
||||
arr["aa"] = 3;
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
@@ -12,5 +12,3 @@
|
||||
# limitations under the License.
|
||||
|
||||
container test start
|
||||
1
|
||||
TypeError: Cannot set property on Container
|
||||
|
||||
Reference in New Issue
Block a user