Skip to content

Commit

Permalink
Change nucleus.compile to use global scope (closes #27)
Browse files Browse the repository at this point in the history
  • Loading branch information
creationix committed Jul 15, 2016
1 parent 0868737 commit e21fa2e
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 12 deletions.
10 changes: 3 additions & 7 deletions api/nucleus.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion implementations/seaduk
2 changes: 1 addition & 1 deletion test/fixtures/a.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
return 'a'
'a'
4 changes: 2 additions & 2 deletions test/parallel/test-nucleus-compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
2 changes: 1 addition & 1 deletion test/parallel/test-nucleus-readfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

0 comments on commit e21fa2e

Please sign in to comment.