mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-14 15:00:01 -04:00
implement call for construct
This commit is contained in:
parent
4d1b7ef1b8
commit
95c080d3ca
1 changed files with 10 additions and 4 deletions
|
@ -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;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue