diff options
author | 2023-01-21 03:14:00 -0800 | |
---|---|---|
committer | 2023-01-21 03:14:00 -0800 | |
commit | 627da4452714bc7126db776682882afd26f89516 (patch) | |
tree | 10ab49fc9d355d06c67bb7ff523db7434844c67e | |
parent | 9955b7462250e0a92c5805a32cc39085e1c6f38f (diff) | |
download | bun-627da4452714bc7126db776682882afd26f89516.tar.gz bun-627da4452714bc7126db776682882afd26f89516.tar.zst bun-627da4452714bc7126db776682882afd26f89516.zip |
Handle string subclasses and new String() in new Buffer
-rw-r--r-- | src/bun.js/bindings/JSBuffer.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/bun.js/bindings/JSBuffer.cpp b/src/bun.js/bindings/JSBuffer.cpp index 8b1c6ddf3..2cf0bb261 100644 --- a/src/bun.js/bindings/JSBuffer.cpp +++ b/src/bun.js/bindings/JSBuffer.cpp @@ -1778,10 +1778,19 @@ JSC_DEFINE_HOST_FUNCTION(constructJSBuffer, (JSC::JSGlobalObject * lexicalGlobal RELEASE_AND_RETURN(throwScope, (constructBufferEmpty(lexicalGlobalObject, callFrame))); } JSValue distinguishingArg = callFrame->uncheckedArgument(0); + if (distinguishingArg.isAnyInt()) { RELEASE_AND_RETURN(throwScope, JSBuffer__bufferFromLength(lexicalGlobalObject, distinguishingArg.asAnyInt())); - } else if (distinguishingArg.isString()) { - RELEASE_AND_RETURN(throwScope, (constructBufferFromStringAndEncoding(lexicalGlobalObject, callFrame))); + } else if (distinguishingArg.isCell()) { + auto type = distinguishingArg.asCell()->type(); + + switch (type) { + case StringType: + case StringObjectType: + case DerivedStringObjectType: { + RELEASE_AND_RETURN(throwScope, (constructBufferFromStringAndEncoding(lexicalGlobalObject, callFrame))); + } + } } JSC::JSObject* constructor = lexicalGlobalObject->m_typedArrayUint8.constructor(lexicalGlobalObject); |