From d56a7e640f766f15980b28d15bbf02bf60975ab2 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 30 Apr 2017 18:53:04 +0200 Subject: src: do proper StringBytes error handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Return `MaybeLocal`s from `StringBytes::Encode` - Add an `error` out parameter to pass JS exceptions to the callers (instead of directly throwing) - Simplify some of the string generation methods in `string_bytes.cc` by unifying the `EXTERN_APEX` logic - Reduce usage of deprecated V8 APIs. - Remove error handling logic from JS, the `buffer.*Slice()` methods now throw errors themselves. - Left TODO comments for future semver-major error message improvements. This paves the way for better error messages coming out of the StringBytes methods. Ref: https://github.com/nodejs/node/issues/3175 PR-URL: https://github.com/nodejs/node/pull/12765 Reviewed-By: Benjamin Gruenbaum Reviewed-By: James M Snell Reviewed-By: Tobias Nießen --- src/fs_event_wrap.cc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/fs_event_wrap.cc') diff --git a/src/fs_event_wrap.cc b/src/fs_event_wrap.cc index a747f71c40..bc3b33027a 100644 --- a/src/fs_event_wrap.cc +++ b/src/fs_event_wrap.cc @@ -39,6 +39,7 @@ using v8::FunctionTemplate; using v8::HandleScope; using v8::Integer; using v8::Local; +using v8::MaybeLocal; using v8::Object; using v8::String; using v8::Value; @@ -187,17 +188,20 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename, }; if (filename != nullptr) { - Local fn = StringBytes::Encode(env->isolate(), - filename, - wrap->encoding_); + Local error; + MaybeLocal fn = StringBytes::Encode(env->isolate(), + filename, + wrap->encoding_, + &error); if (fn.IsEmpty()) { argv[0] = Integer::New(env->isolate(), UV_EINVAL); argv[2] = StringBytes::Encode(env->isolate(), filename, strlen(filename), - BUFFER); + BUFFER, + &error).ToLocalChecked(); } else { - argv[2] = fn; + argv[2] = fn.ToLocalChecked(); } } -- cgit v1.2.3