Skip to content

Commit e21fa2e

Browse files
committed
Change nucleus.compile to use global scope (closes #27)
1 parent 0868737 commit e21fa2e

File tree

5 files changed

+8
-12
lines changed

5 files changed

+8
-12
lines changed

api/nucleus.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,9 @@ A string describing the JS engine. It can contain values like `"duktape"`,
6161

6262
### nucleus.compile(string, path) -> function
6363

64-
Compiles the `string` into a JavaScript function with a file context of `path`,
65-
used in generating error stacktraces.
66-
67-
The source is wrapped in `function () { ... }` and run in function mode.
68-
69-
TODO: should add access to other compile modes? How portable can this be
70-
between engines?
64+
Compiles the `string` into a JavaScript function that takes zero arguments and
65+
returns the last expression. This is run in global context
66+
with a file context of `path`, used in generating error stacktraces.
7167

7268
## Resources
7369

implementations/seaduk

test/fixtures/a.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
return 'a'
1+
'a'

test/parallel/test-nucleus-compile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ function assert(thing, message) {
55
throw new Error(message)
66
}
77

8-
var a = nucleus.compile("return 'a'", 'a')
8+
var a = nucleus.compile("'a'", 'a')
99
assert(a() === 'a', "compile should return 'a'")
1010

11-
var err = nucleus.compile("return new Error('oops')", 'test-nucleus-compile.js')
11+
var err = nucleus.compile("new Error('oops')", 'test-nucleus-compile.js')
1212
print(/\(test-nucleus-compile\.js:1\)/.test(err().stack), "nucleus must contain 'test-nucleus-compile.js'")

test/parallel/test-nucleus-readfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ function assert(thing, message) {
44
throw new Error(message)
55
}
66

7-
assert(nucleus.readfile('../fixtures/a.js') === "return 'a'\n", 'a.js must return it\'s raw source')
7+
assert(nucleus.readfile('../fixtures/a.js') === "'a'\n", 'a.js must return it\'s raw source')
88

99
assert(nucleus.readfile('../fixtures/DOES-NOT-EXIST') === null, 'Non-existant file should return null')

0 commit comments

Comments
 (0)