@@ -3622,6 +3622,12 @@ int JS_NewClass(JSRuntime *rt, JSClassID class_id, const JSClassDef *class_def)
3622
3622
return ret;
3623
3623
}
3624
3624
3625
+ static inline JSValue js_empty_string(JSRuntime *rt)
3626
+ {
3627
+ JSAtomStruct *p = rt->atom_array[JS_ATOM_empty_string];
3628
+ return js_dup(JS_MKPTR(JS_TAG_STRING, p));
3629
+ }
3630
+
3625
3631
// XXX: `buf` contains raw 8-bit data, no UTF-8 decoding is performed
3626
3632
// XXX: no special case for len == 0
3627
3633
static JSValue js_new_string8_len(JSContext *ctx, const char *buf, int len)
@@ -3670,7 +3676,7 @@ static JSValue js_sub_string(JSContext *ctx, JSString *p, int start, int end)
3670
3676
return js_dup(JS_MKPTR(JS_TAG_STRING, p));
3671
3677
}
3672
3678
if (len <= 0) {
3673
- return JS_AtomToString (ctx, JS_ATOM_empty_string );
3679
+ return js_empty_string (ctx->rt );
3674
3680
}
3675
3681
if (p->is_wide_char) {
3676
3682
JSString *str;
@@ -4007,7 +4013,7 @@ static JSValue string_buffer_end(StringBuffer *s)
4007
4013
if (s->len == 0) {
4008
4014
js_free(s->ctx, str);
4009
4015
s->str = NULL;
4010
- return JS_AtomToString (s->ctx, JS_ATOM_empty_string );
4016
+ return js_empty_string (s->ctx->rt );
4011
4017
}
4012
4018
if (s->len < s->size) {
4013
4019
/* smaller size so js_realloc should not fail, but OK if it does */
@@ -4038,7 +4044,7 @@ JSValue JS_NewStringLen(JSContext *ctx, const char *buf, size_t buf_len)
4038
4044
int kind;
4039
4045
4040
4046
if (buf_len <= 0) {
4041
- return JS_AtomToString (ctx, JS_ATOM_empty_string );
4047
+ return js_empty_string (ctx->rt );
4042
4048
}
4043
4049
/* Compute string kind and length: 7-bit, 8-bit, 16-bit, 16-bit UTF-16 */
4044
4050
kind = utf8_scan(buf, buf_len, &len);
@@ -4078,7 +4084,7 @@ JSValue JS_NewTwoByteString(JSContext *ctx, const uint16_t *buf, size_t len)
4078
4084
JSString *str;
4079
4085
4080
4086
if (!len)
4081
- return JS_AtomToString (ctx, JS_ATOM_empty_string );
4087
+ return js_empty_string (ctx->rt );
4082
4088
str = js_alloc_string(ctx, len, 1);
4083
4089
if (!str)
4084
4090
return JS_EXCEPTION;
@@ -16614,7 +16620,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
16614
16620
goto exception;
16615
16621
BREAK;
16616
16622
CASE(OP_push_empty_string):
16617
- *sp++ = JS_AtomToString(ctx, JS_ATOM_empty_string );
16623
+ *sp++ = js_empty_string(rt );
16618
16624
BREAK;
16619
16625
CASE(OP_get_length):
16620
16626
{
@@ -39361,7 +39367,7 @@ static JSValue js_function_bind(JSContext *ctx, JSValueConst this_val,
39361
39367
goto exception;
39362
39368
if (!JS_IsString(name1)) {
39363
39369
JS_FreeValue(ctx, name1);
39364
- name1 = JS_AtomToString (ctx, JS_ATOM_empty_string );
39370
+ name1 = js_empty_string (ctx->rt );
39365
39371
}
39366
39372
name1 = JS_ConcatString3(ctx, "bound ", name1, "");
39367
39373
if (JS_IsException(name1))
@@ -39412,7 +39418,7 @@ static JSValue js_function_toString(JSContext *ctx, JSValueConst this_val,
39412
39418
suff = "() {\n [native code]\n}";
39413
39419
name = JS_GetProperty(ctx, this_val, JS_ATOM_name);
39414
39420
if (JS_IsUndefined(name))
39415
- name = JS_AtomToString (ctx, JS_ATOM_empty_string );
39421
+ name = js_empty_string (ctx->rt );
39416
39422
return JS_ConcatString3(ctx, pref, name, suff);
39417
39423
}
39418
39424
}
@@ -39574,7 +39580,7 @@ static JSValue js_error_toString(JSContext *ctx, JSValueConst this_val,
39574
39580
39575
39581
msg = JS_GetProperty(ctx, this_val, JS_ATOM_message);
39576
39582
if (JS_IsUndefined(msg))
39577
- msg = JS_AtomToString (ctx, JS_ATOM_empty_string );
39583
+ msg = js_empty_string (ctx->rt );
39578
39584
else
39579
39585
msg = JS_ToStringFree(ctx, msg);
39580
39586
if (JS_IsException(msg)) {
@@ -43050,7 +43056,7 @@ static JSValue js_string_constructor(JSContext *ctx, JSValueConst new_target,
43050
43056
{
43051
43057
JSValue val, obj;
43052
43058
if (argc == 0) {
43053
- val = JS_AtomToString (ctx, JS_ATOM_empty_string );
43059
+ val = js_empty_string (ctx->rt );
43054
43060
} else {
43055
43061
if (JS_IsUndefined(new_target) && JS_IsSymbol(argv[0])) {
43056
43062
JSAtomStruct *p = JS_VALUE_GET_PTR(argv[0]);
@@ -43300,7 +43306,7 @@ static JSValue js_string_charAt(JSContext *ctx, JSValueConst this_val,
43300
43306
return JS_EXCEPTION;
43301
43307
}
43302
43308
if (idx < 0 || idx >= p->len) {
43303
- ret = JS_AtomToString (ctx, JS_ATOM_empty_string );
43309
+ ret = js_empty_string (ctx->rt );
43304
43310
} else {
43305
43311
c = string_get(p, idx);
43306
43312
ret = js_new_string_char(ctx, c);
@@ -45330,7 +45336,7 @@ static JSValue js_regexp_constructor(JSContext *ctx, JSValueConst new_target,
45330
45336
flags = js_dup(flags1);
45331
45337
}
45332
45338
if (JS_IsUndefined(pattern)) {
45333
- pattern = JS_AtomToString (ctx, JS_ATOM_empty_string );
45339
+ pattern = js_empty_string (ctx->rt );
45334
45340
} else {
45335
45341
val = pattern;
45336
45342
pattern = JS_ToString(ctx, val);
@@ -45372,7 +45378,7 @@ static JSValue js_regexp_compile(JSContext *ctx, JSValueConst this_val,
45372
45378
} else {
45373
45379
bc = JS_UNDEFINED;
45374
45380
if (JS_IsUndefined(pattern1))
45375
- pattern = JS_AtomToString (ctx, JS_ATOM_empty_string );
45381
+ pattern = js_empty_string (ctx->rt );
45376
45382
else
45377
45383
pattern = JS_ToString(ctx, pattern1);
45378
45384
if (JS_IsException(pattern))
@@ -45530,7 +45536,7 @@ static JSValue js_regexp_get_flags(JSContext *ctx, JSValueConst this_val)
45530
45536
if (res)
45531
45537
*p++ = 'y';
45532
45538
if (p == str)
45533
- return JS_AtomToString (ctx, JS_ATOM_empty_string );
45539
+ return js_empty_string (ctx->rt );
45534
45540
return js_new_string8_len(ctx, str, p - str);
45535
45541
45536
45542
exception:
@@ -47255,7 +47261,7 @@ JSValue JS_JSONStringify(JSContext *ctx, JSValueConst obj,
47255
47261
jsc->property_list = JS_UNDEFINED;
47256
47262
jsc->gap = JS_UNDEFINED;
47257
47263
jsc->b = &b_s;
47258
- jsc->empty = JS_AtomToString (ctx, JS_ATOM_empty_string );
47264
+ jsc->empty = js_empty_string (ctx->rt );
47259
47265
ret = JS_UNDEFINED;
47260
47266
wrapper = JS_UNDEFINED;
47261
47267
@@ -52299,7 +52305,7 @@ static JSValue get_date_string(JSContext *ctx, JSValueConst this_val,
52299
52305
}
52300
52306
if (!pos) {
52301
52307
// XXX: should throw exception?
52302
- return JS_AtomToString (ctx, JS_ATOM_empty_string );
52308
+ return js_empty_string (ctx->rt );
52303
52309
}
52304
52310
return js_new_string8_len(ctx, buf, pos);
52305
52311
}
@@ -53319,7 +53325,7 @@ static void JS_AddIntrinsicBasicObjects(JSContext *ctx)
53319
53325
JS_NewAtomString(ctx, native_error_name[i]),
53320
53326
JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);
53321
53327
JS_DefinePropertyValue(ctx, proto, JS_ATOM_message,
53322
- JS_AtomToString (ctx, JS_ATOM_empty_string ),
53328
+ js_empty_string (ctx->rt ),
53323
53329
JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);
53324
53330
ctx->native_error_proto[i] = proto;
53325
53331
}
@@ -53514,7 +53520,7 @@ void JS_AddIntrinsicBaseObjects(JSContext *ctx)
53514
53520
/* String */
53515
53521
ctx->class_proto[JS_CLASS_STRING] = JS_NewObjectProtoClass(ctx, ctx->class_proto[JS_CLASS_OBJECT],
53516
53522
JS_CLASS_STRING);
53517
- JS_SetObjectData(ctx, ctx->class_proto[JS_CLASS_STRING], JS_AtomToString (ctx, JS_ATOM_empty_string ));
53523
+ JS_SetObjectData(ctx, ctx->class_proto[JS_CLASS_STRING], js_empty_string (ctx->rt ));
53518
53524
obj = JS_NewGlobalCConstructor(ctx, "String", js_string_constructor, 1,
53519
53525
ctx->class_proto[JS_CLASS_STRING]);
53520
53526
JS_SetPropertyFunctionList(ctx, obj, js_string_funcs,
0 commit comments