implement call for construct

This commit is contained in:
velzie 2024-08-31 14:50:34 -04:00
parent 4d1b7ef1b8
commit 95c080d3ca
No known key found for this signature in database
GPG key ID: 048413F95F0DDE1F

View file

@ -190,7 +190,8 @@ export class ScramjetClient {
argArray: any[], argArray: any[],
newTarget: AnyFunction newTarget: AnyFunction
) { ) {
let returnValue: any = null; let returnValue: any = undefined;
let earlyreturn = false;
const ctx: ProxyCtx = { const ctx: ProxyCtx = {
fn: constructor, fn: constructor,
@ -200,12 +201,16 @@ export class ScramjetClient {
return: (r: any) => { return: (r: any) => {
returnValue = r; returnValue = r;
}, },
call: () => alert("todo"), call: () => {
earlyreturn = true;
returnValue = Reflect.construct(ctx.fn, ctx.args, ctx.newTarget);
return returnValue;
},
}; };
handler.construct(ctx); handler.construct(ctx);
if (returnValue) { if (earlyreturn) {
return returnValue; return returnValue;
} }
@ -215,7 +220,7 @@ export class ScramjetClient {
if (handler.apply) { if (handler.apply) {
h.apply = function (fn: any, thisArg: any, argArray: any[]) { h.apply = function (fn: any, thisArg: any, argArray: any[]) {
let returnValue: any = null; let returnValue: any = undefined;
let earlyreturn = false; let earlyreturn = false;
const ctx: ProxyCtx = { const ctx: ProxyCtx = {
@ -230,6 +235,7 @@ export class ScramjetClient {
call: () => { call: () => {
earlyreturn = true; earlyreturn = true;
returnValue = Reflect.apply(ctx.fn, ctx.this, ctx.args); returnValue = Reflect.apply(ctx.fn, ctx.this, ctx.args);
return returnValue;
}, },
}; };