Skip to content

Commit

Permalink
0.3.1, fix for eval, lively.vm 0.5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
rksm committed May 18, 2016
1 parent 8ec83bc commit c4a0746
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
9 changes: 8 additions & 1 deletion dist/lively.modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -23253,6 +23253,8 @@ var categorizer = Object.freeze({

var originalCode = code;

System.debug && console.log("[lively.module] runEval: " + code.slice(0, 100).replace(/\n/mg, " ") + "...");

return Promise.resolve().then(function () {
var targetModule = options.targetModule || "*scratch*";
return System.normalize(targetModule, options.parentModule, options.parentAddress);
Expand Down Expand Up @@ -23283,8 +23285,9 @@ var categorizer = Object.freeze({
transpiler: transpiler
});

recordDoitRequest(System, originalCode, { waitForPromise: options.waitForPromise, targetModule: options.targetModule }, Date.now());
System.debug && console.log("[lively.module] runEval in module " + fullname + " started");

recordDoitRequest(System, originalCode, { waitForPromise: options.waitForPromise, targetModule: options.targetModule }, Date.now());
return lively_vm_lib_evaluator_js.runEval(code, options).then(function (result) {
return result.isError || !env.currentEval.promise ? result : env.currentEval.promise.then(function (result) {
return result.process(options).then(function () {
Expand All @@ -23293,9 +23296,13 @@ var categorizer = Object.freeze({
});
}).then(function (result) {
System["__lively.modules__"].evaluationDone(fullname);
System.debug && console.log("[lively.module] runEval in module " + targetModule + " done");
recordDoitResult(System, originalCode, { waitForPromise: options.waitForPromise, targetModule: options.targetModule }, result, Date.now());
return result;
});
})["catch"](function (err) {
console.error("Error in runEval: " + err.stack);
throw err;
});
});
}
Expand Down
9 changes: 8 additions & 1 deletion dist/lively.modules_no-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -2049,6 +2049,8 @@

var originalCode = code;

System.debug && console.log("[lively.module] runEval: " + code.slice(0, 100).replace(/\n/mg, " ") + "...");

return Promise.resolve().then(function () {
var targetModule = options.targetModule || "*scratch*";
return System.normalize(targetModule, options.parentModule, options.parentAddress);
Expand Down Expand Up @@ -2079,8 +2081,9 @@
transpiler: transpiler
});

recordDoitRequest(System, originalCode, { waitForPromise: options.waitForPromise, targetModule: options.targetModule }, Date.now());
System.debug && console.log("[lively.module] runEval in module " + fullname + " started");

recordDoitRequest(System, originalCode, { waitForPromise: options.waitForPromise, targetModule: options.targetModule }, Date.now());
return lively_vm_lib_evaluator_js.runEval(code, options).then(function (result) {
return result.isError || !env.currentEval.promise ? result : env.currentEval.promise.then(function (result) {
return result.process(options).then(function () {
Expand All @@ -2089,9 +2092,13 @@
});
}).then(function (result) {
System["__lively.modules__"].evaluationDone(fullname);
System.debug && console.log("[lively.module] runEval in module " + targetModule + " done");
recordDoitResult(System, originalCode, { waitForPromise: options.waitForPromise, targetModule: options.targetModule }, result, Date.now());
return result;
});
})["catch"](function (err) {
console.error("Error in runEval: " + err.stack);
throw err;
});
});
}
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lively.modules",
"version": "0.3.0",
"version": "0.3.1",
"main": "dist/lively.modules.js",
"scripts": {
"test": "mocha-es6 tests/*-test.js",
Expand Down Expand Up @@ -40,14 +40,14 @@
"babel-core": "^5.8.38",
"babel-regenerator-runtime": "^6.5.0",
"lively.ast": "^0.6.8",
"lively.lang": "^0.5.22",
"lively.vm": "^0.5.3",
"lively.lang": "^0.5.23",
"lively.vm": "^0.5.4",
"systemjs": "^0.19.24",
"whatwg-fetch": "^1.0.0"
},
"devDependencies": {
"doc-comments": "^0.1.4",
"mocha-es6": "^0.2.7",
"mocha-es6": "^0.2.8",
"rollup-plugin-babel": "^1.0.0"
}
}
15 changes: 14 additions & 1 deletion src/eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ function runEval(System, code, options) {

var originalCode = code;

System.debug && console.log(`[lively.module] runEval: ${code.slice(0,100).replace(/\n/mg, " ")}...`);

return Promise.resolve()
.then(() => {
var targetModule = options.targetModule || "*scratch*";
return System.normalize(targetModule, options.parentModule, options.parentAddress);
})
.then((targetModule) => {
var fullname = options.targetModule = targetModule;
System.debug && console.log(`[lively.module] runEval in module ${targetModule} started`);

return System.import(fullname)
.then(() => ensureImportsAreLoaded(System, code, fullname))
.then(() => {
Expand Down Expand Up @@ -60,6 +64,7 @@ function runEval(System, code, options) {
Date.now());

return realRunEval(code, options).then(result => {
System.debug && console.log(`[lively.module] runEval in module ${targetModule} done`);
System["__lively.modules__"].evaluationDone(fullname);
recordDoitResult(
System, originalCode,
Expand Down Expand Up @@ -178,6 +183,8 @@ function runEvalWithAsyncSupport(System, code, options) {

var originalCode = code;

System.debug && console.log(`[lively.module] runEval: ${code.slice(0,100).replace(/\n/mg, " ")}...`);

return Promise.resolve()
.then(() => {
var targetModule = options.targetModule || "*scratch*";
Expand Down Expand Up @@ -212,11 +219,12 @@ function runEvalWithAsyncSupport(System, code, options) {
transpiler: transpiler
});

System.debug && console.log(`[lively.module] runEval in module ${fullname} started`);

recordDoitRequest(
System, originalCode,
{waitForPromise: options.waitForPromise, targetModule: options.targetModule},
Date.now());

return realRunEval(code, options)
.then(result =>
result.isError || !env.currentEval.promise ?
Expand All @@ -226,13 +234,18 @@ function runEvalWithAsyncSupport(System, code, options) {
}))
.then(result => {
System["__lively.modules__"].evaluationDone(fullname);
System.debug && console.log(`[lively.module] runEval in module ${targetModule} done`);
recordDoitResult(
System, originalCode,
{waitForPromise: options.waitForPromise, targetModule: options.targetModule},
result, Date.now());
return result;
})
})
.catch(err => {
console.error(`Error in runEval: ${err.stack}`);
throw err;
})
});
}

Expand Down
5 changes: 3 additions & 2 deletions tests/eval-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var dir = System.normalizeSync("lively.modules/tests/"),
"file1.js": "import { y } from './file2.js'; var z = 2; export var x = y + z;",
"file2.js": "import { z } from './file3.js'; export var y = z;",
"file3.js": "export var z = 1;",
"file4.js": "export async function foo(arg) { return new Promise((resolve, reject) => setTimeout(resolve, 200, arg)); }",
// "file4.js": "export async function foo(arg) { return new Promise((resolve, reject) => setTimeout(resolve, 200, arg)); }",
"package.json": '{"name": "test-project-1", "main": "file1.js"}',
},

Expand All @@ -28,13 +28,14 @@ describe("eval", () => {
var System;
beforeEach(() => {
System = getSystem("test", {baseURL: dir});
System.debug = true;
return createFiles(testProjectDir, testProjectSpec)
.then(() => System.import(module1));
});

afterEach(() => { removeSystem("test"); return removeDir(testProjectDir); });

it("inside of module", () =>
it.only("inside of module", () =>
runEval(System, "1 + z + x", {targetModule: module1})
.then(result => expect(result.value).equals(6)));

Expand Down

0 comments on commit c4a0746

Please sign in to comment.