mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-11-23 18:20:04 +00:00
!9817 use constant string for symbol tostring
Merge pull request !9817 from zhouguangyuan0718/master-symbol
This commit is contained in:
commit
f87f2186e1
@ -15,6 +15,7 @@
|
||||
|
||||
#include "ecmascript/builtins/builtins_symbol.h"
|
||||
|
||||
#include "ecmascript/ecma_string_table.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/js_primitive_ref.h"
|
||||
#include "ecmascript/symbol_table.h"
|
||||
@ -91,18 +92,19 @@ JSTaggedValue BuiltinsSymbol::SymbolDescriptiveString(JSThread *thread, JSTagged
|
||||
JSHandle<JSTaggedValue> descHandle(thread, symbolObject->GetDescription());
|
||||
|
||||
// If desc is undefined, let desc be the empty string.
|
||||
|
||||
JSHandle<SingleCharTable> singleCharTable(thread, thread->GetSingleCharTable());
|
||||
auto constants = thread->GlobalConstants();
|
||||
if (descHandle->IsUndefined()) {
|
||||
JSHandle<EcmaString> leftHandle(factory->NewFromASCII("Symbol("));
|
||||
JSHandle<EcmaString> rightHandle(factory->NewFromASCII(")"));
|
||||
JSHandle<EcmaString> leftHandle = JSHandle<EcmaString>::Cast(constants->GetHandledSymbolLeftParentheses());
|
||||
JSHandle<EcmaString> rightHandle(thread, singleCharTable->GetStringFromSingleCharTable(')'));
|
||||
JSHandle<EcmaString> str = factory->ConcatFromString(leftHandle, rightHandle);
|
||||
return str.GetTaggedValue();
|
||||
}
|
||||
// Assert: Type(desc) is String.
|
||||
ASSERT(descHandle->IsString());
|
||||
// Return the result of concatenating the strings "Symbol(", desc, and ")".
|
||||
JSHandle<EcmaString> leftHandle(factory->NewFromASCII("Symbol("));
|
||||
JSHandle<EcmaString> rightHandle(factory->NewFromASCII(")"));
|
||||
JSHandle<EcmaString> leftHandle = JSHandle<EcmaString>::Cast(constants->GetHandledSymbolLeftParentheses());
|
||||
JSHandle<EcmaString> rightHandle(thread, singleCharTable->GetStringFromSingleCharTable(')'));
|
||||
JSHandle<EcmaString> stringLeft =
|
||||
factory->ConcatFromString(leftHandle, JSTaggedValue::ToString(thread, descHandle));
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
|
@ -629,7 +629,8 @@ class ObjectFactory;
|
||||
V(AppSpawnFullGcCause, APP_SPAWN_FULL_GC_CAUSE, "app_spawn_full") \
|
||||
V(SharedGcCause, SHARED_GC_CAUSE, "shared") \
|
||||
V(SharedFullGcCause, SHARED_FULL_GC_CAUSE, "shared_full") \
|
||||
V(AppSpawnSharedFullGcCause, APP_SPAWN_SHARED_FULL_GC_CAUSE, "app_spawn_shared_full")
|
||||
V(AppSpawnSharedFullGcCause, APP_SPAWN_SHARED_FULL_GC_CAUSE, "app_spawn_shared_full") \
|
||||
V(SymbolLeftParentheses, SYMBOL_LEFT_PARENTHESES, "Symbol(")
|
||||
|
||||
/* GlobalConstant */
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
|
||||
|
@ -13,4 +13,6 @@
|
||||
|
||||
test Symbol.prototype.toString successful !!!
|
||||
test Symbol.prototype.valueOf successful !!!
|
||||
{"at":true,"copyWithin":true,"entries":true,"fill":true,"find":true,"findIndex":true,"findLast":true,"findLastIndex":true,"flat":true,"flatMap":true,"includes":true,"keys":true,"values":true,"toReversed":true,"toSorted":true,"toSpliced":true}
|
||||
{"at":true,"copyWithin":true,"entries":true,"fill":true,"find":true,"findIndex":true,"findLast":true,"findLastIndex":true,"flat":true,"flatMap":true,"includes":true,"keys":true,"values":true,"toReversed":true,"toSorted":true,"toSpliced":true}
|
||||
Symbol(foo)
|
||||
Symbol(foo)
|
@ -33,3 +33,7 @@ try {
|
||||
print("test Symbol.prototype.valueOf successful !!!");
|
||||
}
|
||||
print(JSON.stringify(Array.prototype[Symbol.unscopables]));
|
||||
|
||||
print(Symbol('foo').toString());
|
||||
|
||||
print(Symbol.for("foo").toString());
|
Loading…
Reference in New Issue
Block a user