| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -411,15 +411,7 @@ function makeTextDecoderICU() { | |||
| 411 | 411 | ||
| 412 | 412 | decode(input = empty, options = kEmptyObject) { | |
| 413 | 413 | validateDecoder(this); | |
| 414 | - if (isAnyArrayBuffer(input)) { | ||
| 415 | - try { | ||
| 416 | - input = lazyBuffer().from(input); | ||
| 417 | - } catch { | ||
| 418 | - // If the buffer is detached, | ||
| 419 | - // use an empty Uint8Array to avoid TypeError | ||
| 420 | - input = empty; | ||
| 421 | - } | ||
| 422 | - } else if (!isArrayBufferView(input)) { | ||
| 414 | + if (!isAnyArrayBuffer(input) && !isArrayBufferView(input)) { | ||
| 423 | 415 | throw new ERR_INVALID_ARG_TYPE('input', | |
| 424 | 416 | ['ArrayBuffer', 'ArrayBufferView'], | |
| 425 | 417 | input); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -513,8 +513,9 @@ SlicedArguments::SlicedArguments( | |||
| 513 | 513 | template <typename T, size_t S> | |
| 514 | 514 | ArrayBufferViewContents<T, S>::ArrayBufferViewContents( | |
| 515 | 515 | v8::Local<v8::Value> value) { | |
| 516 | - CHECK(value->IsArrayBufferView()); | ||
| 517 | - Read(value.As<v8::ArrayBufferView>()); | ||
| 516 | + DCHECK(value->IsArrayBufferView() || value->IsSharedArrayBuffer() || | ||
| 517 | + value->IsArrayBuffer()); | ||
| 518 | + ReadValue(value); | ||
| 518 | 519 | } | |
| 519 | 520 | ||
| 520 | 521 | template <typename T, size_t S> | |
@@ -542,6 +543,26 @@ void ArrayBufferViewContents<T, S>::Read(v8::Local<v8::ArrayBufferView> abv) { | |||
| 542 | 543 | } | |
| 543 | 544 | } | |
| 544 | 545 | ||
| 546 | + template <typename T, size_t S> | ||
| 547 | + void ArrayBufferViewContents<T, S>::ReadValue(v8::Local<v8::Value> buf) { | ||
| 548 | + static_assert(sizeof(T) == 1, "Only supports one-byte data at the moment"); | ||
| 549 | + DCHECK(buf->IsArrayBufferView() || buf->IsSharedArrayBuffer() || | ||
| 550 | + buf->IsArrayBuffer()); | ||
| 551 | + | ||
| 552 | + if (buf->IsArrayBufferView()) { | ||
| 553 | + Read(buf.As<v8::ArrayBufferView>()); | ||
| 554 | + } else if (buf->IsArrayBuffer()) { | ||
| 555 | + auto ab = buf.As<v8::ArrayBuffer>(); | ||
| 556 | + length_ = ab->ByteLength(); | ||
| 557 | + data_ = static_cast<T*>(ab->Data()); | ||
| 558 | + } else { | ||
| 559 | + CHECK(buf->IsSharedArrayBuffer()); | ||
| 560 | + auto sab = buf.As<v8::SharedArrayBuffer>(); | ||
| 561 | + length_ = sab->ByteLength(); | ||
| 562 | + data_ = static_cast<T*>(sab->Data()); | ||
| 563 | + } | ||
| 564 | + } | ||
| 565 | + | ||
| 545 | 566 | // ECMA262 20.1.2.5 | |
| 546 | 567 | inline bool IsSafeJsInt(v8::Local<v8::Value> v) { | |
| 547 | 568 | if (!v->IsNumber()) return false; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -506,6 +506,7 @@ class ArrayBufferViewContents { | |||
| 506 | 506 | explicit inline ArrayBufferViewContents(v8::Local<v8::Object> value); | |
| 507 | 507 | explicit inline ArrayBufferViewContents(v8::Local<v8::ArrayBufferView> abv); | |
| 508 | 508 | inline void Read(v8::Local<v8::ArrayBufferView> abv); | |
| 509 | + inline void ReadValue(v8::Local<v8::Value> buf); | ||
| 509 | 510 | ||
| 510 | 511 | inline const T* data() const { return data_; } | |
| 511 | 512 | inline size_t length() const { return length_; } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments