[dart2js] Fix compatiblity with Node.js 21

Closes https://github.com/dart-lang/sdk/pull/53796

GitOrigin-RevId: caeeb52bb832c401a22d7ba3410f42cb50d6c8c6
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>
This commit is contained in:
なつき 2023-10-19 03:46:18 +00:00 committed by Commit Queue
parent 79981f2f1b
commit e285a57248
2 changed files with 159 additions and 9 deletions

View file

@ -1,4 +1,148 @@
/*library:
/*spec.library:
constant=[
{
"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",
"kind": "constant",
"name": "",
"size": 131,
"outputUnit": "outputUnit/main",
"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"
},
{
"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",
"kind": "constant",
"name": "",
"size": 1117,
"outputUnit": "outputUnit/main",
"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"
},
{
"id": "constant/B.C_JS_CONST1 = function(hooks) {\n if (typeof dartExperimentalFixupGetTag != \"function\") return hooks;\n hooks.getTag = dartExperimentalFixupGetTag(hooks.getTag);\n};\n",
"kind": "constant",
"name": "",
"size": 167,
"outputUnit": "outputUnit/main",
"code": "B.C_JS_CONST1 = function(hooks) {\n if (typeof dartExperimentalFixupGetTag != \"function\") return hooks;\n hooks.getTag = dartExperimentalFixupGetTag(hooks.getTag);\n};\n"
},
{
"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",
"kind": "constant",
"name": "",
"size": 491,
"outputUnit": "outputUnit/main",
"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"
},
{
"id": "constant/B.C_JS_CONST3 = function(hooks) { return hooks; }\n;\n",
"kind": "constant",
"name": "",
"size": 52,
"outputUnit": "outputUnit/main",
"code": "B.C_JS_CONST3 = function(hooks) { return hooks; }\n;\n"
},
{
"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",
"kind": "constant",
"name": "",
"size": 964,
"outputUnit": "outputUnit/main",
"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"
},
{
"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",
"kind": "constant",
"name": "",
"size": 612,
"outputUnit": "outputUnit/main",
"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"
},
{
"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",
"kind": "constant",
"name": "",
"size": 555,
"outputUnit": "outputUnit/main",
"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"
},
{
"id": "constant/B.Interceptor_methods = J.Interceptor.prototype;\n",
"kind": "constant",
"name": "",
"size": 49,
"outputUnit": "outputUnit/main",
"code": "B.Interceptor_methods = J.Interceptor.prototype;\n"
},
{
"id": "constant/B.JSArray_methods = J.JSArray.prototype;\n",
"kind": "constant",
"name": "",
"size": 41,
"outputUnit": "outputUnit/main",
"code": "B.JSArray_methods = J.JSArray.prototype;\n"
},
{
"id": "constant/B.JSString_methods = J.JSString.prototype;\n",
"kind": "constant",
"name": "",
"size": 43,
"outputUnit": "outputUnit/main",
"code": "B.JSString_methods = J.JSString.prototype;\n"
},
{
"id": "constant/B.JavaScriptFunction_methods = J.JavaScriptFunction.prototype;\n",
"kind": "constant",
"name": "",
"size": 63,
"outputUnit": "outputUnit/main",
"code": "B.JavaScriptFunction_methods = J.JavaScriptFunction.prototype;\n"
},
{
"id": "constant/B.JavaScriptObject_methods = J.JavaScriptObject.prototype;\n",
"kind": "constant",
"name": "",
"size": 59,
"outputUnit": "outputUnit/main",
"code": "B.JavaScriptObject_methods = J.JavaScriptObject.prototype;\n"
},
{
"id": "constant/B.PlainJavaScriptObject_methods = J.PlainJavaScriptObject.prototype;\n",
"kind": "constant",
"name": "",
"size": 69,
"outputUnit": "outputUnit/main",
"code": "B.PlainJavaScriptObject_methods = J.PlainJavaScriptObject.prototype;\n"
},
{
"id": "constant/B.UnknownJavaScriptObject_methods = J.UnknownJavaScriptObject.prototype;\n",
"kind": "constant",
"name": "",
"size": 73,
"outputUnit": "outputUnit/main",
"code": "B.UnknownJavaScriptObject_methods = J.UnknownJavaScriptObject.prototype;\n"
}],
deferredFiles=[{}],
dependencies=[{}],
library=[{
"id": "library/memory:sdk/tests/web/native/main.dart::",
"kind": "library",
"name": "js_parameters_test",
"size": 1891,
"children": [
"class/memory:sdk/tests/web/native/main.dart::Bar",
"class/memory:sdk/tests/web/native/main.dart::Foo",
"function/memory:sdk/tests/web/native/main.dart::main"
],
"canonicalUri": "memory:sdk/tests/web/native/main.dart"
}],
outputUnits=[{
"id": "outputUnit/main",
"kind": "outputUnit",
"name": "main",
"filename": "out",
"imports": []
}]
*/
/*kernel.library:
constant=[
{
"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",

View file

@ -437,7 +437,7 @@ function() {
}
}
function getUnknownTagGenericBrowser(object, tag) {
if (self.HTMLElement && object instanceof HTMLElement) return "HTMLElement";
if (object instanceof HTMLElement) return "HTMLElement";
return getUnknownTag(object, tag);
}
function prototypeForTag(tag) {
@ -449,7 +449,9 @@ function() {
}
function discriminator(tag) { return null; }
var isBrowser = typeof navigator == "object";
// The difference for a browser here is that HTMLElement gets special
// treatment in [getUnknownTagGenericBrowser].
var isBrowser = typeof HTMLElement == "function";
return {
getTag: getTag,
@ -476,11 +478,11 @@ function(getTagFallback) {
// If we are not in a browser, assume we are in d8.
// TODO(sra): Recognize jsshell.
if (typeof navigator != "object") return hooks;
var ua = navigator.userAgent;
var userAgent = navigator.userAgent;
if (typeof userAgent != "string") return hooks;
// TODO(antonm): remove a reference to DumpRenderTree.
if (ua.indexOf("DumpRenderTree") >= 0) return hooks;
if (ua.indexOf("Chrome") >= 0) {
if (userAgent.indexOf("DumpRenderTree") >= 0) return hooks;
if (userAgent.indexOf("Chrome") >= 0) {
// Confirm constructor name is usable for dispatch.
function confirm(p) {
return typeof window == "object" && window[p] && window[p].name == p;
@ -494,7 +496,9 @@ function(getTagFallback) {
const _ieHooksTransformer = const JS_CONST(r'''
function(hooks) {
var userAgent = typeof navigator == "object" ? navigator.userAgent : "";
if (typeof navigator != "object") return hooks;
var userAgent = navigator.userAgent;
if (typeof userAgent != "string") return hooks;
if (userAgent.indexOf("Trident/") == -1) return hooks;
var getTag = hooks.getTag;
@ -558,7 +562,9 @@ function(hooks) {
const _firefoxHooksTransformer = const JS_CONST(r'''
function(hooks) {
var userAgent = typeof navigator == "object" ? navigator.userAgent : "";
if (typeof navigator != "object") return hooks;
var userAgent = navigator.userAgent;
if (typeof userAgent != "string") return hooks;
if (userAgent.indexOf("Firefox") == -1) return hooks;
var getTag = hooks.getTag;