diff options
author | Ujjwal Sharma <usharma1998@gmail.com> | 2018-08-29 16:39:55 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-09-02 15:25:16 +0300 |
commit | a55c57b8c48d4d09d3fb74ffddab6e87d10f2030 (patch) | |
tree | abfb494acec7b5bdc1e817a2f9de4a3cb9c11de7 /src/node_buffer.cc | |
parent | 67403b3a849f86ccd03bcf3b829a89d74471f9ca (diff) |
src: rework (mostly internal) functions to use Maybes
Rework all affected functions to use Maybes, thus improving error
handling substantially in internal functions, API functions as well as
utilities.
Co-authored-by: Michaƫl Zasso <targos@protonmail.com>
PR-URL: https://github.com/nodejs/node/pull/21935
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'src/node_buffer.cc')
-rw-r--r-- | src/node_buffer.cc | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 9a280f7c127..d2cb79d4145 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -236,7 +236,9 @@ MaybeLocal<Object> New(Isolate* isolate, enum encoding enc) { EscapableHandleScope scope(isolate); - const size_t length = StringBytes::Size(isolate, string, enc); + size_t length; + if (!StringBytes::Size(isolate, string, enc).To(&length)) + return Local<Object>(); size_t actual = 0; char* data = nullptr; @@ -828,7 +830,8 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) { const size_t haystack_length = (enc == UCS2) ? ts_obj_length &~ 1 : ts_obj_length; // NOLINT(whitespace/operators) - const size_t needle_length = StringBytes::Size(isolate, needle, enc); + size_t needle_length; + if (!StringBytes::Size(isolate, needle, enc).To(&needle_length)) return; int64_t opt_offset = IndexOfOffset(haystack_length, offset_i64, @@ -868,7 +871,7 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) { if (IsBigEndian()) { StringBytes::InlineDecoder decoder; - decoder.Decode(env, needle, args[3], UCS2); + if (decoder.Decode(env, needle, args[3], UCS2).IsNothing()) return; const uint16_t* decoded_string = reinterpret_cast<const uint16_t*>(decoder.out()); |