Skip to content

Commit

Permalink
[stable] [dart2js] Fix compatiblity with Node.js 21
Browse files Browse the repository at this point in the history
Closes #53796

GitOrigin-RevId: caeeb52
Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/330987
Cherry-pick-request: TBA
Change-Id: I459da4b14b29bccca5be2d053d472770f20b04a8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/331323
Reviewed-by: Stephen Adams <sra@google.com>
  • Loading branch information
sigmundch committed Oct 21, 2023
1 parent 6aced7a commit 8fdf766
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 9 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
## 3.1.5

This is a patch release that:

- Fixes an issue affecting Dart compiled to JavaScript running in Node.js 21. A
change in Node.js 21 affected the Dart Web compiler runtime. This patch
release accomodates for those changes (issue #53810).

[#53810]: https://github.com/dart-lang/sdk/issues/53810

## 3.1.4 - 2023-10-18

This is a patch release that:

- Fixes an issue in the Dart VM, users are not being able to see
value of variables while debugging code (issue [#53747]).

Expand Down
146 changes: 145 additions & 1 deletion pkg/compiler/test/dump_info/data/js_members.dart
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
22 changes: 14 additions & 8 deletions sdk/lib/_internal/js_runtime/lib/native_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8fdf766

Please sign in to comment.