fix corner cases with new.target (#4784)

This commit is contained in:
Alex Lam S.L
2021-03-16 06:34:36 +00:00
committed by GitHub
parent 77c9116c91
commit 352a944868
5 changed files with 126 additions and 30 deletions

View File

@@ -55,9 +55,10 @@ function DEFNODE(type, props, methods, base) {
props.forEach(function(prop) {
code.push("this.", prop, "=props.", prop, ";");
});
code.push("}");
var proto = base && new base;
if (proto && proto.initialize || methods && methods.initialize) code.push("this.initialize();");
code.push("}}");
code.push("}");
var ctor = new Function(code.join(""))();
if (proto) {
ctor.prototype = proto;
@@ -1818,6 +1819,9 @@ var AST_This = DEFNODE("This", null, {
var AST_NewTarget = DEFNODE("NewTarget", null, {
$documentation: "The `new.target` symbol",
initialize: function() {
this.name = "new.target";
},
_validate: function() {
if (this.name !== "new.target") throw new Error('name must be "new.target": ' + this.name);
},