[quickjs-devel] Re: quickjs-devel Digest V3 #7

  • From: Luca Adrian Lindhorst <info@xxxxxxxxxxxxxxxx>
  • To: quickjs-devel@xxxxxxxxxxxxx
  • Date: Tue, 23 Feb 2021 14:10:37 +0100

Hey thanks for the hint,

while this works for __filename and __dirname, this probably is not ideal
for module/exports.
So I guess having a general way of adding something to the execution
scope/context of a file (eval) would still be the better solution.

Greetings
Luca Lindhorst

Am Di., 23. Feb. 2021 um 04:21 Uhr schrieb Andrew Fedoniouk <
andrew.fedoniouk@xxxxxxxxx>:

Ideally __filename/__dirname shall be implemented on qJS compiler level.
Any other way is just a palliative.



I did it here as the functionality is critical for Sciter.JS use cases.



Please check :
https://github.com/c-smile/quickjspp/commit/10270350504f2623d53d2903bc23b44b60a76707





Andrew Fedoniouk

Terra Informatica Software, Inc.

Richmond, BC, Canada

http://sciter.com



*From: *FreeLists Mailing List Manager <ecartis@xxxxxxxxxxxxx>
*Sent: *February 22, 2021 5:05 PM
*To: *quickjs-devel digest users <ecartis@xxxxxxxxxxxxx>
*Subject: *quickjs-devel Digest V3 #7



quickjs-devel Digest     Mon, 22 Feb 2021 Volume: 03  Issue: 007



In This Issue:

                [quickjs-devel] Eval with custom local scope



----------------------------------------------------------------------



From: Luca Adrian Lindhorst <info@xxxxxxxxxxxxxxxx>

Date: Mon, 22 Feb 2021 22:30:25 +0100

Subject: [quickjs-devel] Eval with custom local scope



Hello,

I try to build a commonjs require for my project for compatibility reasons.

So I need to define __filename/__dirname/module/exports in the context of

each file. Currently I do

_script = '(function(' + Object.keys(ctx).join(',') + ') {'

+ _script +

'}).bind({})(...Object.values(this))';

evalThis(_script, file, ctx);

where evalThis is basically a call to "JS_EvalThis" with

JS_EVAL_TYPE_GLOBAL. This mostly works but is not ideal for multiple

reasons: for one if those files use ES6 imports they would break.



Currently the only way I could find is to heavily modifying JS_InternalEval

if not the parsing functions themselves.



Are there any better solutions to this?



Thanks

Luca Lindhorst







------------------------------



End of quickjs-devel Digest V3 #7

*********************************





Other related posts: