Skip to content

Commit e285a57

Browse files
ntkmeCommit Queue
authored and
Commit Queue
committed
[dart2js] Fix compatiblity with Node.js 21
Closes #53796 GitOrigin-RevId: caeeb52 Change-Id: I145ecca62875a82f348ce1ea78fb935880d10688 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330987 Reviewed-by: Stephen Adams <sra@google.com> Commit-Queue: Stephen Adams <sra@google.com>
1 parent 79981f2 commit e285a57

File tree

2 files changed

+159
-9
lines changed

2 files changed

+159
-9
lines changed

pkg/compiler/test/dump_info/data/js_members.dart

+145-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,148 @@
1-
/*library:
1+
/*spec.library:
2+
constant=[
3+
{
4+
"id": "constant/B.C_JS_CONST = function getTagFallback(o) {\n var s = Object.prototype.toString.call(o);\n return s.substring(8, s.length - 1);\n};\n",
5+
"kind": "constant",
6+
"name": "",
7+
"size": 131,
8+
"outputUnit": "outputUnit/main",
9+
"code": "B.C_JS_CONST = function getTagFallback(o) {\n var s = Object.prototype.toString.call(o);\n return s.substring(8, s.length - 1);\n};\n"
10+
},
11+
{
12+
"id": "constant/B.C_JS_CONST0 = function() {\n var toStringFunction = Object.prototype.toString;\n function getTag(o) {\n var s = toStringFunction.call(o);\n return s.substring(8, s.length - 1);\n }\n function getUnknownTag(object, tag) {\n if (/^HTML[A-Z].*Element$/.test(tag)) {\n var name = toStringFunction.call(object);\n if (name == \"[object Object]\") return null;\n return \"HTMLElement\";\n }\n }\n function getUnknownTagGenericBrowser(object, tag) {\n if (object instanceof HTMLElement) return \"HTMLElement\";\n return getUnknownTag(object, tag);\n }\n function prototypeForTag(tag) {\n if (typeof window == \"undefined\") return null;\n if (typeof window[tag] == \"undefined\") return null;\n var constructor = window[tag];\n if (typeof constructor != \"function\") return null;\n return constructor.prototype;\n }\n function discriminator(tag) { return null; }\n var isBrowser = typeof HTMLElement == \"function\";\n return {\n getTag: getTag,\n getUnknownTag: isBrowser ? getUnknownTagGenericBrowser : getUnknownTag,\n prototypeForTag: prototypeForTag,\n discriminator: discriminator };\n};\n",
13+
"kind": "constant",
14+
"name": "",
15+
"size": 1117,
16+
"outputUnit": "outputUnit/main",
17+
"code": "B.C_JS_CONST0 = function() {\n var toStringFunction = Object.prototype.toString;\n function getTag(o) {\n var s = toStringFunction.call(o);\n return s.substring(8, s.length - 1);\n }\n function getUnknownTag(object, tag) {\n if (/^HTML[A-Z].*Element$/.test(tag)) {\n var name = toStringFunction.call(object);\n if (name == \"[object Object]\") return null;\n return \"HTMLElement\";\n }\n }\n function getUnknownTagGenericBrowser(object, tag) {\n if (object instanceof HTMLElement) return \"HTMLElement\";\n return getUnknownTag(object, tag);\n }\n function prototypeForTag(tag) {\n if (typeof window == \"undefined\") return null;\n if (typeof window[tag] == \"undefined\") return null;\n var constructor = window[tag];\n if (typeof constructor != \"function\") return null;\n return constructor.prototype;\n }\n function discriminator(tag) { return null; }\n var isBrowser = typeof HTMLElement == \"function\";\n return {\n getTag: getTag,\n getUnknownTag: isBrowser ? getUnknownTagGenericBrowser : getUnknownTag,\n prototypeForTag: prototypeForTag,\n discriminator: discriminator };\n};\n"
18+
},
19+
{
20+
"id": "constant/B.C_JS_CONST1 = function(hooks) {\n if (typeof dartExperimentalFixupGetTag != \"function\") return hooks;\n hooks.getTag = dartExperimentalFixupGetTag(hooks.getTag);\n};\n",
21+
"kind": "constant",
22+
"name": "",
23+
"size": 167,
24+
"outputUnit": "outputUnit/main",
25+
"code": "B.C_JS_CONST1 = function(hooks) {\n if (typeof dartExperimentalFixupGetTag != \"function\") return hooks;\n hooks.getTag = dartExperimentalFixupGetTag(hooks.getTag);\n};\n"
26+
},
27+
{
28+
"id": "constant/B.C_JS_CONST2 = function(hooks) {\n var getTag = hooks.getTag;\n var prototypeForTag = hooks.prototypeForTag;\n function getTagFixed(o) {\n var tag = getTag(o);\n if (tag == \"Document\") {\n if (!!o.xmlVersion) return \"!Document\";\n return \"!HTMLDocument\";\n }\n return tag;\n }\n function prototypeForTagFixed(tag) {\n if (tag == \"Document\") return null;\n return prototypeForTag(tag);\n }\n hooks.getTag = getTagFixed;\n hooks.prototypeForTag = prototypeForTagFixed;\n};\n",
29+
"kind": "constant",
30+
"name": "",
31+
"size": 491,
32+
"outputUnit": "outputUnit/main",
33+
"code": "B.C_JS_CONST2 = function(hooks) {\n var getTag = hooks.getTag;\n var prototypeForTag = hooks.prototypeForTag;\n function getTagFixed(o) {\n var tag = getTag(o);\n if (tag == \"Document\") {\n if (!!o.xmlVersion) return \"!Document\";\n return \"!HTMLDocument\";\n }\n return tag;\n }\n function prototypeForTagFixed(tag) {\n if (tag == \"Document\") return null;\n return prototypeForTag(tag);\n }\n hooks.getTag = getTagFixed;\n hooks.prototypeForTag = prototypeForTagFixed;\n};\n"
34+
},
35+
{
36+
"id": "constant/B.C_JS_CONST3 = function(hooks) { return hooks; }\n;\n",
37+
"kind": "constant",
38+
"name": "",
39+
"size": 52,
40+
"outputUnit": "outputUnit/main",
41+
"code": "B.C_JS_CONST3 = function(hooks) { return hooks; }\n;\n"
42+
},
43+
{
44+
"id": "constant/B.C_JS_CONST4 = function(hooks) {\n if (typeof navigator != \"object\") return hooks;\n var userAgent = navigator.userAgent;\n if (typeof userAgent != \"string\") return hooks;\n if (userAgent.indexOf(\"Trident/\") == -1) return hooks;\n var getTag = hooks.getTag;\n var quickMap = {\n \"BeforeUnloadEvent\": \"Event\",\n \"DataTransfer\": \"Clipboard\",\n \"HTMLDDElement\": \"HTMLElement\",\n \"HTMLDTElement\": \"HTMLElement\",\n \"HTMLPhraseElement\": \"HTMLElement\",\n \"Position\": \"Geoposition\"\n };\n function getTagIE(o) {\n var tag = getTag(o);\n var newTag = quickMap[tag];\n if (newTag) return newTag;\n if (tag == \"Object\") {\n if (window.DataView && (o instanceof window.DataView)) return \"DataView\";\n }\n return tag;\n }\n function prototypeForTagIE(tag) {\n var constructor = window[tag];\n if (constructor == null) return null;\n return constructor.prototype;\n }\n hooks.getTag = getTagIE;\n hooks.prototypeForTag = prototypeForTagIE;\n};\n",
45+
"kind": "constant",
46+
"name": "",
47+
"size": 964,
48+
"outputUnit": "outputUnit/main",
49+
"code": "B.C_JS_CONST4 = function(hooks) {\n if (typeof navigator != \"object\") return hooks;\n var userAgent = navigator.userAgent;\n if (typeof userAgent != \"string\") return hooks;\n if (userAgent.indexOf(\"Trident/\") == -1) return hooks;\n var getTag = hooks.getTag;\n var quickMap = {\n \"BeforeUnloadEvent\": \"Event\",\n \"DataTransfer\": \"Clipboard\",\n \"HTMLDDElement\": \"HTMLElement\",\n \"HTMLDTElement\": \"HTMLElement\",\n \"HTMLPhraseElement\": \"HTMLElement\",\n \"Position\": \"Geoposition\"\n };\n function getTagIE(o) {\n var tag = getTag(o);\n var newTag = quickMap[tag];\n if (newTag) return newTag;\n if (tag == \"Object\") {\n if (window.DataView && (o instanceof window.DataView)) return \"DataView\";\n }\n return tag;\n }\n function prototypeForTagIE(tag) {\n var constructor = window[tag];\n if (constructor == null) return null;\n return constructor.prototype;\n }\n hooks.getTag = getTagIE;\n hooks.prototypeForTag = prototypeForTagIE;\n};\n"
50+
},
51+
{
52+
"id": "constant/B.C_JS_CONST5 = function(hooks) {\n if (typeof navigator != \"object\") return hooks;\n var userAgent = navigator.userAgent;\n if (typeof userAgent != \"string\") return hooks;\n if (userAgent.indexOf(\"Firefox\") == -1) return hooks;\n var getTag = hooks.getTag;\n var quickMap = {\n \"BeforeUnloadEvent\": \"Event\",\n \"DataTransfer\": \"Clipboard\",\n \"GeoGeolocation\": \"Geolocation\",\n \"Location\": \"!Location\",\n \"WorkerMessageEvent\": \"MessageEvent\",\n \"XMLDocument\": \"!Document\"};\n function getTagFirefox(o) {\n var tag = getTag(o);\n return quickMap[tag] || tag;\n }\n hooks.getTag = getTagFirefox;\n};\n",
53+
"kind": "constant",
54+
"name": "",
55+
"size": 612,
56+
"outputUnit": "outputUnit/main",
57+
"code": "B.C_JS_CONST5 = function(hooks) {\n if (typeof navigator != \"object\") return hooks;\n var userAgent = navigator.userAgent;\n if (typeof userAgent != \"string\") return hooks;\n if (userAgent.indexOf(\"Firefox\") == -1) return hooks;\n var getTag = hooks.getTag;\n var quickMap = {\n \"BeforeUnloadEvent\": \"Event\",\n \"DataTransfer\": \"Clipboard\",\n \"GeoGeolocation\": \"Geolocation\",\n \"Location\": \"!Location\",\n \"WorkerMessageEvent\": \"MessageEvent\",\n \"XMLDocument\": \"!Document\"};\n function getTagFirefox(o) {\n var tag = getTag(o);\n return quickMap[tag] || tag;\n }\n hooks.getTag = getTagFirefox;\n};\n"
58+
},
59+
{
60+
"id": "constant/B.C_JS_CONST6 = function(getTagFallback) {\n return function(hooks) {\n if (typeof navigator != \"object\") return hooks;\n var userAgent = navigator.userAgent;\n if (typeof userAgent != \"string\") return hooks;\n if (userAgent.indexOf(\"DumpRenderTree\") >= 0) return hooks;\n if (userAgent.indexOf(\"Chrome\") >= 0) {\n function confirm(p) {\n return typeof window == \"object\" && window[p] && window[p].name == p;\n }\n if (confirm(\"Window\") && confirm(\"HTMLElement\")) return hooks;\n }\n hooks.getTag = getTagFallback;\n };\n};\n",
61+
"kind": "constant",
62+
"name": "",
63+
"size": 555,
64+
"outputUnit": "outputUnit/main",
65+
"code": "B.C_JS_CONST6 = function(getTagFallback) {\n return function(hooks) {\n if (typeof navigator != \"object\") return hooks;\n var userAgent = navigator.userAgent;\n if (typeof userAgent != \"string\") return hooks;\n if (userAgent.indexOf(\"DumpRenderTree\") >= 0) return hooks;\n if (userAgent.indexOf(\"Chrome\") >= 0) {\n function confirm(p) {\n return typeof window == \"object\" && window[p] && window[p].name == p;\n }\n if (confirm(\"Window\") && confirm(\"HTMLElement\")) return hooks;\n }\n hooks.getTag = getTagFallback;\n };\n};\n"
66+
},
67+
{
68+
"id": "constant/B.Interceptor_methods = J.Interceptor.prototype;\n",
69+
"kind": "constant",
70+
"name": "",
71+
"size": 49,
72+
"outputUnit": "outputUnit/main",
73+
"code": "B.Interceptor_methods = J.Interceptor.prototype;\n"
74+
},
75+
{
76+
"id": "constant/B.JSArray_methods = J.JSArray.prototype;\n",
77+
"kind": "constant",
78+
"name": "",
79+
"size": 41,
80+
"outputUnit": "outputUnit/main",
81+
"code": "B.JSArray_methods = J.JSArray.prototype;\n"
82+
},
83+
{
84+
"id": "constant/B.JSString_methods = J.JSString.prototype;\n",
85+
"kind": "constant",
86+
"name": "",
87+
"size": 43,
88+
"outputUnit": "outputUnit/main",
89+
"code": "B.JSString_methods = J.JSString.prototype;\n"
90+
},
91+
{
92+
"id": "constant/B.JavaScriptFunction_methods = J.JavaScriptFunction.prototype;\n",
93+
"kind": "constant",
94+
"name": "",
95+
"size": 63,
96+
"outputUnit": "outputUnit/main",
97+
"code": "B.JavaScriptFunction_methods = J.JavaScriptFunction.prototype;\n"
98+
},
99+
{
100+
"id": "constant/B.JavaScriptObject_methods = J.JavaScriptObject.prototype;\n",
101+
"kind": "constant",
102+
"name": "",
103+
"size": 59,
104+
"outputUnit": "outputUnit/main",
105+
"code": "B.JavaScriptObject_methods = J.JavaScriptObject.prototype;\n"
106+
},
107+
{
108+
"id": "constant/B.PlainJavaScriptObject_methods = J.PlainJavaScriptObject.prototype;\n",
109+
"kind": "constant",
110+
"name": "",
111+
"size": 69,
112+
"outputUnit": "outputUnit/main",
113+
"code": "B.PlainJavaScriptObject_methods = J.PlainJavaScriptObject.prototype;\n"
114+
},
115+
{
116+
"id": "constant/B.UnknownJavaScriptObject_methods = J.UnknownJavaScriptObject.prototype;\n",
117+
"kind": "constant",
118+
"name": "",
119+
"size": 73,
120+
"outputUnit": "outputUnit/main",
121+
"code": "B.UnknownJavaScriptObject_methods = J.UnknownJavaScriptObject.prototype;\n"
122+
}],
123+
deferredFiles=[{}],
124+
dependencies=[{}],
125+
library=[{
126+
"id": "library/memory:sdk/tests/web/native/main.dart::",
127+
"kind": "library",
128+
"name": "js_parameters_test",
129+
"size": 1891,
130+
"children": [
131+
"class/memory:sdk/tests/web/native/main.dart::Bar",
132+
"class/memory:sdk/tests/web/native/main.dart::Foo",
133+
"function/memory:sdk/tests/web/native/main.dart::main"
134+
],
135+
"canonicalUri": "memory:sdk/tests/web/native/main.dart"
136+
}],
137+
outputUnits=[{
138+
"id": "outputUnit/main",
139+
"kind": "outputUnit",
140+
"name": "main",
141+
"filename": "out",
142+
"imports": []
143+
}]
144+
*/
145+
/*kernel.library:
2146
constant=[
3147
{
4148
"id": "constant/B.C_JS_CONST = function getTagFallback(o) {\n var s = Object.prototype.toString.call(o);\n return s.substring(8, s.length - 1);\n};\n",

sdk/lib/_internal/js_runtime/lib/native_helper.dart

+14-8
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ function() {
437437
}
438438
}
439439
function getUnknownTagGenericBrowser(object, tag) {
440-
if (self.HTMLElement && object instanceof HTMLElement) return "HTMLElement";
440+
if (object instanceof HTMLElement) return "HTMLElement";
441441
return getUnknownTag(object, tag);
442442
}
443443
function prototypeForTag(tag) {
@@ -449,7 +449,9 @@ function() {
449449
}
450450
function discriminator(tag) { return null; }
451451
452-
var isBrowser = typeof navigator == "object";
452+
// The difference for a browser here is that HTMLElement gets special
453+
// treatment in [getUnknownTagGenericBrowser].
454+
var isBrowser = typeof HTMLElement == "function";
453455
454456
return {
455457
getTag: getTag,
@@ -476,11 +478,11 @@ function(getTagFallback) {
476478
// If we are not in a browser, assume we are in d8.
477479
// TODO(sra): Recognize jsshell.
478480
if (typeof navigator != "object") return hooks;
479-
480-
var ua = navigator.userAgent;
481+
var userAgent = navigator.userAgent;
482+
if (typeof userAgent != "string") return hooks;
481483
// TODO(antonm): remove a reference to DumpRenderTree.
482-
if (ua.indexOf("DumpRenderTree") >= 0) return hooks;
483-
if (ua.indexOf("Chrome") >= 0) {
484+
if (userAgent.indexOf("DumpRenderTree") >= 0) return hooks;
485+
if (userAgent.indexOf("Chrome") >= 0) {
484486
// Confirm constructor name is usable for dispatch.
485487
function confirm(p) {
486488
return typeof window == "object" && window[p] && window[p].name == p;
@@ -494,7 +496,9 @@ function(getTagFallback) {
494496

495497
const _ieHooksTransformer = const JS_CONST(r'''
496498
function(hooks) {
497-
var userAgent = typeof navigator == "object" ? navigator.userAgent : "";
499+
if (typeof navigator != "object") return hooks;
500+
var userAgent = navigator.userAgent;
501+
if (typeof userAgent != "string") return hooks;
498502
if (userAgent.indexOf("Trident/") == -1) return hooks;
499503
500504
var getTag = hooks.getTag;
@@ -558,7 +562,9 @@ function(hooks) {
558562

559563
const _firefoxHooksTransformer = const JS_CONST(r'''
560564
function(hooks) {
561-
var userAgent = typeof navigator == "object" ? navigator.userAgent : "";
565+
if (typeof navigator != "object") return hooks;
566+
var userAgent = navigator.userAgent;
567+
if (typeof userAgent != "string") return hooks;
562568
if (userAgent.indexOf("Firefox") == -1) return hooks;
563569
564570
var getTag = hooks.getTag;

0 commit comments

Comments
 (0)