@@ -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
{
@@ -39362,7 +39368,7 @@ static JSValue js_function_bind(JSContext *ctx, JSValueConst this_val,
39362
39368
goto exception;
39363
39369
if (!JS_IsString(name1)) {
39364
39370
JS_FreeValue(ctx, name1);
39365
- name1 = JS_AtomToString (ctx, JS_ATOM_empty_string );
39371
+ name1 = js_empty_string (ctx->rt );
39366
39372
}
39367
39373
name1 = JS_ConcatString3(ctx, "bound ", name1, "");
39368
39374
if (JS_IsException(name1))
@@ -39413,7 +39419,7 @@ static JSValue js_function_toString(JSContext *ctx, JSValueConst this_val,
39413
39419
suff = "() {\n [native code]\n}";
39414
39420
name = JS_GetProperty(ctx, this_val, JS_ATOM_name);
39415
39421
if (JS_IsUndefined(name))
39416
- name = JS_AtomToString (ctx, JS_ATOM_empty_string );
39422
+ name = js_empty_string (ctx->rt );
39417
39423
return JS_ConcatString3(ctx, pref, name, suff);
39418
39424
}
39419
39425
}
@@ -39575,7 +39581,7 @@ static JSValue js_error_toString(JSContext *ctx, JSValueConst this_val,
39575
39581
39576
39582
msg = JS_GetProperty(ctx, this_val, JS_ATOM_message);
39577
39583
if (JS_IsUndefined(msg))
39578
- msg = JS_AtomToString (ctx, JS_ATOM_empty_string );
39584
+ msg = js_empty_string (ctx->rt );
39579
39585
else
39580
39586
msg = JS_ToStringFree(ctx, msg);
39581
39587
if (JS_IsException(msg)) {
@@ -43051,7 +43057,7 @@ static JSValue js_string_constructor(JSContext *ctx, JSValueConst new_target,
43051
43057
{
43052
43058
JSValue val, obj;
43053
43059
if (argc == 0) {
43054
- val = JS_AtomToString (ctx, JS_ATOM_empty_string );
43060
+ val = js_empty_string (ctx->rt );
43055
43061
} else {
43056
43062
if (JS_IsUndefined(new_target) && JS_IsSymbol(argv[0])) {
43057
43063
JSAtomStruct *p = JS_VALUE_GET_PTR(argv[0]);
@@ -43301,7 +43307,7 @@ static JSValue js_string_charAt(JSContext *ctx, JSValueConst this_val,
43301
43307
return JS_EXCEPTION;
43302
43308
}
43303
43309
if (idx < 0 || idx >= p->len) {
43304
- ret = JS_AtomToString (ctx, JS_ATOM_empty_string );
43310
+ ret = js_empty_string (ctx->rt );
43305
43311
} else {
43306
43312
c = string_get(p, idx);
43307
43313
ret = js_new_string_char(ctx, c);
@@ -45331,7 +45337,7 @@ static JSValue js_regexp_constructor(JSContext *ctx, JSValueConst new_target,
45331
45337
flags = js_dup(flags1);
45332
45338
}
45333
45339
if (JS_IsUndefined(pattern)) {
45334
- pattern = JS_AtomToString (ctx, JS_ATOM_empty_string );
45340
+ pattern = js_empty_string (ctx->rt );
45335
45341
} else {
45336
45342
val = pattern;
45337
45343
pattern = JS_ToString(ctx, val);
@@ -45373,7 +45379,7 @@ static JSValue js_regexp_compile(JSContext *ctx, JSValueConst this_val,
45373
45379
} else {
45374
45380
bc = JS_UNDEFINED;
45375
45381
if (JS_IsUndefined(pattern1))
45376
- pattern = JS_AtomToString (ctx, JS_ATOM_empty_string );
45382
+ pattern = js_empty_string (ctx->rt );
45377
45383
else
45378
45384
pattern = JS_ToString(ctx, pattern1);
45379
45385
if (JS_IsException(pattern))
@@ -45531,7 +45537,7 @@ static JSValue js_regexp_get_flags(JSContext *ctx, JSValueConst this_val)
45531
45537
if (res)
45532
45538
*p++ = 'y';
45533
45539
if (p == str)
45534
- return JS_AtomToString (ctx, JS_ATOM_empty_string );
45540
+ return js_empty_string (ctx->rt );
45535
45541
return js_new_string8_len(ctx, str, p - str);
45536
45542
45537
45543
exception:
@@ -47256,7 +47262,7 @@ JSValue JS_JSONStringify(JSContext *ctx, JSValueConst obj,
47256
47262
jsc->property_list = JS_UNDEFINED;
47257
47263
jsc->gap = JS_UNDEFINED;
47258
47264
jsc->b = &b_s;
47259
- jsc->empty = JS_AtomToString (ctx, JS_ATOM_empty_string );
47265
+ jsc->empty = js_empty_string (ctx->rt );
47260
47266
ret = JS_UNDEFINED;
47261
47267
wrapper = JS_UNDEFINED;
47262
47268
@@ -52300,7 +52306,7 @@ static JSValue get_date_string(JSContext *ctx, JSValueConst this_val,
52300
52306
}
52301
52307
if (!pos) {
52302
52308
// XXX: should throw exception?
52303
- return JS_AtomToString (ctx, JS_ATOM_empty_string );
52309
+ return js_empty_string (ctx->rt );
52304
52310
}
52305
52311
return js_new_string8_len(ctx, buf, pos);
52306
52312
}
@@ -53320,7 +53326,7 @@ static void JS_AddIntrinsicBasicObjects(JSContext *ctx)
53320
53326
JS_NewAtomString(ctx, native_error_name[i]),
53321
53327
JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);
53322
53328
JS_DefinePropertyValue(ctx, proto, JS_ATOM_message,
53323
- JS_AtomToString (ctx, JS_ATOM_empty_string ),
53329
+ js_empty_string (ctx->rt ),
53324
53330
JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);
53325
53331
ctx->native_error_proto[i] = proto;
53326
53332
}
@@ -53515,7 +53521,7 @@ void JS_AddIntrinsicBaseObjects(JSContext *ctx)
53515
53521
/* String */
53516
53522
ctx->class_proto[JS_CLASS_STRING] = JS_NewObjectProtoClass(ctx, ctx->class_proto[JS_CLASS_OBJECT],
53517
53523
JS_CLASS_STRING);
53518
- JS_SetObjectData(ctx, ctx->class_proto[JS_CLASS_STRING], JS_AtomToString (ctx, JS_ATOM_empty_string ));
53524
+ JS_SetObjectData(ctx, ctx->class_proto[JS_CLASS_STRING], js_empty_string (ctx->rt ));
53519
53525
obj = JS_NewGlobalCConstructor(ctx, "String", js_string_constructor, 1,
53520
53526
ctx->class_proto[JS_CLASS_STRING]);
53521
53527
JS_SetPropertyFunctionList(ctx, obj, js_string_funcs,
@@ -57838,7 +57844,7 @@ static JSValue js_domexception_constructor0(JSContext *ctx, JSValueConst new_tar
57838
57844
if (!JS_IsUndefined(argv[0]))
57839
57845
message = JS_ToString(ctx, argv[0]);
57840
57846
else
57841
- message = JS_AtomToString (ctx, JS_ATOM_empty_string );
57847
+ message = js_empty_string (ctx->rt );
57842
57848
if (JS_IsException(message))
57843
57849
goto fail1;
57844
57850
if (!JS_IsUndefined(argv[1]))
0 commit comments