Description:

Reduce redundant code by using predefined global constants instead of creating new constant strings
Move all global constant strings into nonmovable space to improve code efficiency.

Issues: https://gitee.com/openharmony/ark_js_runtime/issues/I588TY

Signed-off-by: yaoyuan <yuanyao14@huawei.com>
Change-Id: I1f92188175c3129c5d8cec72a0396f11ce17c1c7
This commit is contained in:
yaoyuan 2022-05-31 16:29:55 +08:00
parent 77314ed185
commit b80c0196ca
26 changed files with 472 additions and 317 deletions

View File

@ -336,10 +336,10 @@ JSHandle<EcmaString> NumberHelper::NumberToString(const JSThread *thread, JSTagg
double d = number.GetDouble();
if (std::isnan(d)) {
return factory->NewFromASCII("NaN");
return JSHandle<EcmaString>::Cast(thread->GlobalConstants()->GetHandledNanCapitalString());
}
if (d == 0.0) {
return factory->NewFromASCII("0");
return JSHandle<EcmaString>::Cast(thread->GlobalConstants()->GetHandledZeroString());
}
if (d >= INT32_MIN + 1 && d <= INT32_MAX && d == static_cast<double>(static_cast<int32_t>(d))) {
return factory->NewFromASCII(IntToString(static_cast<int32_t>(d)));

View File

@ -46,7 +46,6 @@ JSTaggedValue BuiltinsArray::ArrayConstructor(EcmaRuntimeCallInfo *argv)
BUILTINS_API_TRACE(argv->GetThread(), Array, Constructor);
JSThread *thread = argv->GetThread();
[[maybe_unused]] EcmaHandleScope handleScope(thread);
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
// 1. Let numberOfArgs be the number of arguments passed to this function call.
uint32_t argc = argv->GetArgsNumber();
@ -84,7 +83,7 @@ JSTaggedValue BuiltinsArray::ArrayConstructor(EcmaRuntimeCallInfo *argv)
// 9. Let setStatus be Set(array, "length", intLen, true).
// 10. Assert: setStatus is not an abrupt completion.
if (!len->IsNumber()) {
JSHandle<JSTaggedValue> key0(factory->NewFromASCII("0"));
JSHandle<JSTaggedValue> key0 = thread->GlobalConstants()->GetHandledZeroString();
JSObject::CreateDataProperty(thread, newArrayHandle, key0, len);
newLen = 1;
} else {
@ -1187,7 +1186,7 @@ JSTaggedValue BuiltinsArray::Join(EcmaRuntimeCallInfo *argv)
// 6. Let sep be ToString(separator).
JSHandle<JSTaggedValue> sepHandle;
if ((GetCallArg(argv, 0)->IsUndefined())) {
sepHandle = JSHandle<JSTaggedValue>::Cast(factory->NewFromASCII(","));
sepHandle = thread->GlobalConstants()->GetHandledCommaString();
} else {
sepHandle = GetCallArg(argv, 0);
}
@ -2486,7 +2485,6 @@ JSTaggedValue BuiltinsArray::ToString(EcmaRuntimeCallInfo *argv)
JSThread *thread = argv->GetThread();
[[maybe_unused]] EcmaHandleScope handleScope(thread);
auto ecmaVm = thread->GetEcmaVM();
ObjectFactory *factory = ecmaVm->GetFactory();
// 1. Let array be ToObject(this value).
JSHandle<JSTaggedValue> thisHandle = GetThis(argv);
@ -2496,7 +2494,7 @@ JSTaggedValue BuiltinsArray::ToString(EcmaRuntimeCallInfo *argv)
JSHandle<JSTaggedValue> thisObjVal(thisObjHandle);
// 3. Let func be Get(array, "join").
JSHandle<JSTaggedValue> joinKey(factory->NewFromASCII("join"));
JSHandle<JSTaggedValue> joinKey = thread->GlobalConstants()->GetHandledJoinString();
JSHandle<JSTaggedValue> callbackFnHandle = JSTaggedValue::GetProperty(thread, thisObjVal, joinKey).GetValue();
// 4. ReturnIfAbrupt(func).
@ -2633,39 +2631,40 @@ JSTaggedValue BuiltinsArray::Unscopables(EcmaRuntimeCallInfo *argv)
JSThread *thread = argv->GetThread();
[[maybe_unused]] EcmaHandleScope handleScope(thread);
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
const GlobalEnvConstants *globalConst = thread->GlobalConstants();
JSHandle<JSTaggedValue> nullHandle(thread, JSTaggedValue::Null());
JSHandle<JSObject> unscopableList = factory->OrdinaryNewJSObjectCreate(nullHandle);
JSHandle<JSTaggedValue> trueVal(thread, JSTaggedValue::True());
JSHandle<JSTaggedValue> copyWithKey(factory->NewFromASCII("copyWithin"));
JSHandle<JSTaggedValue> copyWithKey = globalConst->GetHandledCopyWithinString();
JSObject::CreateDataProperty(thread, unscopableList, copyWithKey, trueVal);
JSHandle<JSTaggedValue> entriesKey(factory->NewFromASCII("entries"));
JSHandle<JSTaggedValue> entriesKey = globalConst->GetHandledEntriesString();
JSObject::CreateDataProperty(thread, unscopableList, entriesKey, trueVal);
JSHandle<JSTaggedValue> fillKey(factory->NewFromASCII("fill"));
JSHandle<JSTaggedValue> fillKey = globalConst->GetHandledFillString();
JSObject::CreateDataProperty(thread, unscopableList, fillKey, trueVal);
JSHandle<JSTaggedValue> findKey(factory->NewFromASCII("find"));
JSHandle<JSTaggedValue> findKey = globalConst->GetHandledFindString();
JSObject::CreateDataProperty(thread, unscopableList, findKey, trueVal);
JSHandle<JSTaggedValue> findIndexKey(factory->NewFromASCII("findIndex"));
JSHandle<JSTaggedValue> findIndexKey = globalConst->GetHandledFindIndexString();
JSObject::CreateDataProperty(thread, unscopableList, findIndexKey, trueVal);
JSHandle<JSTaggedValue> flatKey(factory->NewFromASCII("flat"));
JSHandle<JSTaggedValue> flatKey = globalConst->GetHandledFlatString();
JSObject::CreateDataProperty(thread, unscopableList, flatKey, trueVal);
JSHandle<JSTaggedValue> flatMapKey(factory->NewFromASCII("flatMap"));
JSHandle<JSTaggedValue> flatMapKey = globalConst->GetHandledFlatMapString();
JSObject::CreateDataProperty(thread, unscopableList, flatMapKey, trueVal);
JSHandle<JSTaggedValue> includesKey(factory->NewFromASCII("includes"));
JSHandle<JSTaggedValue> includesKey = globalConst->GetHandledIncludesString();
JSObject::CreateDataProperty(thread, unscopableList, includesKey, trueVal);
JSHandle<JSTaggedValue> keysKey(factory->NewFromASCII("keys"));
JSHandle<JSTaggedValue> keysKey = globalConst->GetHandledKeysString();
JSObject::CreateDataProperty(thread, unscopableList, keysKey, trueVal);
JSHandle<JSTaggedValue> valuesKey(factory->NewFromASCII("values"));
JSHandle<JSTaggedValue> valuesKey = globalConst->GetHandledValuesString();
JSObject::CreateDataProperty(thread, unscopableList, valuesKey, trueVal);
return unscopableList.GetTaggedValue();

View File

@ -204,20 +204,20 @@ JSTaggedValue BuiltinsDate::ToPrimitive(EcmaRuntimeCallInfo *argv)
JSThread *thread = argv->GetThread();
[[maybe_unused]] EcmaHandleScope handleScope(thread);
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<JSTaggedValue> object = GetThis(argv);
if (!object->IsECMAObject()) {
THROW_TYPE_ERROR_AND_RETURN(thread, "Not a JSObject", JSTaggedValue::Exception());
}
JSHandle<JSTaggedValue> hint = GetCallArg(argv, 0);
PreferredPrimitiveType tryFirst = PREFER_STRING;
const GlobalEnvConstants *globalConst = thread->GlobalConstants();
if (hint->IsString()) {
JSHandle<EcmaString> numberStrHandle = factory->NewFromASCII("number");
JSHandle<EcmaString> numberStrHandle = JSHandle<EcmaString>::Cast(globalConst->GetHandledNumberString());
if (EcmaString::StringsAreEqual(hint.GetObject<EcmaString>(), *numberStrHandle)) {
tryFirst = PREFER_NUMBER;
} else {
JSHandle<EcmaString> stringStrHandle = factory->NewFromASCII("string");
JSHandle<EcmaString> defaultStrHandle = factory->NewFromASCII("default");
JSHandle<EcmaString> stringStrHandle = JSHandle<EcmaString>::Cast(globalConst->GetHandledStringString());
JSHandle<EcmaString> defaultStrHandle = JSHandle<EcmaString>::Cast(globalConst->GetHandledDefaultString());
if (EcmaString::StringsAreEqual(hint.GetObject<EcmaString>(), *stringStrHandle) ||
EcmaString::StringsAreEqual(hint.GetObject<EcmaString>(), *defaultStrHandle)) {
tryFirst = PREFER_STRING;

View File

@ -203,7 +203,7 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeBind(EcmaRuntimeCallInfo *argv)
// 13. ReturnIfAbrupt(targetName).
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSTaggedValue> boundName(factory->NewFromASCII("bound"));
JSHandle<JSTaggedValue> boundName = thread->GlobalConstants()->GetHandledBoundString();
// 14. If Type(targetName) is not String, let targetName be the empty string.
// 15. Perform SetFunctionName(F, targetName, "bound").
if (!targetName->IsString()) {

View File

@ -291,7 +291,7 @@ JSTaggedValue BuiltinsLocale::GetLanguage(EcmaRuntimeCallInfo *argv)
// 4. Assert: locale matches the unicode_locale_id production.
// 5. Return the substring of locale corresponding to the unicode_language_subtag production of the
// unicode_language_id.
JSHandle<EcmaString> result = factory->NewFromASCII("undefined");
JSHandle<EcmaString> result = JSHandle<EcmaString>::Cast(thread->GlobalConstants()->GetHandledUndefinedString());
CString language = locale->GetIcuLocale()->getLanguage();
if (language.empty()) {
return result.GetTaggedValue();

View File

@ -57,7 +57,7 @@ JSTaggedValue BuiltinsMap::MapConstructor(EcmaRuntimeCallInfo *argv)
THROW_TYPE_ERROR_AND_RETURN(thread, "iterable is not object", JSTaggedValue::Exception());
}
// Let adder be Get(map, "set").
JSHandle<JSTaggedValue> adderKey(factory->NewFromASCII("set"));
JSHandle<JSTaggedValue> adderKey = thread->GlobalConstants()->GetHandledSetString();
JSHandle<JSTaggedValue> adder = JSObject::GetProperty(thread, JSHandle<JSTaggedValue>(map), adderKey).GetValue();
// ReturnIfAbrupt(adder).
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, adder.GetTaggedValue());

View File

@ -782,7 +782,7 @@ JSTaggedValue BuiltinsObject::GetBuiltinTag(JSThread *thread, const JSHandle<JSO
} else if (object->IsCallable()) {
builtinTag = factory->NewFromASCII("Function");
} else if (object->IsJSError()) {
builtinTag = factory->NewFromASCII("Error");
builtinTag = JSHandle<EcmaString>::Cast(thread->GlobalConstants()->GetHandledErrorString());
} else if (object->IsDate()) {
builtinTag = factory->NewFromASCII("Date");
} else if (object->IsJSRegExp()) {

View File

@ -228,7 +228,7 @@ JSTaggedValue BuiltinsRegExp::ToString(EcmaRuntimeCallInfo *argv)
JSHandle<EcmaString> flagsStrHandle = JSTaggedValue::ToString(thread, getFlags);
// 4. ReturnIfAbrupt(flags).
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<EcmaString> slashStr = factory->NewFromASCII("/");
JSHandle<EcmaString> slashStr = JSHandle<EcmaString>::Cast(globalConstants->GetHandledBackslashString());
// 7. Let result be the String value formed by concatenating "/", pattern, and "/", and flags.
JSHandle<EcmaString> tempStr = factory->ConcatFromString(slashStr, sourceStrHandle);
JSHandle<EcmaString> resultTemp = factory->ConcatFromString(tempStr, slashStr);
@ -1085,12 +1085,12 @@ JSTaggedValue BuiltinsRegExp::Split(EcmaRuntimeCallInfo *argv)
bool unicodeMatching = base::StringHelper::Contains(*flags, *uStringHandle);
// 11. If flags contains "y", let newFlags be flags.
JSHandle<EcmaString> newFlagsHandle;
JSHandle<EcmaString> yStringHandle(factory->NewFromASCII("y"));
JSHandle<EcmaString> yStringHandle = JSHandle<EcmaString>::Cast(globalConstants->GetHandledYString());
if (base::StringHelper::Contains(*flags, *yStringHandle)) {
newFlagsHandle = flags;
} else {
// 12. Else, let newFlags be the string that is the concatenation of flags and "y".
JSHandle<EcmaString> yStr = factory->NewFromASCII("y");
JSHandle<EcmaString> yStr = JSHandle<EcmaString>::Cast(globalConstants->GetHandledYString());
newFlagsHandle = factory->ConcatFromString(flags, yStr);
}
@ -1126,7 +1126,7 @@ JSTaggedValue BuiltinsRegExp::Split(EcmaRuntimeCallInfo *argv)
// 13. Let splitter be Construct(C, «rx, newFlags»).
JSHandle<JSObject> globalObject(thread, thread->GetEcmaVM()->GetGlobalEnv()->GetGlobalObject());
JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
JSHandle<JSTaggedValue> undefined = globalConstants->GetHandledUndefined();
EcmaRuntimeCallInfo runtimeInfo =
EcmaInterpreter::NewRuntimeCallInfo(thread, constructor, undefined, undefined, 2); // 2: two args
runtimeInfo.SetCallArg(thisObj.GetTaggedValue(), newFlagsHandle.GetTaggedValue());
@ -1168,7 +1168,7 @@ JSTaggedValue BuiltinsRegExp::Split(EcmaRuntimeCallInfo *argv)
uint32_t endIndex = startIndex;
JSMutableHandle<JSTaggedValue> lastIndexvalue(thread, JSTaggedValue(endIndex));
// 24. Repeat, while q < size
JSHandle<JSTaggedValue> lastIndexString(thread->GlobalConstants()->GetHandledLastIndexString());
JSHandle<JSTaggedValue> lastIndexString = globalConstants->GetHandledLastIndexString();
while (endIndex < size) {
// a. Let setStatus be Set(splitter, "lastIndex", q, true).
lastIndexvalue.Update(JSTaggedValue(endIndex));
@ -1486,14 +1486,15 @@ JSTaggedValue BuiltinsRegExp::RegExpExec(JSThread *thread, const JSHandle<JSTagg
// 3. Let exec be Get(R, "exec").
JSHandle<EcmaString> inputStr = JSTaggedValue::ToString(thread, inputString);
JSHandle<JSTaggedValue> execHandle(thread->GlobalConstants()->GetHandledExecString());
const GlobalEnvConstants *globalConst = thread->GlobalConstants();
JSHandle<JSTaggedValue> execHandle = globalConst->GetHandledExecString();
JSHandle<JSTaggedValue> exec(
thread, FastRuntimeStub::FastGetProperty(thread, regexp.GetTaggedValue(), execHandle.GetTaggedValue()));
// 4. ReturnIfAbrupt(exec).
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// 5. If IsCallable(exec) is true, then
if (exec->IsCallable()) {
JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
JSHandle<JSTaggedValue> undefined = globalConst->GetHandledUndefined();
EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, exec, regexp, undefined, 1);
info.SetCallArg(inputStr.GetTaggedValue());
JSTaggedValue result = JSFunction::Call(&info);

View File

@ -651,17 +651,17 @@ JSTaggedValue BuiltinsString::Normalize(EcmaRuntimeCallInfo *argv)
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception());
JSHandle<EcmaString> formValue;
if (argv->GetArgsNumber() == 0) {
formValue = factory->NewFromASCII("NFC");
formValue = JSHandle<EcmaString>::Cast(thread->GlobalConstants()->GetHandledNfcString());
} else {
JSHandle<JSTaggedValue> formTag = BuiltinsString::GetCallArg(argv, 0);
if (formTag->IsUndefined()) {
formValue = factory->NewFromASCII("NFC");
formValue = JSHandle<EcmaString>::Cast(thread->GlobalConstants()->GetHandledNfcString());
} else {
formValue = JSTaggedValue::ToString(thread, formTag);
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception());
}
}
JSHandle<EcmaString> nfc = factory->NewFromASCII("NFC");
JSHandle<EcmaString> nfc = JSHandle<EcmaString>::Cast(thread->GlobalConstants()->GetHandledNfcString());
JSHandle<EcmaString> nfd = factory->NewFromASCII("NFD");
JSHandle<EcmaString> nfkc = factory->NewFromASCII("NFKC");
JSHandle<EcmaString> nfkd = factory->NewFromASCII("NFKD");
@ -884,7 +884,7 @@ JSTaggedValue BuiltinsString::GetSubstitution(JSThread *thread, const JSHandle<E
BUILTINS_API_TRACE(thread, String, GetSubstitution);
auto ecmaVm = thread->GetEcmaVM();
ObjectFactory *factory = ecmaVm->GetFactory();
JSHandle<EcmaString> dollarString = factory->NewFromASCII("$");
JSHandle<EcmaString> dollarString = JSHandle<EcmaString>::Cast(thread->GlobalConstants()->GetHandledDollarString());
int32_t replaceLength = static_cast<int32_t>(replacement->GetLength());
int32_t tailPos = position + matched->GetLength();

View File

@ -59,7 +59,7 @@ JSTaggedValue BuiltinsWeakMap::WeakMapConstructor(EcmaRuntimeCallInfo *argv)
THROW_TYPE_ERROR_AND_RETURN(thread, "iterable is not object", JSTaggedValue::Exception());
}
// Let adder be Get(weakMap, "set").
JSHandle<JSTaggedValue> adderKey(factory->NewFromASCII("set"));
JSHandle<JSTaggedValue> adderKey = thread->GlobalConstants()->GetHandledSetString();
JSHandle<JSTaggedValue> adder =
JSObject::GetProperty(thread, JSHandle<JSTaggedValue>(weakMap), adderKey).GetValue();
// ReturnIfAbrupt(adder).

View File

@ -56,7 +56,7 @@ JSTaggedValue BuiltinsWeakSet::WeakSetConstructor(EcmaRuntimeCallInfo *argv)
return weakSet.GetTaggedValue();
}
// Let adder be Get(weakset, "add").
JSHandle<JSTaggedValue> adderKey(factory->NewFromASCII("add"));
JSHandle<JSTaggedValue> adderKey = thread->GlobalConstants()->GetHandledAddString();
JSHandle<JSTaggedValue> weakSetHandle(weakSet);
JSHandle<JSTaggedValue> adder = JSObject::GetProperty(thread, weakSetHandle, adderKey).GetValue();
// ReturnIfAbrupt(adder).

View File

@ -341,7 +341,7 @@ JSHandle<JSTaggedValue> ContainersPrivate::InitializeTreeMap(JSThread *thread)
SetStringTagSymbol(thread, env, mapFuncPrototype, "TreeMap");
// %TreeMapPrototype% [ @@iterator ]
JSHandle<JSTaggedValue> iteratorSymbol = env->GetIteratorSymbol();
JSHandle<JSTaggedValue> entries(factory->NewFromASCII("entries"));
JSHandle<JSTaggedValue> entries = globalConst->GetHandledEntriesString();
JSHandle<JSTaggedValue> entriesFunc =
JSObject::GetMethod(thread, JSHandle<JSTaggedValue>::Cast(mapFuncPrototype), entries);
PropertyDescriptor descriptor(thread, entriesFunc, false, false, false);
@ -492,7 +492,7 @@ JSHandle<JSTaggedValue> ContainersPrivate::InitializePlainArray(JSThread *thread
JSHandle<JSTaggedValue> lengthGetter = CreateGetter(thread, ContainersPlainArray::GetSize, "length",
FuncLength::ZERO);
JSHandle<JSTaggedValue> lengthKey(factory->NewFromASCII("length"));
JSHandle<JSTaggedValue> lengthKey = globalConst->GetHandledLengthString();
SetGetter(thread, plainArrayFuncPrototype, lengthKey, lengthGetter);
JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
@ -554,7 +554,7 @@ JSHandle<JSTaggedValue> ContainersPrivate::InitializeStack(JSThread *thread)
SetStringTagSymbol(thread, env, stackFuncPrototype, "Stack");
JSHandle<JSTaggedValue> lengthGetter = CreateGetter(thread, ContainersStack::GetLength, "length", FuncLength::ZERO);
JSHandle<JSTaggedValue> lengthKey(factory->NewFromASCII("length"));
JSHandle<JSTaggedValue> lengthKey = globalConst->GetHandledLengthString();
SetGetter(thread, stackFuncPrototype, lengthKey, lengthGetter);
SetFunctionAtSymbol(thread, env, stackFuncPrototype, env->GetIteratorSymbol(), "[Symbol.iterator]",
@ -740,7 +740,7 @@ JSHandle<JSTaggedValue> ContainersPrivate::InitializeDeque(JSThread *thread)
SetStringTagSymbol(thread, env, dequeFuncPrototype, "Deque");
JSHandle<JSTaggedValue> lengthGetter = CreateGetter(thread, ContainersDeque::GetSize, "length", FuncLength::ZERO);
JSHandle<JSTaggedValue> lengthKey(factory->NewFromASCII("length"));
JSHandle<JSTaggedValue> lengthKey = globalConst->GetHandledLengthString();
SetGetter(thread, dequeFuncPrototype, lengthKey, lengthGetter);
SetFunctionAtSymbol(thread, env, dequeFuncPrototype, env->GetIteratorSymbol(), "[Symbol.iterator]",

View File

@ -76,6 +76,22 @@ inline EcmaString *EcmaString::CreateFromUtf8(const uint8_t *utf8Data, uint32_t
return string;
}
/* static */
inline EcmaString *EcmaString::CreateFromUtf8NonMovable(const EcmaVM *vm, const uint8_t *utf8Data, uint32_t utf8Len)
{
if (utf8Len == 0) {
return vm->GetFactory()->GetEmptyString().GetObject<EcmaString>();
}
EcmaString *string = AllocStringObjectNonMovable(vm, utf8Len);
ASSERT(string != nullptr);
if (memcpy_s(string->GetDataUtf8Writable(), utf8Len, utf8Data, utf8Len) != EOK) {
LOG_ECMA(FATAL) << "memcpy_s failed";
UNREACHABLE();
}
ASSERT_PRINT(CanBeCompressed(string) == true, "Bad input canBeCompress!");
return string;
}
inline EcmaString *EcmaString::CreateFromUtf16(const uint16_t *utf16Data, uint32_t utf16Len, const EcmaVM *vm,
bool canBeCompress)
{
@ -123,7 +139,18 @@ inline EcmaString *EcmaString::AllocStringObject(size_t length, bool compressed,
auto string = reinterpret_cast<EcmaString *>(vm->GetFactory()->AllocStringObject(size));
string->SetLength(length, compressed);
string->SetRawHashcode(0);
return reinterpret_cast<EcmaString *>(string);
return string;
}
/* static */
inline EcmaString *EcmaString::AllocStringObjectNonMovable(const EcmaVM *vm, size_t length)
{
// we only consider compressable string which is utf8 strings
size_t size = ComputeSizeUtf8(length);
auto string = reinterpret_cast<EcmaString *>(vm->GetFactory()->AllocNonMovableStringObject(size));
string->SetLength(length, true);
string->SetRawHashcode(0);
return string;
}
void EcmaString::WriteData(EcmaString *src, uint32_t start, uint32_t destSize, uint32_t length)

View File

@ -39,6 +39,7 @@ public:
static EcmaString *CreateEmptyString(const EcmaVM *vm);
static EcmaString *CreateFromUtf8(const uint8_t *utf8Data, uint32_t utf8Len, const EcmaVM *vm, bool canBeCompress);
static EcmaString *CreateFromUtf8NonMovable(const EcmaVM *vm, const uint8_t *utf8Data, uint32_t utf8Len);
static EcmaString *CreateFromUtf16(const uint16_t *utf16Data, uint32_t utf16Len, const EcmaVM *vm,
bool canBeCompress);
static EcmaString *Concat(const JSHandle<EcmaString> &str1Handle, const JSHandle<EcmaString> &str2Handle,
@ -298,6 +299,7 @@ public:
}
static EcmaString *AllocStringObject(size_t length, bool compressed, const EcmaVM *vm);
static EcmaString *AllocStringObjectNonMovable(const EcmaVM *vm, size_t length);
static bool CanBeCompressed(const uint8_t *utf8Data, uint32_t utf8Len);
static bool CanBeCompressed(const uint16_t *utf16Data, uint32_t utf16Len);

View File

@ -120,6 +120,17 @@ EcmaString *EcmaStringTable::GetOrInternString(const uint8_t *utf8Data, uint32_t
return result;
}
/*
This function is used to create global constant strings from non-movable sapce only.
It only inserts string into string-table and provides no string-table validity check.
*/
EcmaString *EcmaStringTable::CreateAndInternStringNonMovable(const uint8_t *utf8Data, uint32_t utf8Len)
{
EcmaString *result = EcmaString::CreateFromUtf8NonMovable(vm_, utf8Data, utf8Len);
InternString(result);
return result;
}
EcmaString *EcmaStringTable::GetOrInternString(const uint16_t *utf16Data, uint32_t utf16Len, bool canBeCompress)
{
EcmaString *result = GetString(utf16Data, utf16Len);
@ -164,4 +175,24 @@ void EcmaStringTable::SweepWeakReference(const WeakRootVisitor &visitor)
}
}
}
bool EcmaStringTable::CheckStringTableValidity()
{
for (auto itemOuter = table_.begin(); itemOuter != table_.end(); ++itemOuter) {
auto outerString = itemOuter->second;
int counter = 0;
auto range = table_.equal_range(outerString->GetHashcode());
auto it = range.first;
for (; it != range.second; ++it) {
auto foundString = it->second;
if (EcmaString::StringsAreEqual(foundString, outerString)) {
++counter;
}
}
if (counter > 1) {
return false;
}
}
return true;
}
} // namespace panda::ecmascript

View File

@ -34,11 +34,12 @@ public:
void InternEmptyString(EcmaString *emptyStr);
EcmaString *GetOrInternString(const JSHandle<EcmaString> &firstString, const JSHandle<EcmaString> &secondString);
EcmaString *GetOrInternString(const uint8_t *utf8Data, uint32_t utf8Len, bool canBeCompress);
EcmaString *CreateAndInternStringNonMovable(const uint8_t *utf8Data, uint32_t utf8Len);
EcmaString *GetOrInternString(const uint16_t *utf16Data, uint32_t utf16Len, bool canBeCompress);
EcmaString *GetOrInternString(EcmaString *string);
void SweepWeakReference(const WeakRootVisitor &visitor);
bool CheckStringTableValidity();
private:
NO_COPY_SEMANTIC(EcmaStringTable);
NO_MOVE_SEMANTIC(EcmaStringTable);

View File

@ -222,15 +222,15 @@ void GlobalEnvConstants::InitGlobalConstant(JSThread *thread)
{
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
[[maybe_unused]] auto test = EcmaString::Cast(GetHandledEmptyString().GetObject<EcmaString>());
SetConstant(ConstantIndex::CONSTRUCTOR_STRING_INDEX, factory->NewFromASCII("constructor"));
SetConstant(ConstantIndex::PROTOTYPE_STRING_INDEX, factory->NewFromASCII("prototype"));
SetConstant(ConstantIndex::LENGTH_STRING_INDEX, factory->NewFromASCII("length"));
SetConstant(ConstantIndex::VALUE_STRING_INDEX, factory->NewFromASCII("value"));
SetConstant(ConstantIndex::SET_STRING_INDEX, factory->NewFromASCII("set"));
SetConstant(ConstantIndex::GET_STRING_INDEX, factory->NewFromASCII("get"));
SetConstant(ConstantIndex::WRITABLE_STRING_INDEX, factory->NewFromASCII("writable"));
SetConstant(ConstantIndex::ENUMERABLE_STRING_INDEX, factory->NewFromASCII("enumerable"));
SetConstant(ConstantIndex::CONFIGURABLE_STRING_INDEX, factory->NewFromASCII("configurable"));
SetConstant(ConstantIndex::CONSTRUCTOR_STRING_INDEX, factory->NewFromASCIINonMovable("constructor"));
SetConstant(ConstantIndex::PROTOTYPE_STRING_INDEX, factory->NewFromASCIINonMovable("prototype"));
SetConstant(ConstantIndex::LENGTH_STRING_INDEX, factory->NewFromASCIINonMovable("length"));
SetConstant(ConstantIndex::VALUE_STRING_INDEX, factory->NewFromASCIINonMovable("value"));
SetConstant(ConstantIndex::SET_STRING_INDEX, factory->NewFromASCIINonMovable("set"));
SetConstant(ConstantIndex::GET_STRING_INDEX, factory->NewFromASCIINonMovable("get"));
SetConstant(ConstantIndex::WRITABLE_STRING_INDEX, factory->NewFromASCIINonMovable("writable"));
SetConstant(ConstantIndex::ENUMERABLE_STRING_INDEX, factory->NewFromASCIINonMovable("enumerable"));
SetConstant(ConstantIndex::CONFIGURABLE_STRING_INDEX, factory->NewFromASCIINonMovable("configurable"));
/* non ECMA standard jsapi containers iterators, init to Undefined first */
SetConstant(ConstantIndex::ARRAYLIST_FUNCTION_INDEX, JSTaggedValue::Undefined());
SetConstant(ConstantIndex::ARRAYLIST_ITERATOR_PROTOTYPE_INDEX, JSTaggedValue::Undefined());
@ -244,236 +244,255 @@ void GlobalEnvConstants::InitGlobalConstant(JSThread *thread)
SetConstant(ConstantIndex::VECTOR_FUNCTION_INDEX, JSTaggedValue::Undefined());
SetConstant(ConstantIndex::VECTOR_ITERATOR_PROTOTYPE_INDEX, JSTaggedValue::Undefined());
/* SymbolTable *RegisterSymbols */
SetConstant(ConstantIndex::NAME_STRING_INDEX, factory->NewFromASCII("name"));
SetConstant(ConstantIndex::GETPROTOTYPEOF_STRING_INDEX, factory->NewFromASCII("getPrototypeOf"));
SetConstant(ConstantIndex::SETPROTOTYPEOF_STRING_INDEX, factory->NewFromASCII("setPrototypeOf"));
SetConstant(ConstantIndex::ISEXTENSIBLE_STRING_INDEX, factory->NewFromASCII("isExtensible"));
SetConstant(ConstantIndex::NAME_STRING_INDEX, factory->NewFromASCIINonMovable("name"));
SetConstant(ConstantIndex::GETPROTOTYPEOF_STRING_INDEX, factory->NewFromASCIINonMovable("getPrototypeOf"));
SetConstant(ConstantIndex::SETPROTOTYPEOF_STRING_INDEX, factory->NewFromASCIINonMovable("setPrototypeOf"));
SetConstant(ConstantIndex::ISEXTENSIBLE_STRING_INDEX, factory->NewFromASCIINonMovable("isExtensible"));
SetConstant(ConstantIndex::PREVENTEXTENSIONS_STRING_INDEX,
factory->NewFromASCII("preventExtensions"));
factory->NewFromASCIINonMovable("preventExtensions"));
SetConstant(ConstantIndex::GETOWNPROPERTYDESCRIPTOR_STRING_INDEX,
factory->NewFromASCII("getOwnPropertyDescriptor"));
SetConstant(ConstantIndex::DEFINEPROPERTY_STRING_INDEX, factory->NewFromASCII("defineProperty"));
SetConstant(ConstantIndex::HAS_STRING_INDEX, factory->NewFromASCII("has"));
SetConstant(ConstantIndex::DELETEPROPERTY_STRING_INDEX, factory->NewFromASCII("deleteProperty"));
SetConstant(ConstantIndex::ENUMERATE_STRING_INDEX, factory->NewFromASCII("enumerate"));
SetConstant(ConstantIndex::OWNKEYS_STRING_INDEX, factory->NewFromASCII("ownKeys"));
SetConstant(ConstantIndex::APPLY_STRING_INDEX, factory->NewFromASCII("apply"));
SetConstant(ConstantIndex::NEGATIVE_ZERO_STRING_INDEX, factory->NewFromASCII("-0"));
SetConstant(ConstantIndex::DONE_STRING_INDEX, factory->NewFromASCII("done"));
SetConstant(ConstantIndex::PROXY_STRING_INDEX, factory->NewFromASCII("proxy"));
SetConstant(ConstantIndex::REVOKE_STRING_INDEX, factory->NewFromASCII("revoke"));
SetConstant(ConstantIndex::NEXT_STRING_INDEX, factory->NewFromASCII("next"));
SetConstant(ConstantIndex::TO_STRING_STRING_INDEX, factory->NewFromASCII("toString"));
SetConstant(ConstantIndex::TO_LOCALE_STRING_STRING_INDEX, factory->NewFromASCII("toLocaleString"));
SetConstant(ConstantIndex::VALUE_OF_STRING_INDEX, factory->NewFromASCII("valueOf"));
SetConstant(ConstantIndex::UNDEFINED_STRING_INDEX, factory->NewFromASCII("undefined"));
SetConstant(ConstantIndex::NULL_STRING_INDEX, factory->NewFromASCII("null"));
SetConstant(ConstantIndex::BOOLEAN_STRING_INDEX, factory->NewFromASCII("boolean"));
SetConstant(ConstantIndex::NUMBER_STRING_INDEX, factory->NewFromASCII("number"));
SetConstant(ConstantIndex::BIGINT_STRING_INDEX, factory->NewFromASCII("bigint"));
SetConstant(ConstantIndex::FUNCTION_STRING_INDEX, factory->NewFromASCII("function"));
SetConstant(ConstantIndex::STRING_STRING_INDEX, factory->NewFromASCII("string"));
SetConstant(ConstantIndex::SYMBOL_STRING_INDEX, factory->NewFromASCII("symbol"));
SetConstant(ConstantIndex::OBJECT_STRING_INDEX, factory->NewFromASCII("object"));
SetConstant(ConstantIndex::TRUE_STRING_INDEX, factory->NewFromASCII("true"));
SetConstant(ConstantIndex::FALSE_STRING_INDEX, factory->NewFromASCII("false"));
SetConstant(ConstantIndex::RETURN_STRING_INDEX, factory->NewFromASCII("return"));
SetConstant(ConstantIndex::PROXY_CONSTRUCT_STRING_INDEX, factory->NewFromASCII("construct"));
SetConstant(ConstantIndex::PROXY_CALL_STRING_INDEX, factory->NewFromASCII("call"));
SetConstant(ConstantIndex::PROMISE_THEN_STRING_INDEX, factory->NewFromASCII("then"));
SetConstant(ConstantIndex::PROMISE_CATCH_STRING_INDEX, factory->NewFromASCII("catch"));
SetConstant(ConstantIndex::SCRIPT_JOB_STRING_INDEX, factory->NewFromASCII("ScriptJobs"));
SetConstant(ConstantIndex::PROMISE_STRING_INDEX, factory->NewFromASCII("PrimiseJobs"));
SetConstant(ConstantIndex::THROWER_STRING_INDEX, factory->NewFromASCII("Thrower"));
SetConstant(ConstantIndex::IDENTITY_STRING_INDEX, factory->NewFromASCII("Identity"));
SetConstant(ConstantIndex::CALLER_STRING_INDEX, factory->NewFromASCII("caller"));
SetConstant(ConstantIndex::CALLEE_STRING_INDEX, factory->NewFromASCII("callee"));
SetConstant(ConstantIndex::INT8_ARRAY_STRING_INDEX, factory->NewFromASCII("Int8Array"));
SetConstant(ConstantIndex::UINT8_ARRAY_STRING_INDEX, factory->NewFromASCII("Uint8Array"));
factory->NewFromASCIINonMovable("getOwnPropertyDescriptor"));
SetConstant(ConstantIndex::DEFINEPROPERTY_STRING_INDEX, factory->NewFromASCIINonMovable("defineProperty"));
SetConstant(ConstantIndex::HAS_STRING_INDEX, factory->NewFromASCIINonMovable("has"));
SetConstant(ConstantIndex::DELETEPROPERTY_STRING_INDEX, factory->NewFromASCIINonMovable("deleteProperty"));
SetConstant(ConstantIndex::ENUMERATE_STRING_INDEX, factory->NewFromASCIINonMovable("enumerate"));
SetConstant(ConstantIndex::OWNKEYS_STRING_INDEX, factory->NewFromASCIINonMovable("ownKeys"));
SetConstant(ConstantIndex::APPLY_STRING_INDEX, factory->NewFromASCIINonMovable("apply"));
SetConstant(ConstantIndex::NEGATIVE_ZERO_STRING_INDEX, factory->NewFromASCIINonMovable("-0"));
SetConstant(ConstantIndex::DONE_STRING_INDEX, factory->NewFromASCIINonMovable("done"));
SetConstant(ConstantIndex::PROXY_STRING_INDEX, factory->NewFromASCIINonMovable("proxy"));
SetConstant(ConstantIndex::REVOKE_STRING_INDEX, factory->NewFromASCIINonMovable("revoke"));
SetConstant(ConstantIndex::NEXT_STRING_INDEX, factory->NewFromASCIINonMovable("next"));
SetConstant(ConstantIndex::TO_STRING_STRING_INDEX, factory->NewFromASCIINonMovable("toString"));
SetConstant(ConstantIndex::TO_LOCALE_STRING_STRING_INDEX, factory->NewFromASCIINonMovable("toLocaleString"));
SetConstant(ConstantIndex::VALUE_OF_STRING_INDEX, factory->NewFromASCIINonMovable("valueOf"));
SetConstant(ConstantIndex::UNDEFINED_STRING_INDEX, factory->NewFromASCIINonMovable("undefined"));
SetConstant(ConstantIndex::NULL_STRING_INDEX, factory->NewFromASCIINonMovable("null"));
SetConstant(ConstantIndex::BOOLEAN_STRING_INDEX, factory->NewFromASCIINonMovable("boolean"));
SetConstant(ConstantIndex::NUMBER_STRING_INDEX, factory->NewFromASCIINonMovable("number"));
SetConstant(ConstantIndex::BIGINT_STRING_INDEX, factory->NewFromASCIINonMovable("bigint"));
SetConstant(ConstantIndex::FUNCTION_STRING_INDEX, factory->NewFromASCIINonMovable("function"));
SetConstant(ConstantIndex::STRING_STRING_INDEX, factory->NewFromASCIINonMovable("string"));
SetConstant(ConstantIndex::SYMBOL_STRING_INDEX, factory->NewFromASCIINonMovable("symbol"));
SetConstant(ConstantIndex::OBJECT_STRING_INDEX, factory->NewFromASCIINonMovable("object"));
SetConstant(ConstantIndex::TRUE_STRING_INDEX, factory->NewFromASCIINonMovable("true"));
SetConstant(ConstantIndex::FALSE_STRING_INDEX, factory->NewFromASCIINonMovable("false"));
SetConstant(ConstantIndex::RETURN_STRING_INDEX, factory->NewFromASCIINonMovable("return"));
SetConstant(ConstantIndex::PROXY_CONSTRUCT_STRING_INDEX, factory->NewFromASCIINonMovable("construct"));
SetConstant(ConstantIndex::PROXY_CALL_STRING_INDEX, factory->NewFromASCIINonMovable("call"));
SetConstant(ConstantIndex::PROMISE_THEN_STRING_INDEX, factory->NewFromASCIINonMovable("then"));
SetConstant(ConstantIndex::PROMISE_CATCH_STRING_INDEX, factory->NewFromASCIINonMovable("catch"));
SetConstant(ConstantIndex::SCRIPT_JOB_STRING_INDEX, factory->NewFromASCIINonMovable("ScriptJobs"));
SetConstant(ConstantIndex::PROMISE_STRING_INDEX, factory->NewFromASCIINonMovable("PrimiseJobs"));
SetConstant(ConstantIndex::THROWER_STRING_INDEX, factory->NewFromASCIINonMovable("Thrower"));
SetConstant(ConstantIndex::IDENTITY_STRING_INDEX, factory->NewFromASCIINonMovable("Identity"));
SetConstant(ConstantIndex::CALLER_STRING_INDEX, factory->NewFromASCIINonMovable("caller"));
SetConstant(ConstantIndex::CALLEE_STRING_INDEX, factory->NewFromASCIINonMovable("callee"));
SetConstant(ConstantIndex::INT8_ARRAY_STRING_INDEX, factory->NewFromASCIINonMovable("Int8Array"));
SetConstant(ConstantIndex::UINT8_ARRAY_STRING_INDEX, factory->NewFromASCIINonMovable("Uint8Array"));
SetConstant(ConstantIndex::UINT8_CLAMPED_ARRAY_STRING_INDEX,
factory->NewFromASCII("Uint8ClampedArray"));
SetConstant(ConstantIndex::INT16_ARRAY_STRING_INDEX, factory->NewFromASCII("Int16Array"));
SetConstant(ConstantIndex::UINT16_ARRAY_STRING_INDEX, factory->NewFromASCII("Uint16Array"));
SetConstant(ConstantIndex::INT32_ARRAY_STRING_INDEX, factory->NewFromASCII("Int32Array"));
SetConstant(ConstantIndex::UINT32_ARRAY_STRING_INDEX, factory->NewFromASCII("Uint32Array"));
SetConstant(ConstantIndex::FLOAT32_ARRAY_STRING_INDEX, factory->NewFromASCII("Float32Array"));
SetConstant(ConstantIndex::FLOAT64_ARRAY_STRING_INDEX, factory->NewFromASCII("Float64Array"));
SetConstant(ConstantIndex::BIGINT64_ARRAY_STRING_INDEX, factory->NewFromASCII("BigInt64Array"));
SetConstant(ConstantIndex::BIGUINT64_ARRAY_STRING_INDEX, factory->NewFromASCII("BigUint64Array"));
SetConstant(ConstantIndex::ASYNC_FUNCTION_STRING_INDEX, factory->NewFromASCII("AsyncFunction"));
SetConstant(ConstantIndex::PROMISE_RESOLVE_STRING_INDEX, factory->NewFromASCII("resolve"));
SetConstant(ConstantIndex::ID_STRING_INDEX, factory->NewFromASCII("id"));
SetConstant(ConstantIndex::METHOD_STRING_INDEX, factory->NewFromASCII("method"));
SetConstant(ConstantIndex::PARAMS_STRING_INDEX, factory->NewFromASCII("params"));
SetConstant(ConstantIndex::RESULT_STRING_INDEX, factory->NewFromASCII("result"));
SetConstant(ConstantIndex::TO_JSON_STRING_INDEX, factory->NewFromASCII("toJSON"));
SetConstant(ConstantIndex::GLOBAL_STRING_INDEX, factory->NewFromASCII("global"));
SetConstant(ConstantIndex::MESSAGE_STRING_INDEX, factory->NewFromASCII("message"));
SetConstant(ConstantIndex::ERROR_STRING_INDEX, factory->NewFromASCII("Error"));
SetConstant(ConstantIndex::RANGE_ERROR_STRING_INDEX, factory->NewFromASCII("RangeError"));
SetConstant(ConstantIndex::REFERENCE_ERROR_STRING_INDEX, factory->NewFromASCII("ReferenceError"));
SetConstant(ConstantIndex::TYPE_ERROR_STRING_INDEX, factory->NewFromASCII("TypeError"));
SetConstant(ConstantIndex::URI_ERROR_STRING_INDEX, factory->NewFromASCII("URIError"));
SetConstant(ConstantIndex::SYNTAX_ERROR_STRING_INDEX, factory->NewFromASCII("SyntaxError"));
SetConstant(ConstantIndex::EVAL_ERROR_STRING_INDEX, factory->NewFromASCII("EvalError"));
SetConstant(ConstantIndex::STACK_STRING_INDEX, factory->NewFromASCII("stack"));
SetConstant(ConstantIndex::STACK_EMPTY_STRING_INDEX, factory->NewFromASCII("stackisempty"));
factory->NewFromASCIINonMovable("Uint8ClampedArray"));
SetConstant(ConstantIndex::INT16_ARRAY_STRING_INDEX, factory->NewFromASCIINonMovable("Int16Array"));
SetConstant(ConstantIndex::UINT16_ARRAY_STRING_INDEX, factory->NewFromASCIINonMovable("Uint16Array"));
SetConstant(ConstantIndex::INT32_ARRAY_STRING_INDEX, factory->NewFromASCIINonMovable("Int32Array"));
SetConstant(ConstantIndex::UINT32_ARRAY_STRING_INDEX, factory->NewFromASCIINonMovable("Uint32Array"));
SetConstant(ConstantIndex::FLOAT32_ARRAY_STRING_INDEX, factory->NewFromASCIINonMovable("Float32Array"));
SetConstant(ConstantIndex::FLOAT64_ARRAY_STRING_INDEX, factory->NewFromASCIINonMovable("Float64Array"));
SetConstant(ConstantIndex::BIGINT64_ARRAY_STRING_INDEX, factory->NewFromASCIINonMovable("BigInt64Array"));
SetConstant(ConstantIndex::BIGUINT64_ARRAY_STRING_INDEX, factory->NewFromASCIINonMovable("BigUint64Array"));
SetConstant(ConstantIndex::ASYNC_FUNCTION_STRING_INDEX, factory->NewFromASCIINonMovable("AsyncFunction"));
SetConstant(ConstantIndex::PROMISE_RESOLVE_STRING_INDEX, factory->NewFromASCIINonMovable("resolve"));
SetConstant(ConstantIndex::ID_STRING_INDEX, factory->NewFromASCIINonMovable("id"));
SetConstant(ConstantIndex::METHOD_STRING_INDEX, factory->NewFromASCIINonMovable("method"));
SetConstant(ConstantIndex::PARAMS_STRING_INDEX, factory->NewFromASCIINonMovable("params"));
SetConstant(ConstantIndex::RESULT_STRING_INDEX, factory->NewFromASCIINonMovable("result"));
SetConstant(ConstantIndex::TO_JSON_STRING_INDEX, factory->NewFromASCIINonMovable("toJSON"));
SetConstant(ConstantIndex::GLOBAL_STRING_INDEX, factory->NewFromASCIINonMovable("global"));
SetConstant(ConstantIndex::MESSAGE_STRING_INDEX, factory->NewFromASCIINonMovable("message"));
SetConstant(ConstantIndex::ERROR_STRING_INDEX, factory->NewFromASCIINonMovable("Error"));
SetConstant(ConstantIndex::RANGE_ERROR_STRING_INDEX, factory->NewFromASCIINonMovable("RangeError"));
SetConstant(ConstantIndex::REFERENCE_ERROR_STRING_INDEX, factory->NewFromASCIINonMovable("ReferenceError"));
SetConstant(ConstantIndex::TYPE_ERROR_STRING_INDEX, factory->NewFromASCIINonMovable("TypeError"));
SetConstant(ConstantIndex::URI_ERROR_STRING_INDEX, factory->NewFromASCIINonMovable("URIError"));
SetConstant(ConstantIndex::SYNTAX_ERROR_STRING_INDEX, factory->NewFromASCIINonMovable("SyntaxError"));
SetConstant(ConstantIndex::EVAL_ERROR_STRING_INDEX, factory->NewFromASCIINonMovable("EvalError"));
SetConstant(ConstantIndex::STACK_STRING_INDEX, factory->NewFromASCIINonMovable("stack"));
SetConstant(ConstantIndex::STACK_EMPTY_STRING_INDEX, factory->NewFromASCIINonMovable("stackisempty"));
SetConstant(ConstantIndex::OBJ_NOT_COERCIBLE_STRING_INDEX,
factory->NewFromASCII("objectnotcoercible"));
factory->NewFromASCIINonMovable("objectnotcoercible"));
/* for Intl. */
SetConstant(ConstantIndex::LANGUAGE_STRING_CLASS_INDEX, factory->NewFromASCII("language"));
SetConstant(ConstantIndex::SCRIPT_STRING_CLASS_INDEX, factory->NewFromASCII("script"));
SetConstant(ConstantIndex::REGION_STRING_CLASS_INDEX, factory->NewFromASCII("region"));
SetConstant(ConstantIndex::BASE_NAME_STRING_CLASS_INDEX, factory->NewFromASCII("baseName"));
SetConstant(ConstantIndex::CALENDAR_STRING_CLASS_INDEX, factory->NewFromASCII("calendar"));
SetConstant(ConstantIndex::COLLATION_STRING_CLASS_INDEX, factory->NewFromASCII("collation"));
SetConstant(ConstantIndex::HOUR_CYCLE_STRING_CLASS_INDEX, factory->NewFromASCII("hourCycle"));
SetConstant(ConstantIndex::CASE_FIRST_STRING_CLASS_INDEX, factory->NewFromASCII("caseFirst"));
SetConstant(ConstantIndex::NUMERIC_STRING_CLASS_INDEX, factory->NewFromASCII("numeric"));
SetConstant(ConstantIndex::LANGUAGE_STRING_CLASS_INDEX, factory->NewFromASCIINonMovable("language"));
SetConstant(ConstantIndex::SCRIPT_STRING_CLASS_INDEX, factory->NewFromASCIINonMovable("script"));
SetConstant(ConstantIndex::REGION_STRING_CLASS_INDEX, factory->NewFromASCIINonMovable("region"));
SetConstant(ConstantIndex::BASE_NAME_STRING_CLASS_INDEX, factory->NewFromASCIINonMovable("baseName"));
SetConstant(ConstantIndex::CALENDAR_STRING_CLASS_INDEX, factory->NewFromASCIINonMovable("calendar"));
SetConstant(ConstantIndex::COLLATION_STRING_CLASS_INDEX, factory->NewFromASCIINonMovable("collation"));
SetConstant(ConstantIndex::HOUR_CYCLE_STRING_CLASS_INDEX, factory->NewFromASCIINonMovable("hourCycle"));
SetConstant(ConstantIndex::CASE_FIRST_STRING_CLASS_INDEX, factory->NewFromASCIINonMovable("caseFirst"));
SetConstant(ConstantIndex::NUMERIC_STRING_CLASS_INDEX, factory->NewFromASCIINonMovable("numeric"));
SetConstant(ConstantIndex::NUMBERING_SYSTEM_STRING_CLASS_INDEX,
factory->NewFromASCII("numberingSystem"));
SetConstant(ConstantIndex::TYPE_STRING_INDEX, factory->NewFromASCII("type"));
SetConstant(ConstantIndex::LOCALE_MATCHER_STRING_INDEX, factory->NewFromASCII("localeMatcher"));
SetConstant(ConstantIndex::FORMAT_MATCHER_STRING_INDEX, factory->NewFromASCII("formatMatcher"));
SetConstant(ConstantIndex::HOUR12_STRING_INDEX, factory->NewFromASCII("hour12"));
SetConstant(ConstantIndex::H11_STRING_INDEX, factory->NewFromASCII("h11"));
SetConstant(ConstantIndex::H12_STRING_INDEX, factory->NewFromASCII("h12"));
SetConstant(ConstantIndex::H23_STRING_INDEX, factory->NewFromASCII("h23"));
SetConstant(ConstantIndex::H24_STRING_INDEX, factory->NewFromASCII("h24"));
SetConstant(ConstantIndex::WEEK_DAY_STRING_INDEX, factory->NewFromASCII("weekday"));
SetConstant(ConstantIndex::ERA_STRING_INDEX, factory->NewFromASCII("era"));
SetConstant(ConstantIndex::YEAR_STRING_INDEX, factory->NewFromASCII("year"));
SetConstant(ConstantIndex::QUARTER_STRING_INDEX, factory->NewFromASCII("quarter"));
SetConstant(ConstantIndex::MONTH_STRING_INDEX, factory->NewFromASCII("month"));
SetConstant(ConstantIndex::DAY_STRING_INDEX, factory->NewFromASCII("day"));
SetConstant(ConstantIndex::HOUR_STRING_INDEX, factory->NewFromASCII("hour"));
SetConstant(ConstantIndex::MINUTE_STRING_INDEX, factory->NewFromASCII("minute"));
SetConstant(ConstantIndex::SECOND_STRING_INDEX, factory->NewFromASCII("second"));
SetConstant(ConstantIndex::YEARS_STRING_INDEX, factory->NewFromASCII("years"));
SetConstant(ConstantIndex::QUARTERS_STRING_INDEX, factory->NewFromASCII("quarters"));
SetConstant(ConstantIndex::MONTHS_STRING_INDEX, factory->NewFromASCII("months"));
SetConstant(ConstantIndex::DAYS_STRING_INDEX, factory->NewFromASCII("days"));
SetConstant(ConstantIndex::HOURS_STRING_INDEX, factory->NewFromASCII("hours"));
SetConstant(ConstantIndex::MINUTES_STRING_INDEX, factory->NewFromASCII("minutes"));
SetConstant(ConstantIndex::SECONDS_STRING_INDEX, factory->NewFromASCII("seconds"));
SetConstant(ConstantIndex::TIME_ZONE_NAME_STRING_INDEX, factory->NewFromASCII("timeZoneName"));
SetConstant(ConstantIndex::LOCALE_STRING_INDEX, factory->NewFromASCII("locale"));
SetConstant(ConstantIndex::TIME_ZONE_STRING_INDEX, factory->NewFromASCII("timeZone"));
SetConstant(ConstantIndex::LITERAL_STRING_INDEX, factory->NewFromASCII("literal"));
SetConstant(ConstantIndex::YEAR_NAME_STRING_INDEX, factory->NewFromASCII("yearName"));
SetConstant(ConstantIndex::DAY_PERIOD_STRING_INDEX, factory->NewFromASCII("dayPeriod"));
factory->NewFromASCIINonMovable("numberingSystem"));
SetConstant(ConstantIndex::TYPE_STRING_INDEX, factory->NewFromASCIINonMovable("type"));
SetConstant(ConstantIndex::LOCALE_MATCHER_STRING_INDEX, factory->NewFromASCIINonMovable("localeMatcher"));
SetConstant(ConstantIndex::FORMAT_MATCHER_STRING_INDEX, factory->NewFromASCIINonMovable("formatMatcher"));
SetConstant(ConstantIndex::HOUR12_STRING_INDEX, factory->NewFromASCIINonMovable("hour12"));
SetConstant(ConstantIndex::H11_STRING_INDEX, factory->NewFromASCIINonMovable("h11"));
SetConstant(ConstantIndex::H12_STRING_INDEX, factory->NewFromASCIINonMovable("h12"));
SetConstant(ConstantIndex::H23_STRING_INDEX, factory->NewFromASCIINonMovable("h23"));
SetConstant(ConstantIndex::H24_STRING_INDEX, factory->NewFromASCIINonMovable("h24"));
SetConstant(ConstantIndex::WEEK_DAY_STRING_INDEX, factory->NewFromASCIINonMovable("weekday"));
SetConstant(ConstantIndex::ERA_STRING_INDEX, factory->NewFromASCIINonMovable("era"));
SetConstant(ConstantIndex::YEAR_STRING_INDEX, factory->NewFromASCIINonMovable("year"));
SetConstant(ConstantIndex::QUARTER_STRING_INDEX, factory->NewFromASCIINonMovable("quarter"));
SetConstant(ConstantIndex::MONTH_STRING_INDEX, factory->NewFromASCIINonMovable("month"));
SetConstant(ConstantIndex::DAY_STRING_INDEX, factory->NewFromASCIINonMovable("day"));
SetConstant(ConstantIndex::HOUR_STRING_INDEX, factory->NewFromASCIINonMovable("hour"));
SetConstant(ConstantIndex::MINUTE_STRING_INDEX, factory->NewFromASCIINonMovable("minute"));
SetConstant(ConstantIndex::SECOND_STRING_INDEX, factory->NewFromASCIINonMovable("second"));
SetConstant(ConstantIndex::YEARS_STRING_INDEX, factory->NewFromASCIINonMovable("years"));
SetConstant(ConstantIndex::QUARTERS_STRING_INDEX, factory->NewFromASCIINonMovable("quarters"));
SetConstant(ConstantIndex::MONTHS_STRING_INDEX, factory->NewFromASCIINonMovable("months"));
SetConstant(ConstantIndex::DAYS_STRING_INDEX, factory->NewFromASCIINonMovable("days"));
SetConstant(ConstantIndex::HOURS_STRING_INDEX, factory->NewFromASCIINonMovable("hours"));
SetConstant(ConstantIndex::MINUTES_STRING_INDEX, factory->NewFromASCIINonMovable("minutes"));
SetConstant(ConstantIndex::SECONDS_STRING_INDEX, factory->NewFromASCIINonMovable("seconds"));
SetConstant(ConstantIndex::TIME_ZONE_NAME_STRING_INDEX, factory->NewFromASCIINonMovable("timeZoneName"));
SetConstant(ConstantIndex::LOCALE_STRING_INDEX, factory->NewFromASCIINonMovable("locale"));
SetConstant(ConstantIndex::TIME_ZONE_STRING_INDEX, factory->NewFromASCIINonMovable("timeZone"));
SetConstant(ConstantIndex::LITERAL_STRING_INDEX, factory->NewFromASCIINonMovable("literal"));
SetConstant(ConstantIndex::YEAR_NAME_STRING_INDEX, factory->NewFromASCIINonMovable("yearName"));
SetConstant(ConstantIndex::DAY_PERIOD_STRING_INDEX, factory->NewFromASCIINonMovable("dayPeriod"));
SetConstant(ConstantIndex::FRACTIONAL_SECOND_DIGITS_STRING_INDEX,
factory->NewFromASCII("fractionalSecondDigits"));
SetConstant(ConstantIndex::FRACTIONAL_SECOND_STRING_INDEX, factory->NewFromASCII("fractionalSecond"));
SetConstant(ConstantIndex::RELATED_YEAR_STRING_INDEX, factory->NewFromASCII("relatedYear"));
SetConstant(ConstantIndex::LOOK_UP_STRING_INDEX, factory->NewFromASCII("lookup"));
SetConstant(ConstantIndex::BEST_FIT_STRING_INDEX, factory->NewFromASCII("bestfit"));
SetConstant(ConstantIndex::DATE_STYLE_STRING_INDEX, factory->NewFromASCII("dateStyle"));
SetConstant(ConstantIndex::TIME_STYLE_STRING_INDEX, factory->NewFromASCII("timeStyle"));
SetConstant(ConstantIndex::UTC_STRING_INDEX, factory->NewFromASCII("UTC"));
SetConstant(ConstantIndex::INITIALIZED_RELATIVE_INDEX, factory->NewFromASCII("true"));
SetConstant(ConstantIndex::WEEK_STRING_INDEX, factory->NewFromASCII("week"));
SetConstant(ConstantIndex::WEEKS_STRING_INDEX, factory->NewFromASCII("weeks"));
SetConstant(ConstantIndex::SOURCE_STRING_INDEX, factory->NewFromASCII("source"));
SetConstant(ConstantIndex::FORMAT_STRING_INDEX, factory->NewFromASCII("format"));
SetConstant(ConstantIndex::EN_US_STRING_INDEX, factory->NewFromASCII("en-US"));
SetConstant(ConstantIndex::UND_STRING_INDEX, factory->NewFromASCII("und"));
SetConstant(ConstantIndex::LATN_STRING_INDEX, factory->NewFromASCII("latn"));
SetConstant(ConstantIndex::STYLE_STRING_INDEX, factory->NewFromASCII("style"));
SetConstant(ConstantIndex::UNIT_STRING_INDEX, factory->NewFromASCII("unit"));
SetConstant(ConstantIndex::INTEGER_STRING_INDEX, factory->NewFromASCII("integer"));
SetConstant(ConstantIndex::NAN_STRING_INDEX, factory->NewFromASCII("nan"));
SetConstant(ConstantIndex::INFINITY_STRING_INDEX, factory->NewFromASCII("infinity"));
SetConstant(ConstantIndex::FRACTION_STRING_INDEX, factory->NewFromASCII("fraction"));
SetConstant(ConstantIndex::DECIMAL_STRING_INDEX, factory->NewFromASCII("decimal"));
SetConstant(ConstantIndex::GROUP_STRING_INDEX, factory->NewFromASCII("group"));
SetConstant(ConstantIndex::CURRENCY_STRING_INDEX, factory->NewFromASCII("currency"));
SetConstant(ConstantIndex::CURRENCY_SIGN_STRING_INDEX, factory->NewFromASCII("currencySign"));
SetConstant(ConstantIndex::CURRENCY_DISPLAY_STRING_INDEX, factory->NewFromASCII("currencyDisplay"));
SetConstant(ConstantIndex::PERCENT_SIGN_STRING_INDEX, factory->NewFromASCII("percentSign"));
SetConstant(ConstantIndex::PERCENT_STRING_INDEX, factory->NewFromASCII("percent"));
SetConstant(ConstantIndex::MINUS_SIGN_STRING_INDEX, factory->NewFromASCII("minusSign"));
SetConstant(ConstantIndex::PLUS_SIGN_STRING_INDEX, factory->NewFromASCII("plusSign"));
factory->NewFromASCIINonMovable("fractionalSecondDigits"));
SetConstant(ConstantIndex::FRACTIONAL_SECOND_STRING_INDEX, factory->NewFromASCIINonMovable("fractionalSecond"));
SetConstant(ConstantIndex::RELATED_YEAR_STRING_INDEX, factory->NewFromASCIINonMovable("relatedYear"));
SetConstant(ConstantIndex::LOOK_UP_STRING_INDEX, factory->NewFromASCIINonMovable("lookup"));
SetConstant(ConstantIndex::BEST_FIT_STRING_INDEX, factory->NewFromASCIINonMovable("bestfit"));
SetConstant(ConstantIndex::DATE_STYLE_STRING_INDEX, factory->NewFromASCIINonMovable("dateStyle"));
SetConstant(ConstantIndex::TIME_STYLE_STRING_INDEX, factory->NewFromASCIINonMovable("timeStyle"));
SetConstant(ConstantIndex::UTC_STRING_INDEX, factory->NewFromASCIINonMovable("UTC"));
SetConstant(ConstantIndex::WEEK_STRING_INDEX, factory->NewFromASCIINonMovable("week"));
SetConstant(ConstantIndex::WEEKS_STRING_INDEX, factory->NewFromASCIINonMovable("weeks"));
SetConstant(ConstantIndex::SOURCE_STRING_INDEX, factory->NewFromASCIINonMovable("source"));
SetConstant(ConstantIndex::FORMAT_STRING_INDEX, factory->NewFromASCIINonMovable("format"));
SetConstant(ConstantIndex::EN_US_STRING_INDEX, factory->NewFromASCIINonMovable("en-US"));
SetConstant(ConstantIndex::UND_STRING_INDEX, factory->NewFromASCIINonMovable("und"));
SetConstant(ConstantIndex::LATN_STRING_INDEX, factory->NewFromASCIINonMovable("latn"));
SetConstant(ConstantIndex::STYLE_STRING_INDEX, factory->NewFromASCIINonMovable("style"));
SetConstant(ConstantIndex::UNIT_STRING_INDEX, factory->NewFromASCIINonMovable("unit"));
SetConstant(ConstantIndex::INTEGER_STRING_INDEX, factory->NewFromASCIINonMovable("integer"));
SetConstant(ConstantIndex::NAN_STRING_INDEX, factory->NewFromASCIINonMovable("nan"));
SetConstant(ConstantIndex::INFINITY_STRING_INDEX, factory->NewFromASCIINonMovable("infinity"));
SetConstant(ConstantIndex::FRACTION_STRING_INDEX, factory->NewFromASCIINonMovable("fraction"));
SetConstant(ConstantIndex::DECIMAL_STRING_INDEX, factory->NewFromASCIINonMovable("decimal"));
SetConstant(ConstantIndex::GROUP_STRING_INDEX, factory->NewFromASCIINonMovable("group"));
SetConstant(ConstantIndex::CURRENCY_STRING_INDEX, factory->NewFromASCIINonMovable("currency"));
SetConstant(ConstantIndex::CURRENCY_SIGN_STRING_INDEX, factory->NewFromASCIINonMovable("currencySign"));
SetConstant(ConstantIndex::CURRENCY_DISPLAY_STRING_INDEX, factory->NewFromASCIINonMovable("currencyDisplay"));
SetConstant(ConstantIndex::PERCENT_SIGN_STRING_INDEX, factory->NewFromASCIINonMovable("percentSign"));
SetConstant(ConstantIndex::PERCENT_STRING_INDEX, factory->NewFromASCIINonMovable("percent"));
SetConstant(ConstantIndex::MINUS_SIGN_STRING_INDEX, factory->NewFromASCIINonMovable("minusSign"));
SetConstant(ConstantIndex::PLUS_SIGN_STRING_INDEX, factory->NewFromASCIINonMovable("plusSign"));
SetConstant(ConstantIndex::EXPONENT_SEPARATOR_STRING_INDEX,
factory->NewFromASCII("exponentSeparator"));
SetConstant(ConstantIndex::EXPONENT_MINUS_SIGN_INDEX, factory->NewFromASCII("exponentMinusSign"));
SetConstant(ConstantIndex::EXPONENT_INTEGER_STRING_INDEX, factory->NewFromASCII("exponentInteger"));
SetConstant(ConstantIndex::LONG_STRING_INDEX, factory->NewFromASCII("long"));
SetConstant(ConstantIndex::SHORT_STRING_INDEX, factory->NewFromASCII("short"));
SetConstant(ConstantIndex::FULL_STRING_INDEX, factory->NewFromASCII("full"));
SetConstant(ConstantIndex::MEDIUM_STRING_INDEX, factory->NewFromASCII("medium"));
SetConstant(ConstantIndex::NARROW_STRING_INDEX, factory->NewFromASCII("narrow"));
SetConstant(ConstantIndex::ALWAYS_STRING_INDEX, factory->NewFromASCII("always"));
SetConstant(ConstantIndex::AUTO_STRING_INDEX, factory->NewFromASCII("auto"));
SetConstant(ConstantIndex::UNIT_DISPLAY_INDEX, factory->NewFromASCII("unitDisplay"));
SetConstant(ConstantIndex::NOTATION_INDEX, factory->NewFromASCII("notation"));
SetConstant(ConstantIndex::COMPACT_DISPALY_INDEX, factory->NewFromASCII("compactDisplay"));
SetConstant(ConstantIndex::USER_GROUPING_INDEX, factory->NewFromASCII("useGrouping"));
SetConstant(ConstantIndex::SIGN_DISPLAY_INDEX, factory->NewFromASCII("signDisplay"));
SetConstant(ConstantIndex::CODE_INDEX, factory->NewFromASCII("code"));
SetConstant(ConstantIndex::NARROW_SYMBOL_INDEX, factory->NewFromASCII("narrowSymbol"));
SetConstant(ConstantIndex::STANDARD_INDEX, factory->NewFromASCII("standard"));
SetConstant(ConstantIndex::ACCOUNTING_INDEX, factory->NewFromASCII("accounting"));
SetConstant(ConstantIndex::SCIENTIFIC_INDEX, factory->NewFromASCII("scientific"));
SetConstant(ConstantIndex::ENGINEERING_INDEX, factory->NewFromASCII("engineering"));
SetConstant(ConstantIndex::COMPACT_STRING_INDEX, factory->NewFromASCII("compact"));
SetConstant(ConstantIndex::NEVER_INDEX, factory->NewFromASCII("never"));
SetConstant(ConstantIndex::EXPECT_ZERO_INDEX, factory->NewFromASCII("exceptZero"));
factory->NewFromASCIINonMovable("exponentSeparator"));
SetConstant(ConstantIndex::EXPONENT_MINUS_SIGN_INDEX, factory->NewFromASCIINonMovable("exponentMinusSign"));
SetConstant(ConstantIndex::EXPONENT_INTEGER_STRING_INDEX, factory->NewFromASCIINonMovable("exponentInteger"));
SetConstant(ConstantIndex::LONG_STRING_INDEX, factory->NewFromASCIINonMovable("long"));
SetConstant(ConstantIndex::SHORT_STRING_INDEX, factory->NewFromASCIINonMovable("short"));
SetConstant(ConstantIndex::FULL_STRING_INDEX, factory->NewFromASCIINonMovable("full"));
SetConstant(ConstantIndex::MEDIUM_STRING_INDEX, factory->NewFromASCIINonMovable("medium"));
SetConstant(ConstantIndex::NARROW_STRING_INDEX, factory->NewFromASCIINonMovable("narrow"));
SetConstant(ConstantIndex::ALWAYS_STRING_INDEX, factory->NewFromASCIINonMovable("always"));
SetConstant(ConstantIndex::AUTO_STRING_INDEX, factory->NewFromASCIINonMovable("auto"));
SetConstant(ConstantIndex::UNIT_DISPLAY_INDEX, factory->NewFromASCIINonMovable("unitDisplay"));
SetConstant(ConstantIndex::NOTATION_INDEX, factory->NewFromASCIINonMovable("notation"));
SetConstant(ConstantIndex::COMPACT_DISPALY_INDEX, factory->NewFromASCIINonMovable("compactDisplay"));
SetConstant(ConstantIndex::USER_GROUPING_INDEX, factory->NewFromASCIINonMovable("useGrouping"));
SetConstant(ConstantIndex::SIGN_DISPLAY_INDEX, factory->NewFromASCIINonMovable("signDisplay"));
SetConstant(ConstantIndex::CODE_INDEX, factory->NewFromASCIINonMovable("code"));
SetConstant(ConstantIndex::NARROW_SYMBOL_INDEX, factory->NewFromASCIINonMovable("narrowSymbol"));
SetConstant(ConstantIndex::STANDARD_INDEX, factory->NewFromASCIINonMovable("standard"));
SetConstant(ConstantIndex::ACCOUNTING_INDEX, factory->NewFromASCIINonMovable("accounting"));
SetConstant(ConstantIndex::SCIENTIFIC_INDEX, factory->NewFromASCIINonMovable("scientific"));
SetConstant(ConstantIndex::ENGINEERING_INDEX, factory->NewFromASCIINonMovable("engineering"));
SetConstant(ConstantIndex::COMPACT_STRING_INDEX, factory->NewFromASCIINonMovable("compact"));
SetConstant(ConstantIndex::NEVER_INDEX, factory->NewFromASCIINonMovable("never"));
SetConstant(ConstantIndex::EXPECT_ZERO_INDEX, factory->NewFromASCIINonMovable("exceptZero"));
SetConstant(ConstantIndex::MINIMUM_INTEGER_DIGITS_INDEX,
factory->NewFromASCII("minimumIntegerDigits"));
factory->NewFromASCIINonMovable("minimumIntegerDigits"));
SetConstant(ConstantIndex::MINIMUM_FRACTIONDIGITS_INDEX,
factory->NewFromASCII("minimumFractionDigits"));
factory->NewFromASCIINonMovable("minimumFractionDigits"));
SetConstant(ConstantIndex::MAXIMUM_FRACTIONDIGITS_INDEX,
factory->NewFromASCII("maximumFractionDigits"));
factory->NewFromASCIINonMovable("maximumFractionDigits"));
SetConstant(ConstantIndex::MINIMUM_SIGNIFICANTDIGITS_INDEX,
factory->NewFromASCII("minimumSignificantDigits"));
factory->NewFromASCIINonMovable("minimumSignificantDigits"));
SetConstant(ConstantIndex::MAXIMUM_SIGNIFICANTDIGITS_INDEX,
factory->NewFromASCII("maximumSignificantDigits"));
SetConstant(ConstantIndex::INVALID_DATE_INDEX, factory->NewFromASCII("Invalid Date"));
SetConstant(ConstantIndex::USAGE_INDEX, factory->NewFromASCII("usage"));
SetConstant(ConstantIndex::COMPARE_INDEX, factory->NewFromASCII("compare"));
SetConstant(ConstantIndex::SENSITIVITY_INDEX, factory->NewFromASCII("sensitivity"));
SetConstant(ConstantIndex::IGNORE_PUNCTUATION_INDEX, factory->NewFromASCII("ignorePunctuation"));
SetConstant(ConstantIndex::CARDINAL_INDEX, factory->NewFromASCII("cardinal"));
SetConstant(ConstantIndex::ORDINAL_INDEX, factory->NewFromASCII("ordinal"));
SetConstant(ConstantIndex::EXEC_INDEX, factory->NewFromASCII("exec"));
SetConstant(ConstantIndex::LAST_INDEX_INDEX, factory->NewFromASCII("lastIndex"));
SetConstant(ConstantIndex::PLURAL_CATEGORIES_INDEX, factory->NewFromASCII("pluralCategories"));
SetConstant(ConstantIndex::SORT_INDEX, factory->NewFromASCII("sort"));
SetConstant(ConstantIndex::SEARCH_INDEX, factory->NewFromASCII("search"));
SetConstant(ConstantIndex::BASE_INDEX, factory->NewFromASCII("base"));
SetConstant(ConstantIndex::ACCENT_INDEX, factory->NewFromASCII("accent"));
SetConstant(ConstantIndex::CASE_INDEX, factory->NewFromASCII("case"));
SetConstant(ConstantIndex::VARIANT_INDEX, factory->NewFromASCII("variant"));
SetConstant(ConstantIndex::EN_US_POSIX_STRING_INDEX, factory->NewFromASCII("en-US-POSIX"));
SetConstant(ConstantIndex::UPPER_INDEX, factory->NewFromASCII("upper"));
SetConstant(ConstantIndex::LOWER_INDEX, factory->NewFromASCII("lower"));
SetConstant(ConstantIndex::DEFAULT_INDEX, factory->NewFromASCII("default"));
SetConstant(ConstantIndex::SHARED_INDEX, factory->NewFromASCII("shared"));
SetConstant(ConstantIndex::START_RANGE_INDEX, factory->NewFromASCII("startRange"));
SetConstant(ConstantIndex::END_RANGE_INDEX, factory->NewFromASCII("endRange"));
SetConstant(ConstantIndex::ISO8601_INDEX, factory->NewFromASCII("iso8601"));
SetConstant(ConstantIndex::GREGORY_INDEX, factory->NewFromASCII("gregory"));
SetConstant(ConstantIndex::ETHIOAA_INDEX, factory->NewFromASCII("ethioaa"));
SetConstant(ConstantIndex::STICKY_INDEX, factory->NewFromASCII("sticky"));
SetConstant(ConstantIndex::U_INDEX, factory->NewFromASCII("u"));
SetConstant(ConstantIndex::INDEX_INDEX, factory->NewFromASCII("index"));
SetConstant(ConstantIndex::INPUT_INDEX, factory->NewFromASCII("input"));
SetConstant(ConstantIndex::UNICODE_INDEX, factory->NewFromASCII("unicode"));
SetConstant(ConstantIndex::ZERO_INDEX, factory->NewFromASCII("0"));
SetConstant(ConstantIndex::VALUES_INDEX, factory->NewFromASCII("values"));
SetConstant(ConstantIndex::ADD_INDEX, factory->NewFromASCII("add"));
SetConstant(ConstantIndex::AMBIGUOUS_INDEX, factory->NewFromASCII("ambiguous"));
SetConstant(ConstantIndex::MODULE_INDEX, factory->NewFromASCII("module"));
SetConstant(ConstantIndex::STAR_INDEX, factory->NewFromASCII("*"));
SetConstant(ConstantIndex::DATETIMEFIELD_INDEX, factory->NewFromASCII("datetimefield"));
SetConstant(ConstantIndex::CONJUNCTION_INDEX, factory->NewFromASCII("conjunction"));
SetConstant(ConstantIndex::NONE_INDEX, factory->NewFromASCII("none"));
SetConstant(ConstantIndex::FALLBACK_INDEX, factory->NewFromASCII("fallback"));
SetConstant(ConstantIndex::DISJUNCTION_INDEX, factory->NewFromASCII("disjunction"));
SetConstant(ConstantIndex::ELEMENT_INDEX, factory->NewFromASCII("element"));
SetConstant(ConstantIndex::FLAGS_INDEX, factory->NewFromASCII("flags"));
SetConstant(ConstantIndex::G_INDEX, factory->NewFromASCII("g"));
factory->NewFromASCIINonMovable("maximumSignificantDigits"));
SetConstant(ConstantIndex::INVALID_DATE_INDEX, factory->NewFromASCIINonMovable("Invalid Date"));
SetConstant(ConstantIndex::USAGE_INDEX, factory->NewFromASCIINonMovable("usage"));
SetConstant(ConstantIndex::COMPARE_INDEX, factory->NewFromASCIINonMovable("compare"));
SetConstant(ConstantIndex::SENSITIVITY_INDEX, factory->NewFromASCIINonMovable("sensitivity"));
SetConstant(ConstantIndex::IGNORE_PUNCTUATION_INDEX, factory->NewFromASCIINonMovable("ignorePunctuation"));
SetConstant(ConstantIndex::CARDINAL_INDEX, factory->NewFromASCIINonMovable("cardinal"));
SetConstant(ConstantIndex::ORDINAL_INDEX, factory->NewFromASCIINonMovable("ordinal"));
SetConstant(ConstantIndex::EXEC_INDEX, factory->NewFromASCIINonMovable("exec"));
SetConstant(ConstantIndex::LAST_INDEX_INDEX, factory->NewFromASCIINonMovable("lastIndex"));
SetConstant(ConstantIndex::PLURAL_CATEGORIES_INDEX, factory->NewFromASCIINonMovable("pluralCategories"));
SetConstant(ConstantIndex::SORT_INDEX, factory->NewFromASCIINonMovable("sort"));
SetConstant(ConstantIndex::SEARCH_INDEX, factory->NewFromASCIINonMovable("search"));
SetConstant(ConstantIndex::BASE_INDEX, factory->NewFromASCIINonMovable("base"));
SetConstant(ConstantIndex::ACCENT_INDEX, factory->NewFromASCIINonMovable("accent"));
SetConstant(ConstantIndex::CASE_INDEX, factory->NewFromASCIINonMovable("case"));
SetConstant(ConstantIndex::VARIANT_INDEX, factory->NewFromASCIINonMovable("variant"));
SetConstant(ConstantIndex::EN_US_POSIX_STRING_INDEX, factory->NewFromASCIINonMovable("en-US-POSIX"));
SetConstant(ConstantIndex::UPPER_INDEX, factory->NewFromASCIINonMovable("upper"));
SetConstant(ConstantIndex::LOWER_INDEX, factory->NewFromASCIINonMovable("lower"));
SetConstant(ConstantIndex::DEFAULT_INDEX, factory->NewFromASCIINonMovable("default"));
SetConstant(ConstantIndex::SHARED_INDEX, factory->NewFromASCIINonMovable("shared"));
SetConstant(ConstantIndex::START_RANGE_INDEX, factory->NewFromASCIINonMovable("startRange"));
SetConstant(ConstantIndex::END_RANGE_INDEX, factory->NewFromASCIINonMovable("endRange"));
SetConstant(ConstantIndex::ISO8601_INDEX, factory->NewFromASCIINonMovable("iso8601"));
SetConstant(ConstantIndex::GREGORY_INDEX, factory->NewFromASCIINonMovable("gregory"));
SetConstant(ConstantIndex::ETHIOAA_INDEX, factory->NewFromASCIINonMovable("ethioaa"));
SetConstant(ConstantIndex::STICKY_INDEX, factory->NewFromASCIINonMovable("sticky"));
SetConstant(ConstantIndex::U_INDEX, factory->NewFromASCIINonMovable("u"));
SetConstant(ConstantIndex::INDEX_INDEX, factory->NewFromASCIINonMovable("index"));
SetConstant(ConstantIndex::INPUT_INDEX, factory->NewFromASCIINonMovable("input"));
SetConstant(ConstantIndex::UNICODE_INDEX, factory->NewFromASCIINonMovable("unicode"));
SetConstant(ConstantIndex::ZERO_INDEX, factory->NewFromASCIINonMovable("0"));
SetConstant(ConstantIndex::VALUES_INDEX, factory->NewFromASCIINonMovable("values"));
SetConstant(ConstantIndex::ADD_INDEX, factory->NewFromASCIINonMovable("add"));
SetConstant(ConstantIndex::AMBIGUOUS_INDEX, factory->NewFromASCIINonMovable("ambiguous"));
SetConstant(ConstantIndex::MODULE_INDEX, factory->NewFromASCIINonMovable("module"));
SetConstant(ConstantIndex::STAR_INDEX, factory->NewFromASCIINonMovable("*"));
SetConstant(ConstantIndex::DATETIMEFIELD_INDEX, factory->NewFromASCIINonMovable("datetimefield"));
SetConstant(ConstantIndex::CONJUNCTION_INDEX, factory->NewFromASCIINonMovable("conjunction"));
SetConstant(ConstantIndex::NONE_INDEX, factory->NewFromASCIINonMovable("none"));
SetConstant(ConstantIndex::FALLBACK_INDEX, factory->NewFromASCIINonMovable("fallback"));
SetConstant(ConstantIndex::DISJUNCTION_INDEX, factory->NewFromASCIINonMovable("disjunction"));
SetConstant(ConstantIndex::ELEMENT_INDEX, factory->NewFromASCIINonMovable("element"));
SetConstant(ConstantIndex::FLAGS_INDEX, factory->NewFromASCIINonMovable("flags"));
SetConstant(ConstantIndex::G_INDEX, factory->NewFromASCIINonMovable("g"));
SetConstant(ConstantIndex::NFC_INDEX, factory->NewFromASCIINonMovable("NFC"));
SetConstant(ConstantIndex::ENTRIES_INDEX, factory->NewFromASCIINonMovable("entries"));
SetConstant(ConstantIndex::LEFT_SQUARE_BRACKET_INDEX, factory->NewFromASCIINonMovable("["));
SetConstant(ConstantIndex::RIGHT_SQUARE_BRACKET_INDEX, factory->NewFromASCIINonMovable("]"));
SetConstant(ConstantIndex::Y_INDEX, factory->NewFromASCIINonMovable("y"));
SetConstant(ConstantIndex::DOLLAR_INDEX, factory->NewFromASCIINonMovable("$"));
SetConstant(ConstantIndex::COMMA_INDEX, factory->NewFromASCIINonMovable(","));
SetConstant(ConstantIndex::JOIN_INDEX, factory->NewFromASCIINonMovable("join"));
SetConstant(ConstantIndex::COPY_WITHIN_INDEX, factory->NewFromASCIINonMovable("copyWithin"));
SetConstant(ConstantIndex::FILL_INDEX, factory->NewFromASCIINonMovable("fill"));
SetConstant(ConstantIndex::FIND_INDEX, factory->NewFromASCIINonMovable("find"));
SetConstant(ConstantIndex::FIND_INDEX_INDEX, factory->NewFromASCIINonMovable("findIndex"));
SetConstant(ConstantIndex::FLAT_INDEX, factory->NewFromASCIINonMovable("flat"));
SetConstant(ConstantIndex::FLATMAP_INDEX, factory->NewFromASCIINonMovable("flatMap"));
SetConstant(ConstantIndex::INCLUDES_INDEX, factory->NewFromASCIINonMovable("includes"));
SetConstant(ConstantIndex::KEYS_INDEX, factory->NewFromASCIINonMovable("keys"));
SetConstant(ConstantIndex::BOUND_INDEX, factory->NewFromASCIINonMovable("bound"));
SetConstant(ConstantIndex::BACKSLASH_INDEX, factory->NewFromASCIINonMovable("/"));
SetConstant(ConstantIndex::SPACE_INDEX, factory->NewFromASCIINonMovable(" "));
SetConstant(ConstantIndex::NAN_INDEX, factory->NewFromASCIINonMovable("NaN"));
auto accessor = factory->NewInternalAccessor(reinterpret_cast<void *>(JSFunction::PrototypeSetter),
reinterpret_cast<void *>(JSFunction::PrototypeGetter));

View File

@ -246,7 +246,6 @@ class JSThread;
V(JSTaggedValue, DateStyleString, DATE_STYLE_STRING_INDEX, dateStyle) \
V(JSTaggedValue, TimeStyleString, TIME_STYLE_STRING_INDEX, timeStyle) \
V(JSTaggedValue, UTCString, UTC_STRING_INDEX, UTC) \
V(JSTaggedValue, InitializedRelativeTimeFormatString, INITIALIZED_RELATIVE_INDEX, true) \
V(JSTaggedValue, WeekString, WEEK_STRING_INDEX, week) \
V(JSTaggedValue, WeeksString, WEEKS_STRING_INDEX, weeks) \
V(JSTaggedValue, SourceString, SOURCE_STRING_INDEX, source) \
@ -342,7 +341,27 @@ class JSThread;
V(JSTaggedValue, DisjunctionString, DISJUNCTION_INDEX, disjunction) \
V(JSTaggedValue, ElementString, ELEMENT_INDEX, element) \
V(JSTaggedValue, FlagsString, FLAGS_INDEX, flags) \
V(JSTaggedValue, GString, G_INDEX, g)
V(JSTaggedValue, GString, G_INDEX, g) \
V(JSTaggedValue, NfcString, NFC_INDEX, nfc) \
V(JSTaggedValue, EntriesString, ENTRIES_INDEX, entries) \
V(JSTaggedValue, LeftSquareBracketString, LEFT_SQUARE_BRACKET_INDEX, leftsquarebracket) \
V(JSTaggedValue, RightSquareBracketString, RIGHT_SQUARE_BRACKET_INDEX, rightsquarebracket) \
V(JSTaggedValue, YString, Y_INDEX, y) \
V(JSTaggedValue, DollarString, DOLLAR_INDEX, dollar) \
V(JSTaggedValue, CommaString, COMMA_INDEX, comma) \
V(JSTaggedValue, JoinString, JOIN_INDEX, join) \
V(JSTaggedValue, CopyWithinString, COPY_WITHIN_INDEX, copywithin) \
V(JSTaggedValue, FillString, FILL_INDEX, fill) \
V(JSTaggedValue, FindString, FIND_INDEX, find) \
V(JSTaggedValue, FindIndexString, FIND_INDEX_INDEX, findindex) \
V(JSTaggedValue, FlatString, FLAT_INDEX, flat) \
V(JSTaggedValue, FlatMapString, FLATMAP_INDEX, flatmap) \
V(JSTaggedValue, IncludesString, INCLUDES_INDEX, includes) \
V(JSTaggedValue, KeysString, KEYS_INDEX, keys) \
V(JSTaggedValue, BoundString, BOUND_INDEX, bound) \
V(JSTaggedValue, BackslashString, BACKSLASH_INDEX, backslash) \
V(JSTaggedValue, SpaceString, SPACE_INDEX, space) \
V(JSTaggedValue, NanCapitalString, NAN_INDEX, nan)
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define GLOBAL_ENV_CONSTANT_ACCESSOR(V) \

View File

@ -362,6 +362,7 @@ bool JSFunctionBase::SetFunctionName(JSThread *thread, const JSHandle<JSFunction
ASSERT_PRINT(name->IsStringOrSymbol(), "name must be string or symbol");
bool needPrefix = false;
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
const GlobalEnvConstants *globalConst = thread->GlobalConstants();
if (!prefix->IsUndefined()) {
ASSERT_PRINT(prefix->IsString(), "prefix must be string");
needPrefix = true;
@ -377,8 +378,10 @@ bool JSFunctionBase::SetFunctionName(JSThread *thread, const JSHandle<JSFunction
if (description.IsUndefined()) {
functionName = factory->GetEmptyString();
} else {
JSHandle<EcmaString> leftBrackets = factory->NewFromASCII("[");
JSHandle<EcmaString> rightBrackets = factory->NewFromASCII("]");
JSHandle<EcmaString> leftBrackets = JSHandle<EcmaString>::Cast(globalConst->
GetHandledLeftSquareBracketString());
JSHandle<EcmaString> rightBrackets = JSHandle<EcmaString>::Cast(globalConst->
GetHandledRightSquareBracketString());
functionName = factory->ConcatFromString(leftBrackets, descriptionHandle);
functionName = factory->ConcatFromString(functionName, rightBrackets);
}
@ -388,14 +391,14 @@ bool JSFunctionBase::SetFunctionName(JSThread *thread, const JSHandle<JSFunction
EcmaString *newString;
if (needPrefix) {
JSHandle<EcmaString> handlePrefixString = JSTaggedValue::ToString(thread, prefix);
JSHandle<EcmaString> spaceString(factory->NewFromASCII(" "));
JSHandle<EcmaString> spaceString = JSHandle<EcmaString>::Cast(globalConst->GetHandledSpaceString());
JSHandle<EcmaString> concatString = factory->ConcatFromString(handlePrefixString, spaceString);
newString = *factory->ConcatFromString(concatString, functionName);
} else {
newString = *functionName;
}
JSHandle<JSTaggedValue> nameHandle(thread, newString);
JSHandle<JSTaggedValue> nameKey = thread->GlobalConstants()->GetHandledNameString();
JSHandle<JSTaggedValue> nameKey = globalConst->GetHandledNameString();
PropertyDescriptor nameDesc(thread, nameHandle, false, false, true);
JSHandle<JSTaggedValue> funcHandle(func);
return JSTaggedValue::DefinePropertyOrThrow(thread, funcHandle, nameKey, nameDesc);
@ -480,6 +483,7 @@ void JSFunction::SetFunctionNameNoPrefix(JSThread *thread, JSFunction *func, JST
{
ASSERT_PRINT(func->IsExtensible(), "Function must be extensible");
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
const GlobalEnvConstants *globalConst = thread->GlobalConstants();
JSHandle<JSTaggedValue> funcHandle(thread, func);
{
@ -490,11 +494,13 @@ void JSFunction::SetFunctionNameNoPrefix(JSThread *thread, JSFunction *func, JST
JSHandle<JSTaggedValue> nameBegin(thread, name);
JSTaggedValue description = JSSymbol::Cast(name.GetTaggedObject())->GetDescription();
if (description.IsUndefined()) {
nameHandle.Update(thread->GlobalConstants()->GetEmptyString());
nameHandle.Update(globalConst->GetEmptyString());
} else {
JSHandle<EcmaString> concatName;
JSHandle<EcmaString> leftBrackets = factory->NewFromASCII("[");
JSHandle<EcmaString> rightBrackets = factory->NewFromASCII("]");
JSHandle<EcmaString> leftBrackets = JSHandle<EcmaString>::Cast(globalConst->
GetHandledLeftSquareBracketString());
JSHandle<EcmaString> rightBrackets = JSHandle<EcmaString>::Cast(globalConst->
GetHandledRightSquareBracketString());
concatName = factory->ConcatFromString(
leftBrackets,
JSHandle<EcmaString>(thread, JSSymbol::Cast(nameBegin->GetHeapObject())->GetDescription()));
@ -503,8 +509,7 @@ void JSFunction::SetFunctionNameNoPrefix(JSThread *thread, JSFunction *func, JST
}
}
PropertyDescriptor nameDesc(thread, nameHandle, false, false, true);
JSTaggedValue::DefinePropertyOrThrow(thread, funcHandle, thread->GlobalConstants()->GetHandledNameString(),
nameDesc);
JSTaggedValue::DefinePropertyOrThrow(thread, funcHandle, globalConst->GetHandledNameString(), nameDesc);
}
}

View File

@ -71,10 +71,12 @@ JSHandle<JSTaggedValue> JSIterator::GetIterator(JSThread *thread, const JSHandle
// 7.4.2
JSHandle<JSObject> JSIterator::IteratorNext(JSThread *thread, const JSHandle<JSTaggedValue> &iter)
{
const GlobalEnvConstants *globalConst = thread->GlobalConstants();
// 1.If value was not passed, then Let result be Invoke(iterator, "next", «‍ »).
JSHandle<JSTaggedValue> key(thread->GlobalConstants()->GetHandledNextString());
JSHandle<JSTaggedValue> key(globalConst->GetHandledNextString());
JSHandle<JSTaggedValue> next(JSObject::GetMethod(thread, iter, key));
JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
JSHandle<JSTaggedValue> undefined = globalConst->GetHandledUndefined();
EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, next, iter, undefined, 0);
JSTaggedValue ret = JSFunction::Call(&info);
JSHandle<JSObject> result(thread, ret);
@ -90,10 +92,11 @@ JSHandle<JSObject> JSIterator::IteratorNext(JSThread *thread, const JSHandle<JST
JSHandle<JSObject> JSIterator::IteratorNext(JSThread *thread, const JSHandle<JSTaggedValue> &iter,
const JSHandle<JSTaggedValue> &value)
{
const GlobalEnvConstants *globalConst = thread->GlobalConstants();
// 2.Let result be Invoke(iterator, "next", «value»).
JSHandle<JSTaggedValue> key(thread->GlobalConstants()->GetHandledNextString());
JSHandle<JSTaggedValue> key(globalConst->GetHandledNextString());
JSHandle<JSTaggedValue> next(JSObject::GetMethod(thread, iter, key));
JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
JSHandle<JSTaggedValue> undefined = globalConst->GetHandledUndefined();
EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, next, iter, undefined, 1);
info.SetCallArg(value.GetTaggedValue());
JSTaggedValue ret = JSFunction::Call(&info);

View File

@ -48,6 +48,7 @@ JSHandle<JSProxy> JSProxy::ProxyCreate(JSThread *thread, const JSHandle<JSTagged
// ES6 9.5.1 [[GetPrototypeOf]] ( )
JSTaggedValue JSProxy::GetPrototype(JSThread *thread, const JSHandle<JSProxy> &proxy)
{
const GlobalEnvConstants *globalConst = thread->GlobalConstants();
// 1. Let handler be the value of the [[ProxyHandler]] internal slot of O.
JSHandle<JSTaggedValue> handler(thread, proxy->GetHandler());
// 2. If handler is null, throw a TypeError exception.
@ -59,7 +60,7 @@ JSTaggedValue JSProxy::GetPrototype(JSThread *thread, const JSHandle<JSProxy> &p
// 4. Let target be the value of the [[ProxyTarget]] internal slot of O.
JSHandle<JSTaggedValue> targetHandle(thread, proxy->GetTarget());
// 5. Let trap be GetMethod(handler, "getPrototypeOf").
JSHandle<JSTaggedValue> name(thread->GlobalConstants()->GetHandledGetPrototypeOfString());
JSHandle<JSTaggedValue> name(globalConst->GetHandledGetPrototypeOfString());
JSHandle<JSTaggedValue> trap = JSObject::GetMethod(thread, handler, name);
// 6. ReturnIfAbrupt(trap).
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
@ -69,7 +70,7 @@ JSTaggedValue JSProxy::GetPrototype(JSThread *thread, const JSHandle<JSProxy> &p
return JSTaggedValue::GetPrototype(thread, targetHandle);
}
// 8. Let handlerProto be Call(trap, handler, «target»).
JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
JSHandle<JSTaggedValue> undefined = globalConst->GetHandledUndefined();
EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handler, undefined, 1);
info.SetCallArg(targetHandle.GetTaggedValue());
JSTaggedValue handlerProto = JSFunction::Call(&info);
@ -105,6 +106,7 @@ JSTaggedValue JSProxy::GetPrototype(JSThread *thread, const JSHandle<JSProxy> &p
// ES6 9.5.2 [[SetPrototypeOf]] (V)
bool JSProxy::SetPrototype(JSThread *thread, const JSHandle<JSProxy> &proxy, const JSHandle<JSTaggedValue> &proto)
{
const GlobalEnvConstants *globalConst = thread->GlobalConstants();
// 1. Assert: Either Type(V) is Object or Type(V) is Null.
ASSERT(proto->IsECMAObject() || proto->IsNull());
// 2. Let handler be the value of the [[ProxyHandler]] internal slot of O.
@ -118,7 +120,7 @@ bool JSProxy::SetPrototype(JSThread *thread, const JSHandle<JSProxy> &proxy, con
// 5. Let target be the value of the [[ProxyTarget]] internal slot of O.
JSHandle<JSTaggedValue> targetHandle(thread, proxy->GetTarget());
// 6. Let trap be GetMethod(handler, "setPrototypeOf").
JSHandle<JSTaggedValue> name = thread->GlobalConstants()->GetHandledSetPrototypeOfString();
JSHandle<JSTaggedValue> name = globalConst->GetHandledSetPrototypeOfString();
JSHandle<JSTaggedValue> trap(JSObject::GetMethod(thread, JSHandle<JSTaggedValue>(thread, handler), name));
// 7. ReturnIfAbrupt(trap).
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false);
@ -129,7 +131,7 @@ bool JSProxy::SetPrototype(JSThread *thread, const JSHandle<JSProxy> &proxy, con
}
JSHandle<JSTaggedValue> handlerTag(thread, proxy->GetHandler());
const size_t argsLength = 2; // 2: target and proto
JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
JSHandle<JSTaggedValue> undefined = globalConst->GetHandledUndefined();
EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, argsLength);
info.SetCallArg(targetHandle.GetTaggedValue(), proto.GetTaggedValue());
JSTaggedValue trapResult = JSFunction::Call(&info);
@ -165,6 +167,7 @@ bool JSProxy::SetPrototype(JSThread *thread, const JSHandle<JSProxy> &proxy, con
// ES6 9.5.3 [[IsExtensible]] ( )
bool JSProxy::IsExtensible(JSThread *thread, const JSHandle<JSProxy> &proxy)
{
const GlobalEnvConstants *globalConst = thread->GlobalConstants();
// 1. Let handler be the value of the [[ProxyHandler]] internal slot of O.
JSTaggedValue handler = proxy->GetHandler();
// 2. If handler is null, throw a TypeError exception.
@ -176,7 +179,7 @@ bool JSProxy::IsExtensible(JSThread *thread, const JSHandle<JSProxy> &proxy)
// 4. Let target be the value of the [[ProxyTarget]] internal slot of O.
JSHandle<JSTaggedValue> targetHandle(thread, proxy->GetTarget());
// 5. Let trap be GetMethod(handler, "isExtensible").
JSHandle<JSTaggedValue> name = thread->GlobalConstants()->GetHandledIsExtensibleString();
JSHandle<JSTaggedValue> name = globalConst->GetHandledIsExtensibleString();
JSHandle<JSTaggedValue> trap(JSObject::GetMethod(thread, JSHandle<JSTaggedValue>(thread, handler), name));
// 6. ReturnIfAbrupt(trap).
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false);
@ -188,7 +191,7 @@ bool JSProxy::IsExtensible(JSThread *thread, const JSHandle<JSProxy> &proxy)
// 8. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target»)).
JSHandle<JSTaggedValue> newTgt(thread, JSTaggedValue::Undefined());
JSHandle<JSTaggedValue> handlerTag(thread, proxy->GetHandler());
JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
JSHandle<JSTaggedValue> undefined = globalConst->GetHandledUndefined();
EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, 1);
info.SetCallArg(targetHandle.GetTaggedValue());
JSTaggedValue trapResult = JSFunction::Call(&info);
@ -211,6 +214,7 @@ bool JSProxy::IsExtensible(JSThread *thread, const JSHandle<JSProxy> &proxy)
// ES6 9.5.4 [[PreventExtensions]] ( )
bool JSProxy::PreventExtensions(JSThread *thread, const JSHandle<JSProxy> &proxy)
{
const GlobalEnvConstants *globalConst = thread->GlobalConstants();
// 1. Let handler be the value of the [[ProxyHandler]] internal slot of O.
// 2. If handler is null, throw a TypeError exception.
// 3. Assert: Type(handler) is Object.
@ -227,7 +231,7 @@ bool JSProxy::PreventExtensions(JSThread *thread, const JSHandle<JSProxy> &proxy
}
ASSERT(handler.IsECMAObject());
JSHandle<JSTaggedValue> targetHandle(thread, proxy->GetTarget());
JSHandle<JSTaggedValue> name = thread->GlobalConstants()->GetHandledPreventExtensionsString();
JSHandle<JSTaggedValue> name = globalConst->GetHandledPreventExtensionsString();
JSHandle<JSTaggedValue> trap(JSObject::GetMethod(thread, JSHandle<JSTaggedValue>(thread, handler), name));
// 6. ReturnIfAbrupt(trap).
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false);
@ -236,7 +240,7 @@ bool JSProxy::PreventExtensions(JSThread *thread, const JSHandle<JSProxy> &proxy
return JSTaggedValue::PreventExtensions(thread, targetHandle);
}
JSHandle<JSTaggedValue> handlerTag(thread, proxy->GetHandler());
JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
JSHandle<JSTaggedValue> undefined = globalConst->GetHandledUndefined();
EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, 1);
info.SetCallArg(targetHandle.GetTaggedValue());
JSTaggedValue trapResult = JSFunction::Call(&info);
@ -259,6 +263,7 @@ bool JSProxy::PreventExtensions(JSThread *thread, const JSHandle<JSProxy> &proxy
bool JSProxy::GetOwnProperty(JSThread *thread, const JSHandle<JSProxy> &proxy, const JSHandle<JSTaggedValue> &key,
PropertyDescriptor &desc)
{
const GlobalEnvConstants *globalConst = thread->GlobalConstants();
// 1. Assert: IsPropertyKey(P) is true.
ASSERT(JSTaggedValue::IsPropertyKey(key));
// 2. Let handler be the value of the [[ProxyHandler]] internal slot of O.
@ -278,7 +283,7 @@ bool JSProxy::GetOwnProperty(JSThread *thread, const JSHandle<JSProxy> &proxy, c
}
ASSERT(handler.IsECMAObject());
JSHandle<JSTaggedValue> targetHandle(thread, proxy->GetTarget());
JSHandle<JSTaggedValue> name = thread->GlobalConstants()->GetHandledGetOwnPropertyDescriptorString();
JSHandle<JSTaggedValue> name = globalConst->GetHandledGetOwnPropertyDescriptorString();
JSHandle<JSTaggedValue> trap(JSObject::GetMethod(thread, JSHandle<JSTaggedValue>(thread, handler), name));
// 7. ReturnIfAbrupt(trap).
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false);
@ -288,7 +293,7 @@ bool JSProxy::GetOwnProperty(JSThread *thread, const JSHandle<JSProxy> &proxy, c
}
JSHandle<JSTaggedValue> handlerTag(thread, proxy->GetHandler());
const size_t argsLength = 2; // 2: target and key
JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
JSHandle<JSTaggedValue> undefined = globalConst->GetHandledUndefined();
EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, argsLength);
info.SetCallArg(targetHandle.GetTaggedValue(), key.GetTaggedValue());
JSTaggedValue trapResultObj = JSFunction::Call(&info);
@ -364,6 +369,7 @@ bool JSProxy::GetOwnProperty(JSThread *thread, const JSHandle<JSProxy> &proxy, c
bool JSProxy::DefineOwnProperty(JSThread *thread, const JSHandle<JSProxy> &proxy, const JSHandle<JSTaggedValue> &key,
const PropertyDescriptor &desc)
{
const GlobalEnvConstants *globalConst = thread->GlobalConstants();
// step 1 ~ 10 are almost same as GetOwnProperty
ASSERT(JSTaggedValue::IsPropertyKey(key));
JSTaggedValue handler = proxy->GetHandler();
@ -372,7 +378,7 @@ bool JSProxy::DefineOwnProperty(JSThread *thread, const JSHandle<JSProxy> &proxy
}
ASSERT(handler.IsECMAObject());
JSHandle<JSTaggedValue> targetHandle(thread, proxy->GetTarget());
JSHandle<JSTaggedValue> name = thread->GlobalConstants()->GetHandledDefinePropertyString();
JSHandle<JSTaggedValue> name = globalConst->GetHandledDefinePropertyString();
JSHandle<JSTaggedValue> trap(JSObject::GetMethod(thread, JSHandle<JSTaggedValue>(thread, handler), name));
// 7. ReturnIfAbrupt(trap).
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false);
@ -384,7 +390,7 @@ bool JSProxy::DefineOwnProperty(JSThread *thread, const JSHandle<JSProxy> &proxy
JSHandle<JSTaggedValue> descObj = JSObject::FromPropertyDescriptor(thread, desc);
JSHandle<JSTaggedValue> handlerTag(thread, proxy->GetHandler());
const size_t argsLength = 3; // 3: target, key and desc
JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
JSHandle<JSTaggedValue> undefined = globalConst->GetHandledUndefined();
EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, argsLength);
info.SetCallArg(targetHandle.GetTaggedValue(), key.GetTaggedValue(), descObj.GetTaggedValue());
JSTaggedValue trapResult = JSFunction::Call(&info);
@ -450,6 +456,7 @@ bool JSProxy::DefineOwnProperty(JSThread *thread, const JSHandle<JSProxy> &proxy
// ES6 9.5.7 [[HasProperty]] (P)
bool JSProxy::HasProperty(JSThread *thread, const JSHandle<JSProxy> &proxy, const JSHandle<JSTaggedValue> &key)
{
const GlobalEnvConstants *globalConst = thread->GlobalConstants();
// step 1 ~ 10 are almost same as GetOwnProperty
ASSERT(JSTaggedValue::IsPropertyKey(key));
JSTaggedValue handler = proxy->GetHandler();
@ -458,7 +465,7 @@ bool JSProxy::HasProperty(JSThread *thread, const JSHandle<JSProxy> &proxy, cons
}
ASSERT(handler.IsECMAObject());
JSHandle<JSTaggedValue> targetHandle(thread, proxy->GetTarget());
JSHandle<JSTaggedValue> name = thread->GlobalConstants()->GetHandledHasString();
JSHandle<JSTaggedValue> name = globalConst->GetHandledHasString();
JSHandle<JSTaggedValue> trap(JSObject::GetMethod(thread, JSHandle<JSTaggedValue>(thread, handler), name));
// 7. ReturnIfAbrupt(trap).
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false);
@ -470,7 +477,7 @@ bool JSProxy::HasProperty(JSThread *thread, const JSHandle<JSProxy> &proxy, cons
JSHandle<JSTaggedValue> handlerTag(thread, proxy->GetHandler());
const size_t argsLength = 2; // 2: target and key
JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
JSHandle<JSTaggedValue> undefined = globalConst->GetHandledUndefined();
EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, argsLength);
info.SetCallArg(targetHandle.GetTaggedValue(), key.GetTaggedValue());
JSTaggedValue trapResult = JSFunction::Call(&info);
@ -507,6 +514,7 @@ bool JSProxy::HasProperty(JSThread *thread, const JSHandle<JSProxy> &proxy, cons
OperationResult JSProxy::GetProperty(JSThread *thread, const JSHandle<JSProxy> &proxy,
const JSHandle<JSTaggedValue> &key, const JSHandle<JSTaggedValue> &receiver)
{
const GlobalEnvConstants *globalConst = thread->GlobalConstants();
// step 1 ~ 10 are almost same as GetOwnProperty
ASSERT(JSTaggedValue::IsPropertyKey(key));
JSTaggedValue handler = proxy->GetHandler();
@ -517,7 +525,7 @@ OperationResult JSProxy::GetProperty(JSThread *thread, const JSHandle<JSProxy> &
}
ASSERT(handler.IsECMAObject());
JSHandle<JSTaggedValue> targetHandle(thread, proxy->GetTarget());
JSHandle<JSTaggedValue> name = thread->GlobalConstants()->GetHandledGetString();
JSHandle<JSTaggedValue> name = globalConst->GetHandledGetString();
JSHandle<JSTaggedValue> trap(JSObject::GetMethod(thread, JSHandle<JSTaggedValue>(thread, handler), name));
// 7. ReturnIfAbrupt(trap).
RETURN_VALUE_IF_ABRUPT_COMPLETION(
@ -529,7 +537,7 @@ OperationResult JSProxy::GetProperty(JSThread *thread, const JSHandle<JSProxy> &
// 9. Let trapResult be Call(trap, handler, «target, P, Receiver»).
JSHandle<JSTaggedValue> handlerTag(thread, proxy->GetHandler());
const size_t argsLength = 3; // 3: «target, P, Receiver»
JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
JSHandle<JSTaggedValue> undefined = globalConst->GetHandledUndefined();
EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, argsLength);
info.SetCallArg(targetHandle.GetTaggedValue(), key.GetTaggedValue(), receiver.GetTaggedValue());
JSTaggedValue trapResult = JSFunction::Call(&info);
@ -578,6 +586,7 @@ OperationResult JSProxy::GetProperty(JSThread *thread, const JSHandle<JSProxy> &
bool JSProxy::SetProperty(JSThread *thread, const JSHandle<JSProxy> &proxy, const JSHandle<JSTaggedValue> &key,
const JSHandle<JSTaggedValue> &value, const JSHandle<JSTaggedValue> &receiver, bool mayThrow)
{
const GlobalEnvConstants *globalConst = thread->GlobalConstants();
// step 1 ~ 10 are almost same as GetOwnProperty
ASSERT(JSTaggedValue::IsPropertyKey(key));
JSTaggedValue handler = proxy->GetHandler();
@ -586,7 +595,7 @@ bool JSProxy::SetProperty(JSThread *thread, const JSHandle<JSProxy> &proxy, cons
}
ASSERT(handler.IsECMAObject());
JSHandle<JSTaggedValue> targetHandle(thread, proxy->GetTarget());
JSHandle<JSTaggedValue> name = thread->GlobalConstants()->GetHandledSetString();
JSHandle<JSTaggedValue> name = globalConst->GetHandledSetString();
JSHandle<JSTaggedValue> trap(JSObject::GetMethod(thread, JSHandle<JSTaggedValue>(thread, handler), name));
// 7. ReturnIfAbrupt(trap).
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false);
@ -597,7 +606,7 @@ bool JSProxy::SetProperty(JSThread *thread, const JSHandle<JSProxy> &proxy, cons
// 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P, V, Receiver»))
JSHandle<JSTaggedValue> handlerTag(thread, proxy->GetHandler());
const size_t argsLength = 4; // 4: «target, P, V, Receiver»
JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
JSHandle<JSTaggedValue> undefined = globalConst->GetHandledUndefined();
EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, argsLength);
info.SetCallArg(
targetHandle.GetTaggedValue(), key.GetTaggedValue(), value.GetTaggedValue(), receiver.GetTaggedValue());
@ -635,6 +644,7 @@ bool JSProxy::SetProperty(JSThread *thread, const JSHandle<JSProxy> &proxy, cons
// ES6 9.5.10 [[Delete]] (P)
bool JSProxy::DeleteProperty(JSThread *thread, const JSHandle<JSProxy> &proxy, const JSHandle<JSTaggedValue> &key)
{
const GlobalEnvConstants *globalConst = thread->GlobalConstants();
// step 1 ~ 13 are almost same as GetOwnProperty
ASSERT(JSTaggedValue::IsPropertyKey(key));
JSTaggedValue handler = proxy->GetHandler();
@ -643,7 +653,7 @@ bool JSProxy::DeleteProperty(JSThread *thread, const JSHandle<JSProxy> &proxy, c
}
ASSERT(handler.IsECMAObject());
JSHandle<JSTaggedValue> targetHandle(thread, proxy->GetTarget());
JSHandle<JSTaggedValue> name = thread->GlobalConstants()->GetHandledDeletePropertyString();
JSHandle<JSTaggedValue> name = globalConst->GetHandledDeletePropertyString();
JSHandle<JSTaggedValue> trap(JSObject::GetMethod(thread, JSHandle<JSTaggedValue>(thread, handler), name));
// 7. ReturnIfAbrupt(trap).
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false);
@ -655,7 +665,7 @@ bool JSProxy::DeleteProperty(JSThread *thread, const JSHandle<JSProxy> &proxy, c
JSHandle<JSTaggedValue> newTgt(thread, JSTaggedValue::Undefined());
JSHandle<JSTaggedValue> handlerTag(thread, proxy->GetHandler());
const size_t argsLength = 2; // 2: target and key
JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
JSHandle<JSTaggedValue> undefined = globalConst->GetHandledUndefined();
EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, argsLength);
info.SetCallArg(targetHandle.GetTaggedValue(), key.GetTaggedValue());
JSTaggedValue trapResult = JSFunction::Call(&info);
@ -690,6 +700,7 @@ bool JSProxy::DeleteProperty(JSThread *thread, const JSHandle<JSProxy> &proxy, c
// ES6 9.5.12 [[OwnPropertyKeys]] ()
JSHandle<TaggedArray> JSProxy::OwnPropertyKeys(JSThread *thread, const JSHandle<JSProxy> &proxy)
{
const GlobalEnvConstants *globalConst = thread->GlobalConstants();
// step 1 ~ 4 get ProxyHandler and ProxyTarget
JSTaggedValue handler = proxy->GetHandler();
if (handler.IsNull()) {
@ -701,7 +712,7 @@ JSHandle<TaggedArray> JSProxy::OwnPropertyKeys(JSThread *thread, const JSHandle<
JSHandle<JSTaggedValue> targetHandle(thread, proxy->GetTarget());
// 5.Let trap be GetMethod(handler, "ownKeys").
JSHandle<JSTaggedValue> key = thread->GlobalConstants()->GetHandledOwnKeysString();
JSHandle<JSTaggedValue> key = globalConst->GetHandledOwnKeysString();
JSHandle<JSTaggedValue> handlerHandle(thread, handler);
JSHandle<JSTaggedValue> trap(JSObject::GetMethod(thread, handlerHandle, key));
@ -716,7 +727,7 @@ JSHandle<TaggedArray> JSProxy::OwnPropertyKeys(JSThread *thread, const JSHandle<
// 8.Let trapResultArray be Call(trap, handler, «target»).
JSHandle<JSFunction> tagFunc(targetHandle);
JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
JSHandle<JSTaggedValue> undefined = globalConst->GetHandledUndefined();
EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerHandle, undefined, 1);
info.SetCallArg(targetHandle.GetTaggedValue());
JSTaggedValue res = JSFunction::Call(&info);
@ -839,6 +850,7 @@ JSTaggedValue JSProxy::CallInternal(EcmaRuntimeCallInfo *info)
}
JSThread *thread = info->GetThread();
const GlobalEnvConstants *globalConst = thread->GlobalConstants();
JSHandle<JSProxy> proxy(info->GetFunction());
// step 1 ~ 4 get ProxyHandler and ProxyTarget
JSHandle<JSTaggedValue> handler(thread, proxy->GetHandler());
@ -849,7 +861,7 @@ JSTaggedValue JSProxy::CallInternal(EcmaRuntimeCallInfo *info)
JSHandle<JSTaggedValue> target(thread, proxy->GetTarget());
// 5.Let trap be GetMethod(handler, "apply").
JSHandle<JSTaggedValue> key(thread->GlobalConstants()->GetHandledApplyString());
JSHandle<JSTaggedValue> key(globalConst->GetHandledApplyString());
JSHandle<JSTaggedValue> method = JSObject::GetMethod(thread, handler, key);
// 6.ReturnIfAbrupt(trap).
@ -872,7 +884,7 @@ JSTaggedValue JSProxy::CallInternal(EcmaRuntimeCallInfo *info)
// 9.Return Call(trap, handler, «target, thisArgument, argArray»).
JSHandle<JSTaggedValue> thisArg = info->GetThis();
const size_t argsLength = 3; // 3: «target, thisArgument, argArray»
JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
JSHandle<JSTaggedValue> undefined = globalConst->GetHandledUndefined();
EcmaRuntimeCallInfo runtimeInfo =
EcmaInterpreter::NewRuntimeCallInfo(thread, method, handler, undefined, argsLength);
runtimeInfo.SetCallArg(target.GetTaggedValue(), thisArg.GetTaggedValue(), arrHandle.GetTaggedValue());
@ -887,6 +899,7 @@ JSTaggedValue JSProxy::ConstructInternal(EcmaRuntimeCallInfo *info)
}
JSThread *thread = info->GetThread();
const GlobalEnvConstants *globalConst = thread->GlobalConstants();
// step 1 ~ 4 get ProxyHandler and ProxyTarget
JSHandle<JSProxy> proxy(info->GetFunction());
JSHandle<JSTaggedValue> handler(thread, proxy->GetHandler());
@ -897,7 +910,7 @@ JSTaggedValue JSProxy::ConstructInternal(EcmaRuntimeCallInfo *info)
JSHandle<JSTaggedValue> target(thread, proxy->GetTarget());
// 5.Let trap be GetMethod(handler, "construct").
JSHandle<JSTaggedValue> key(thread->GlobalConstants()->GetHandledProxyConstructString());
JSHandle<JSTaggedValue> key(globalConst->GetHandledProxyConstructString());
JSHandle<JSTaggedValue> method = JSObject::GetMethod(thread, handler, key);
// 6.ReturnIfAbrupt(trap).
@ -923,7 +936,7 @@ JSTaggedValue JSProxy::ConstructInternal(EcmaRuntimeCallInfo *info)
// step 8 ~ 9 Call(trap, handler, «target, argArray, newTarget »).
JSHandle<JSTaggedValue> newTarget(info->GetNewTarget());
const size_t argsLength = 3; // 3: «target, argArray, newTarget »
JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
JSHandle<JSTaggedValue> undefined = globalConst->GetHandledUndefined();
EcmaRuntimeCallInfo runtimeInfo =
EcmaInterpreter::NewRuntimeCallInfo(thread, method, handler, undefined, argsLength);
runtimeInfo.SetCallArg(target.GetTaggedValue(), arrHandle.GetTaggedValue(), newTarget.GetTaggedValue());

View File

@ -39,14 +39,14 @@
namespace panda::ecmascript {
JSHandle<EcmaString> GetTypeString(JSThread *thread, PreferredPrimitiveType type)
{
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
const GlobalEnvConstants *globalConst = thread->GlobalConstants();
if (type == NO_PREFERENCE) {
return factory->NewFromASCII("default");
return JSHandle<EcmaString>::Cast(globalConst->GetHandledDefaultString());
}
if (type == PREFER_NUMBER) {
return factory->NewFromASCII("number");
return JSHandle<EcmaString>::Cast(globalConst->GetHandledNumberString());
}
return factory->NewFromASCII("string");
return JSHandle<EcmaString>::Cast(globalConst->GetHandledStringString());
}
JSHandle<JSTaggedValue> JSTaggedValue::ToPropertyKey(JSThread *thread, const JSHandle<JSTaggedValue> &tagged)

View File

@ -2094,6 +2094,16 @@ JSHandle<EcmaString> ObjectFactory::GetStringFromStringTable(const uint8_t *utf8
return JSHandle<EcmaString>(thread_, stringTable->GetOrInternString(utf8Data, utf8Len, canBeCompress));
}
JSHandle<EcmaString> ObjectFactory::GetStringFromStringTableNonMovable(const uint8_t *utf8Data, uint32_t utf8Len) const
{
NewObjectHook();
if (utf8Len == 0) {
return GetEmptyString();
}
auto stringTable = vm_->GetEcmaStringTable();
return JSHandle<EcmaString>(thread_, stringTable->CreateAndInternStringNonMovable(utf8Data, utf8Len));
}
JSHandle<EcmaString> ObjectFactory::GetStringFromStringTable(const uint16_t *utf16Data, uint32_t utf16Len,
bool canBeCompress) const
{
@ -2707,6 +2717,13 @@ JSHandle<EcmaString> ObjectFactory::NewFromASCII(const CString &data)
return GetStringFromStringTable(utf8Data, data.length(), true);
}
JSHandle<EcmaString> ObjectFactory::NewFromASCIINonMovable(const CString &data)
{
auto utf8Data = reinterpret_cast<const uint8_t *>(data.c_str());
ASSERT(EcmaString::CanBeCompressed(utf8Data, data.length()));
return GetStringFromStringTableNonMovable(utf8Data, data.length());
}
JSHandle<EcmaString> ObjectFactory::NewFromUtf8(const CString &data)
{
auto utf8Data = reinterpret_cast<const uint8_t *>(data.c_str());

View File

@ -505,6 +505,9 @@ private:
// used to create nonmovable js_object
JSHandle<JSObject> NewNonMovableJSObject(const JSHandle<JSHClass> &jshclass);
// used to create nonmovable utf8 string at global constants
JSHandle<EcmaString> NewFromASCIINonMovable(const CString &data);
// used for creating Function
JSHandle<JSFunction> NewJSFunction(const JSHandle<GlobalEnv> &env, const JSHandle<JSHClass> &dynKlass);
JSHandle<JSHClass> CreateObjectClass(const JSHandle<TaggedArray> &properties, size_t length);
@ -516,6 +519,7 @@ private:
const JSHandle<JSTaggedValue> &object);
JSHandle<EcmaString> GetStringFromStringTable(const uint8_t *utf8Data, uint32_t utf8Len, bool canBeCompress) const;
JSHandle<EcmaString> GetStringFromStringTableNonMovable(const uint8_t *utf8Data, uint32_t utf8Len) const;
// For MUtf-8 string data
EcmaString *GetRawStringFromStringTable(const uint8_t *mutf8Data, uint32_t utf16Len, bool canBeCompressed) const;

View File

@ -126,4 +126,17 @@ HWTEST_F_L0(EcmaStringTableTest, GetOrInternString_EcmaString)
EXPECT_STREQ(ecmaStrGetPtr->GetCString().get(), "hello world");
EXPECT_TRUE(ecmaStrGetPtr->IsInternString());
}
/**
* @tc.name: GetOrInternString
* @tc.desc: Check the uniqueness of string and its hashcode in stringtable to ensure that no two strings have
same contents and same hashcode
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F_L0(EcmaStringTableTest, GetOrInternString_CheckStringTable)
{
EcmaVM *vm = thread->GetEcmaVM();
EXPECT_TRUE(vm->GetEcmaStringTable()->CheckStringTableValidity());
}
} // namespace panda::test

View File

@ -288,12 +288,13 @@ void DebuggerApi::HandleUncaughtException(const EcmaVM *ecmaVm, CString &message
{
JSThread *thread = ecmaVm->GetJSThread();
[[maybe_unused]] EcmaHandleScope handleScope(thread);
const GlobalEnvConstants *globalConst = thread->GlobalConstants();
JSHandle<JSTaggedValue> exHandle(thread, thread->GetException());
if (exHandle->IsJSError()) {
JSHandle<JSTaggedValue> nameKey = thread->GlobalConstants()->GetHandledNameString();
JSHandle<JSTaggedValue> nameKey = globalConst->GetHandledNameString();
JSHandle<EcmaString> name(JSObject::GetProperty(thread, exHandle, nameKey).GetValue());
JSHandle<JSTaggedValue> msgKey = thread->GlobalConstants()->GetHandledMessageString();
JSHandle<JSTaggedValue> msgKey = globalConst->GetHandledMessageString();
JSHandle<EcmaString> msg(JSObject::GetProperty(thread, exHandle, msgKey).GetValue());
message = ConvertToString(*name) + ": " + ConvertToString(*msg);
} else {