diff options
Diffstat (limited to 'src/string_bytes.h')
-rw-r--r-- | src/string_bytes.h | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/src/string_bytes.h b/src/string_bytes.h index 5f5fcd9fa0f..8280e379877 100644 --- a/src/string_bytes.h +++ b/src/string_bytes.h @@ -35,29 +35,26 @@ class StringBytes { public: class InlineDecoder : public MaybeStackBuffer<char> { public: - inline bool Decode(Environment* env, - v8::Local<v8::String> string, - v8::Local<v8::Value> encoding, - enum encoding _default) { + inline v8::Maybe<bool> Decode(Environment* env, + v8::Local<v8::String> string, + v8::Local<v8::Value> encoding, + enum encoding _default) { enum encoding enc = ParseEncoding(env->isolate(), encoding, _default); if (!StringBytes::IsValidString(string, enc)) { env->ThrowTypeError("Bad input string"); - return false; + return v8::Just(false); } - const size_t storage = StringBytes::StorageSize(env->isolate(), - string, - enc); + size_t storage; + if (!StringBytes::StorageSize(env->isolate(), string, enc).To(&storage)) + return v8::Nothing<bool>(); AllocateSufficientStorage(storage); - const size_t length = StringBytes::Write(env->isolate(), - out(), - storage, - string, - enc); + const size_t length = + StringBytes::Write(env->isolate(), out(), storage, string, enc); // No zero terminator is included when using this method. SetLength(length); - return true; + return v8::Just(true); } inline size_t size() const { return length(); } @@ -71,15 +68,15 @@ class StringBytes { // Fast, but can be 2 bytes oversized for Base64, and // as much as triple UTF-8 strings <= 65536 chars in length - static size_t StorageSize(v8::Isolate* isolate, - v8::Local<v8::Value> val, - enum encoding enc); + static v8::Maybe<size_t> StorageSize(v8::Isolate* isolate, + v8::Local<v8::Value> val, + enum encoding enc); // Precise byte count, but slightly slower for Base64 and // very much slower for UTF-8 - static size_t Size(v8::Isolate* isolate, - v8::Local<v8::Value> val, - enum encoding enc); + static v8::Maybe<size_t> Size(v8::Isolate* isolate, + v8::Local<v8::Value> val, + enum encoding enc); // Write the bytes from the string or buffer into the char* // returns the number of bytes written, which will always be |