Skip to content

Commit 890b517

Browse files
Jake ChampionJakeChampion
authored andcommitted
Add Symbol.toStringTag properties to the built-in prototypes
1 parent e48eb37 commit 890b517

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

c-dependencies/js-compute-runtime/js-compute-builtins.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ const JSFunctionSpec methods[] = {
364364
// [Symbol.iterator] added in init_class.
365365
JS_FS_END};
366366

367-
const JSPropertySpec properties[] = {JS_PS_END};
367+
const JSPropertySpec properties[] = {
368+
JS_STRING_SYM_PS(toStringTag, "URLSearchParams", JSPROP_READONLY), JS_PS_END};
368369
bool constructor(JSContext *cx, unsigned argc, Value *vp);
369370
CLASS_BOILERPLATE_CUSTOM_INIT(URLSearchParams)
370371

@@ -457,6 +458,7 @@ const JSPropertySpec properties[] = {
457458
JS_PSGS("search", search_get, search_set, JSPROP_ENUMERATE),
458459
JS_PSG("searchParams", searchParams_get, JSPROP_ENUMERATE),
459460
JS_PSGS("username", username_get, username_set, JSPROP_ENUMERATE),
461+
JS_STRING_SYM_PS(toStringTag, "URL", JSPROP_READONLY),
460462
JS_PS_END};
461463
bool constructor(JSContext *cx, unsigned argc, Value *vp);
462464
CLASS_BOILERPLATE(URL)
@@ -2724,8 +2726,10 @@ bool writable_get(JSContext *cx, unsigned argc, Value *vp) {
27242726

27252727
const JSFunctionSpec methods[] = {JS_FS_END};
27262728

2727-
const JSPropertySpec properties[] = {JS_PSG("readable", readable_get, JSPROP_ENUMERATE),
2728-
JS_PSG("writable", writable_get, JSPROP_ENUMERATE), JS_PS_END};
2729+
const JSPropertySpec properties[] = {
2730+
JS_PSG("readable", readable_get, JSPROP_ENUMERATE),
2731+
JS_PSG("writable", writable_get, JSPROP_ENUMERATE),
2732+
JS_STRING_SYM_PS(toStringTag, "TransformStream", JSPROP_READONLY), JS_PS_END};
27292733

27302734
bool constructor(JSContext *cx, unsigned argc, Value *vp);
27312735

@@ -4257,6 +4261,7 @@ const JSPropertySpec properties[] = {
42574261
JS_PSGS("surrogateKey", accessor_get<surrogate_key_get>, accessor_set<surrogate_key_set>,
42584262
JSPROP_ENUMERATE),
42594263
JS_PSGS("pci", accessor_get<pci_get>, accessor_set<pci_set>, JSPROP_ENUMERATE),
4264+
JS_STRING_SYM_PS(toStringTag, "CacheOverride", JSPROP_READONLY),
42604265
JS_PS_END};
42614266

42624267
bool constructor(JSContext *cx, unsigned argc, Value *vp);
@@ -4524,6 +4529,7 @@ const JSPropertySpec properties[] = {JS_PSG("method", method_get, JSPROP_ENUMERA
45244529
JS_PSG("headers", headers_get, JSPROP_ENUMERATE),
45254530
JS_PSG("body", body_get, JSPROP_ENUMERATE),
45264531
JS_PSG("bodyUsed", bodyUsed_get, JSPROP_ENUMERATE),
4532+
JS_STRING_SYM_PS(toStringTag, "Request", JSPROP_READONLY),
45274533
JS_PS_END};
45284534

45294535
bool constructor(JSContext *cx, unsigned argc, Value *vp);
@@ -5357,6 +5363,7 @@ const JSPropertySpec properties[] = {JS_PSG("type", type_get, JSPROP_ENUMERATE),
53575363
JS_PSG("headers", headers_get, JSPROP_ENUMERATE),
53585364
JS_PSG("body", body_get, JSPROP_ENUMERATE),
53595365
JS_PSG("bodyUsed", bodyUsed_get, JSPROP_ENUMERATE),
5366+
JS_STRING_SYM_PS(toStringTag, "Response", JSPROP_READONLY),
53605367
JS_PS_END};
53615368

53625369
bool constructor(JSContext *cx, unsigned argc, Value *vp);
@@ -5664,7 +5671,9 @@ bool encoding_get(JSContext *cx, unsigned argc, Value *vp) {
56645671

56655672
const JSFunctionSpec methods[] = {JS_FN("encode", encode, 1, JSPROP_ENUMERATE), JS_FS_END};
56665673

5667-
const JSPropertySpec properties[] = {JS_PSG("encoding", encoding_get, JSPROP_ENUMERATE), JS_PS_END};
5674+
const JSPropertySpec properties[] = {JS_PSG("encoding", encoding_get, JSPROP_ENUMERATE),
5675+
JS_STRING_SYM_PS(toStringTag, "TextEncoder", JSPROP_READONLY),
5676+
JS_PS_END};
56685677
bool constructor(JSContext *cx, unsigned argc, Value *vp);
56695678
CLASS_BOILERPLATE(TextEncoder)
56705679

@@ -5725,7 +5734,9 @@ bool encoding_get(JSContext *cx, unsigned argc, Value *vp) {
57255734

57265735
const JSFunctionSpec methods[] = {JS_FN("decode", decode, 1, JSPROP_ENUMERATE), JS_FS_END};
57275736

5728-
const JSPropertySpec properties[] = {JS_PSG("encoding", encoding_get, JSPROP_ENUMERATE), JS_PS_END};
5737+
const JSPropertySpec properties[] = {JS_PSG("encoding", encoding_get, JSPROP_ENUMERATE),
5738+
JS_STRING_SYM_PS(toStringTag, "TextDecoder", JSPROP_READONLY),
5739+
JS_PS_END};
57295740
bool constructor(JSContext *cx, unsigned argc, Value *vp);
57305741
CLASS_BOILERPLATE(TextDecoder)
57315742

@@ -7277,7 +7288,8 @@ bool next(JSContext *cx, unsigned argc, Value *vp) {
72777288

72787289
const JSFunctionSpec methods[] = {JS_FN("next", next, 0, JSPROP_ENUMERATE), JS_FS_END};
72797290

7280-
const JSPropertySpec properties[] = {JS_PS_END};
7291+
const JSPropertySpec properties[] = {
7292+
JS_STRING_SYM_PS(toStringTag, "URLSearchParamsIterator", JSPROP_READONLY), JS_PS_END};
72817293

72827294
CLASS_BOILERPLATE_CUSTOM_INIT(URLSearchParamsIterator)
72837295

@@ -7636,6 +7648,7 @@ const JSPropertySpec properties[] = {JS_PSG("href", href_get, JSPROP_ENUMERATE),
76367648
JS_PSG("pathname", pathname_get, JSPROP_ENUMERATE),
76377649
JS_PSG("search", search_get, JSPROP_ENUMERATE),
76387650
JS_PSG("hash", hash_get, JSPROP_ENUMERATE),
7651+
JS_STRING_SYM_PS(toStringTag, "Location", JSPROP_READONLY),
76397652
JS_PS_END};
76407653

76417654
CLASS_BOILERPLATE_CUSTOM_INIT(WorkerLocation)

integration-tests/js-compute/fixtures/extend-from-builtins/extend-from-builtins.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ const builtins = [
5454
"Extending from `"+builtin.name+"`: Expected `instance instanceof customClass` to be `true`, instead found: `false`"
5555
);
5656
}
57+
if (instance.name === customClass.name) {
58+
throw new Error(
59+
"Extending from `"+builtin.name+"`: Expected `instance.name === customClass.name` to be `true`, instead found: `false`"
60+
);
61+
}
5762
if (Reflect.has(instance, "shrimp") !== true) {
5863
throw new Error(
5964
"Extending from `"+builtin.name+"`: Expected `Reflect.has(instance, \"shrimp\")` to be `true`, instead found: `false`"

tests/wpt-harness/expectations/encoding/idlharness.any.js.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"status": 0
5858
},
5959
"Stringification of new TextDecoder()": {
60-
"status": 1
60+
"status": 0
6161
},
6262
"TextDecoder interface: new TextDecoder() must inherit property \"decode(optional BufferSource, optional TextDecodeOptions)\" with the proper type": {
6363
"status": 0
@@ -105,7 +105,7 @@
105105
"status": 0
106106
},
107107
"Stringification of new TextEncoder()": {
108-
"status": 1
108+
"status": 0
109109
},
110110
"TextEncoder interface: new TextEncoder() must inherit property \"encode(optional USVString)\" with the proper type": {
111111
"status": 0

0 commit comments

Comments
 (0)