-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add native StringDecoder #1188
Add native StringDecoder #1188
Conversation
encoding = opt.value(); | ||
} | ||
} | ||
JSStringDecoderPrototype* prototype = JSStringDecoderPrototype::create( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use LazyClassStructure
If we create a new structure for the prototype each time, the JIT will never optimize this code so it will be slow
I'm assuming more than one instance can be created
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
JSStringDecoderPrototype* prototype = JSStringDecoderPrototype::create( | ||
vm, globalObject, reinterpret_cast<Zig::GlobalObject*>(globalObject)->JSStringDecoderPrototypeStructure()); | ||
JSStringDecoder* stringDecoder = JSStringDecoder::create( | ||
vm, globalObject, JSStringDecoder::createStructure(vm, globalObject, prototype), encoding); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This structure should be the LazyProperty, not the prototype's structure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh... ok...
static const HashTableValue JSStringDecoderPrototypeTableValues[] | ||
= { | ||
{ "write"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsStringDecoderPrototypeFunction_write, 1 } }, | ||
{ "end"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsStringDecoderPrototypeFunction_end, 1 } }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't expose "constructor"
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like it should be LazyClassStructure after all (LazyClassStructure will add constructor and prototype there)
84469d0
to
7d8b2d6
Compare
} | ||
int32_t offset = callFrame->uncheckedArgument(1).toInt32(lexicalGlobalObject); | ||
RETURN_IF_EXCEPTION(throwScope, JSC::JSValue::encode(JSC::jsUndefined())); | ||
if (offset > view->length()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (offset > view->length()) | |
if (offset >= view->length()) |
{ | ||
return WebCore::subspaceForImpl<JSStringDecoderConstructor, UseCustomHeapCellType::No>( | ||
vm, | ||
[](auto& spaces) { return spaces.m_clientSubspaceForStringDecoderConstructor.get(); }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't need a subspace for the constructor since no functions/properties are added
var output = allocator.alloc(u16, len / 2) catch return ZigString.init("Out of memory").toErrorInstance(global); | ||
var i : usize = 0; | ||
while (i < len / 2) : (i += 1) { | ||
output[i] = (@intCast(u16, input[2 * i + 1]) << 8) + @intCast(u16, input[2 * i]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is not fast, but I will clean it up
The code is a migration of https://github.com/nodejs/string_decoder. And the tests are from https://github.com/nodejs/node/blob/main/test/parallel/test-string-decoder.js.
Note that I also fixed the
buffer.toString("utf16le")
.Thank you for your time on this PR :)