From e21fa2e112d75b9c40181f43ee6db0054888158b Mon Sep 17 00:00:00 2001 From: Tim Caswell Date: Fri, 15 Jul 2016 15:53:51 -0500 Subject: [PATCH] Change nucleus.compile to use global scope (closes #27) --- api/nucleus.md | 10 +++------- implementations/seaduk | 2 +- test/fixtures/a.js | 2 +- test/parallel/test-nucleus-compile.js | 4 ++-- test/parallel/test-nucleus-readfile.js | 2 +- 5 files changed, 8 insertions(+), 12 deletions(-) diff --git a/api/nucleus.md b/api/nucleus.md index 4343d80..9b65040 100644 --- a/api/nucleus.md +++ b/api/nucleus.md @@ -61,13 +61,9 @@ A string describing the JS engine. It can contain values like `"duktape"`, ### nucleus.compile(string, path) -> function -Compiles the `string` into a JavaScript function with a file context of `path`, -used in generating error stacktraces. - -The source is wrapped in `function () { ... }` and run in function mode. - -TODO: should add access to other compile modes? How portable can this be -between engines? +Compiles the `string` into a JavaScript function that takes zero arguments and +returns the last expression. This is run in global context +with a file context of `path`, used in generating error stacktraces. ## Resources diff --git a/implementations/seaduk b/implementations/seaduk index e8695cd..99da0b7 160000 --- a/implementations/seaduk +++ b/implementations/seaduk @@ -1 +1 @@ -Subproject commit e8695cdf69e751ce3ecc55bbd27e77a5884a795e +Subproject commit 99da0b7d9acf59b851e9aacfca2e20e26c865d7c diff --git a/test/fixtures/a.js b/test/fixtures/a.js index f90b7f2..67fe32d 100644 --- a/test/fixtures/a.js +++ b/test/fixtures/a.js @@ -1 +1 @@ -return 'a' +'a' diff --git a/test/parallel/test-nucleus-compile.js b/test/parallel/test-nucleus-compile.js index 339c485..b1b2d7b 100644 --- a/test/parallel/test-nucleus-compile.js +++ b/test/parallel/test-nucleus-compile.js @@ -5,8 +5,8 @@ function assert(thing, message) { throw new Error(message) } -var a = nucleus.compile("return 'a'", 'a') +var a = nucleus.compile("'a'", 'a') assert(a() === 'a', "compile should return 'a'") -var err = nucleus.compile("return new Error('oops')", 'test-nucleus-compile.js') +var err = nucleus.compile("new Error('oops')", 'test-nucleus-compile.js') print(/\(test-nucleus-compile\.js:1\)/.test(err().stack), "nucleus must contain 'test-nucleus-compile.js'") diff --git a/test/parallel/test-nucleus-readfile.js b/test/parallel/test-nucleus-readfile.js index d9ff7bf..b897b87 100644 --- a/test/parallel/test-nucleus-readfile.js +++ b/test/parallel/test-nucleus-readfile.js @@ -4,6 +4,6 @@ function assert(thing, message) { throw new Error(message) } -assert(nucleus.readfile('../fixtures/a.js') === "return 'a'\n", 'a.js must return it\'s raw source') +assert(nucleus.readfile('../fixtures/a.js') === "'a'\n", 'a.js must return it\'s raw source') assert(nucleus.readfile('../fixtures/DOES-NOT-EXIST') === null, 'Non-existant file should return null')