Skip to content
Permalink
Browse files

core, feat: support for top-level await operators.

  • Loading branch information...
xicilion committed Jun 18, 2018
1 parent 78ae3b1 commit 8de2cfd0b86bd0814cd9bc2c29cf310e9406ef4f
@@ -11,13 +11,13 @@

namespace fibjs {

const char* SandBox::script_args = "(function(__filename,__dirname,require,run,exports,module,argv,repl){";
const char* SandBox::script_args = "(async function(__filename,__dirname,require,run,exports,module,argv,repl){";
static const int32_t script_args_count = 8;

const char* SandBox::worker_args = "(function(__filename,__dirname,require,run,exports,module,Master){";
const char* SandBox::worker_args = "(async function(__filename,__dirname,require,run,exports,module,Master){";
static const int32_t worker_args_count = 7;

const char* SandBox::module_args = "(function(__filename,__dirname,require,run,exports,module){";
const char* SandBox::module_args = "(async function(__filename,__dirname,require,run,exports,module){";
static const int32_t module_args_count = 6;

result_t SandBox::ExtLoader::run_script(Context* ctx, Buffer_base* src, exlib::string name,
@@ -9,6 +9,7 @@
#include "path.h"
#include "SandBox.h"
#include "loaders.h"
#include "ifs/util.h"

namespace fibjs {

@@ -61,10 +62,13 @@ result_t JsLoader::run(SandBox::Context* ctx, Buffer_base* src, exlib::string na
if (v.IsEmpty())
return CALL_E_JAVASCRIPT;

v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(v);
util_base::sync(func, true, func);

args[0] = soname;
args[1] = isolate->NewString(pname);
v8::Local<v8::Object> glob = isolate->context()->Global();
v = v8::Local<v8::Function>::Cast(v)->Call(glob, args_count, args);
v = func->Call(glob, args_count, args);
if (v.IsEmpty())
return CALL_E_JAVASCRIPT;

@@ -9,6 +9,7 @@
#include "path.h"
#include "SandBox.h"
#include "ifs/zlib.h"
#include "ifs/util.h"
#include "loaders.h"
#include "version.h"

@@ -86,10 +87,13 @@ result_t JscLoader::run(SandBox::Context* ctx, Buffer_base* src, exlib::string n
if (v.IsEmpty())
return CALL_E_JAVASCRIPT;

v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(v);
util_base::sync(func, true, func);

args[0] = soname;
args[1] = isolate->NewString(pname);
v8::Local<v8::Object> glob = isolate->context()->Global();
v = v8::Local<v8::Function>::Cast(v)->Call(glob, args_count, args);
v = func->Call(glob, args_count, args);
if (v.IsEmpty())
return CALL_E_JAVASCRIPT;

@@ -10,6 +10,7 @@
#include "SandBox.h"
#include "Buffer.h"
#include "loaders.h"
#include "ifs/util.h"

namespace fibjs {

@@ -99,10 +100,13 @@ result_t TsLoader::run(SandBox::Context* ctx, Buffer_base* src, exlib::string na
if (v.IsEmpty())
return CALL_E_JAVASCRIPT;

v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(v);
util_base::sync(func, true, func);

args[0] = soname;
args[1] = isolate->NewString(pname);
v8::Local<v8::Object> glob = isolate->context()->Global();
v = v8::Local<v8::Function>::Cast(v)->Call(glob, args_count, args);
v = func->Call(glob, args_count, args);
if (v.IsEmpty())
return CALL_E_JAVASCRIPT;

@@ -138,14 +138,17 @@ static void async_promise(const v8::FunctionCallbackInfo<v8::Value>& args)
result_t util_base::sync(v8::Local<v8::Function> func, bool async_func, v8::Local<v8::Function>& retVal)
{
Isolate* isolate = Isolate::current();
v8::Local<v8::Function> func1;

if (async_func || func->IsAsyncFunction())
func = isolate->NewFunction("async_promise", async_promise, func);

retVal = isolate->NewFunction("sync", sync_stub, func);
retVal->SetPrivate(retVal->CreationContext(),
func1 = isolate->NewFunction("sync", sync_stub, func);
func1->SetPrivate(func1->CreationContext(),
v8::Private::ForApi(isolate->m_isolate, isolate->NewString("_async")), func);

retVal = func1;

return 0;
}
}
@@ -0,0 +1,5 @@
async function test() {
return 100;
}

module.exports = await test();
@@ -87,6 +87,10 @@ describe("module", () => {
});
});

it("require async file", () => {
assert.equal(require('./module/d2'), 100);
});

it("support symlink", () => {
fs.symlink(path.join(__dirname, 'module', 'p6'), path.join(__dirname, 'module', 'p6_1'));
assert.equal(require('./module/p6/t'), require('./module/p6_1/t'));

0 comments on commit 8de2cfd

Please sign in to comment.
You can’t perform that action at this time.