From 31c96dd4ea002d516548f3ca583d2662b55bb247 Mon Sep 17 00:00:00 2001 From: Rintim Date: Sun, 17 Sep 2023 02:46:10 +0800 Subject: [PATCH] determine the arg of `gnc.of` as a generator function. `gnc.of` needs a generator function, so we check the input value to make the error clear. --- game/game.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/game/game.js b/game/game.js index adef4af72..6351d1d18 100644 --- a/game/game.js +++ b/game/game.js @@ -32,7 +32,7 @@ const GeneratorFunction=(function*(){}).constructor; // gnc: GeNCoroutine const gnc={ - of:fn=>function genCoroutine(){ + of:fn=>gnc.is.generatorFunc(fn)?function genCoroutine(){ let gen=fn.apply(this,arguments); gen.status="next"; gen.state=undefined; @@ -61,7 +61,7 @@ result=result.value; Promise.resolve(result).then(nexts,throws); }); - }, + }:(()=>{throw new TypeError("gnc.of needs a GeneratorFunction.")})(), /* await:gen=>new Promise((resolve,reject)=>{ let result=gen;