diff options
author | Anna Henningsen <anna@addaleax.net> | 2017-04-30 19:53:04 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2017-05-03 20:21:32 +0300 |
commit | d56a7e640f766f15980b28d15bbf02bf60975ab2 (patch) | |
tree | d50b7da36ca2331cabe23da90d55d4dcf77ea74f /src/string_bytes.h | |
parent | 6c2daf0ce9cffbadf51359ddfb804f5a6107737c (diff) |
src: do proper StringBytes error handling
- 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 <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Diffstat (limited to 'src/string_bytes.h')
-rw-r--r-- | src/string_bytes.h | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/string_bytes.h b/src/string_bytes.h index 81561e6e706..e11c16d65f2 100644 --- a/src/string_bytes.h +++ b/src/string_bytes.h @@ -105,19 +105,22 @@ class StringBytes { // Take the bytes in the src, and turn it into a Buffer or String. // Don't call with encoding=UCS2. - static v8::Local<v8::Value> Encode(v8::Isolate* isolate, - const char* buf, - size_t buflen, - enum encoding encoding); + static v8::MaybeLocal<v8::Value> Encode(v8::Isolate* isolate, + const char* buf, + size_t buflen, + enum encoding encoding, + v8::Local<v8::Value>* error); // The input buffer should be in host endianness. - static v8::Local<v8::Value> Encode(v8::Isolate* isolate, - const uint16_t* buf, - size_t buflen); - - static v8::Local<v8::Value> Encode(v8::Isolate* isolate, - const char* buf, - enum encoding encoding); + static v8::MaybeLocal<v8::Value> Encode(v8::Isolate* isolate, + const uint16_t* buf, + size_t buflen, + v8::Local<v8::Value>* error); + + static v8::MaybeLocal<v8::Value> Encode(v8::Isolate* isolate, + const char* buf, + enum encoding encoding, + v8::Local<v8::Value>* error); private: static size_t WriteUCS2(char* buf, |