Skip to content

Commit ece6708

Browse files
committed
fix: Migrate neon to 1.0.0
1 parent c78150a commit ece6708

6 files changed

Lines changed: 24 additions & 53 deletions

File tree

index.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,9 @@ StateConstructor.prototype.run = function run() {
1414

1515
module.exports = {
1616
doStringSync: native.doStringSync,
17-
doString(program) {
18-
return new Promise((resolve) => native.doStringAsync(program, resolve));
19-
},
20-
17+
doString: native.doStringAsync,
2118
doFileSync: native.doFileSync,
22-
doFile(filename) {
23-
return new Promise((resolve) => native.doFileAsync(filename, resolve));
24-
},
25-
19+
doFile: native.doFileAsync,
2620
loadProgram(program) {
2721
return new StateConstructor(program);
2822
}

native/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,5 @@ crate-type = ["cdylib"]
1414

1515
[dependencies]
1616
lua = { version = "0.0.10" }
17-
neon = { version = "0.10.1", default-features = false, features = [
18-
"napi-6",
19-
"channel-api",
20-
] }
17+
neon = { version = "1.1.1", default-features = false, features = ["napi-6"] }
2118
static_assertions = "1.1.0"

native/src/do_file.rs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,13 @@ pub fn do_file_sync(mut cx: FunctionContext) -> JsResult<JsValue> {
1313

1414
pub fn do_file_async(mut cx: FunctionContext) -> JsResult<JsValue> {
1515
let program = cx.argument::<JsString>(0)?.value(&mut cx);
16-
let callback = cx.argument::<JsFunction>(1)?.root(&mut cx);
17-
let mut channel = cx.channel();
18-
channel.unref(&mut cx);
19-
20-
std::thread::spawn(move || {
21-
let mut state = State::new();
22-
state.open_libs();
23-
let status = state.do_file(&program);
24-
25-
channel.send(move |mut cx| {
26-
let callback = callback.into_inner(&mut cx);
27-
let this = cx.undefined();
28-
let args = [convert_err(status, &mut state, &mut cx)?];
29-
30-
callback.call(&mut cx, this, args)?;
31-
32-
Ok(())
33-
});
34-
});
35-
Ok(cx.undefined().as_value(&mut cx))
16+
let promise = cx
17+
.task(move || {
18+
let mut state = State::new();
19+
state.open_libs();
20+
let status = state.do_file(&program);
21+
(state, status)
22+
})
23+
.promise(|mut cx, (mut state, status)| convert_err(status, &mut state, &mut cx));
24+
Ok(promise.as_value(&mut cx))
3625
}

native/src/do_string.rs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,13 @@ pub fn do_string_sync(mut cx: FunctionContext) -> JsResult<JsValue> {
1313

1414
pub fn do_string_async(mut cx: FunctionContext) -> JsResult<JsValue> {
1515
let program = cx.argument::<JsString>(0)?.value(&mut cx);
16-
let callback = cx.argument::<JsFunction>(1)?.root(&mut cx);
17-
let mut channel = cx.channel();
18-
channel.unref(&mut cx);
19-
20-
std::thread::spawn(move || {
21-
let mut state = State::new();
22-
state.open_libs();
23-
let status = state.do_string(&program);
24-
25-
channel.send(move |mut cx| {
26-
let callback = callback.into_inner(&mut cx);
27-
let this = cx.undefined();
28-
let args = [convert_err(status, &mut state, &mut cx)?];
29-
30-
callback.call(&mut cx, this, args)?;
31-
32-
Ok(())
33-
});
34-
});
35-
Ok(cx.undefined().as_value(&mut cx))
16+
let promise = cx
17+
.task(move || {
18+
let mut state = State::new();
19+
state.open_libs();
20+
let status = state.do_string(&program);
21+
(state, status)
22+
})
23+
.promise(|mut cx, (mut state, status)| convert_err(status, &mut state, &mut cx));
24+
Ok(promise.as_value(&mut cx))
3625
}

native/src/program/entry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl Entry {
6565
} else if let Ok(o) = value.downcast::<JsObject, _>(cx) {
6666
Entry::Table(Table::from_js(cx, o)?)
6767
} else {
68-
return cx.throw_type_error(&format!(
68+
return cx.throw_type_error(format!(
6969
"found value of unsupported type on the key: {:?}",
7070
key
7171
));

package-lock.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)