From b970b68ed1aecc4ec70f12c90df066f2b87a49d5 Mon Sep 17 00:00:00 2001 From: Fabian Date: Mon, 5 Nov 2018 14:49:14 -0600 Subject: [PATCH] Improved detection of global object Generate Function("return this")() instead of function(){return this}(). The former works in strict mode, the latter doesn't. --- compiler/lib/driver.ml | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/compiler/lib/driver.ml b/compiler/lib/driver.ml index 32a6d0134a..24fa43371d 100644 --- a/compiler/lib/driver.ml +++ b/compiler/lib/driver.ml @@ -385,14 +385,13 @@ let pack ~global js = | `Custom name -> J.ECall (f, [J.EVar (J.S {J.name;var=None})], J.N) | `Auto -> - let global = - J.ECall ( - J.EFun (None, [], [ - J.Statement ( - J.Return_statement( - Some (J.EVar (J.S {J.name="this";var=None})))), - J.N - ], J.N), [], J.N) in + let global = + J.ECall ( + J.ECall ( + (J.EVar (J.S {J.name="Function";var=None})), + [EStr ("return this", `Bytes)], + J.N), + [], J.N) in J.ECall (f, [global], J.N) in match global with