| 89 | } |
| 90 | |
| 91 | static void serializeString(const v8::FunctionCallbackInfo<v8::Value> &args) { |
| 92 | auto isolate = args.GetIsolate(); |
| 93 | auto context = isolate->GetCurrentContext(); |
| 94 | v8::Local<v8::Uint8Array> dst = args[0].As<v8::Uint8Array>(); |
| 95 | v8::Local<v8::String> str = args[1].As<v8::String>(); |
| 96 | uint32_t offset = args[2].As<v8::Number>()->Uint32Value(context).ToChecked(); |
| 97 | |
| 98 | bool is_one_byte = str->IsOneByte(); |
| 99 | uint8_t *dst_data = |
| 100 | reinterpret_cast<uint8_t *>(dst->Buffer()->GetBackingStore()->Data()); |
| 101 | |
| 102 | if (is_one_byte && str->IsExternalOneByte()) { |
| 103 | offset += writeVarUint32(dst_data, offset, |
| 104 | (str->Length() << 2) | Encoding::LATIN1); // length |
| 105 | const auto src = str->GetExternalOneByteStringResource()->data(); |
| 106 | memcpy(dst_data + offset, src, str->Length()); |
| 107 | offset += str->Length(); |
| 108 | } else { |
| 109 | v8::HandleScope scope(isolate); |
| 110 | int flags = String::HINT_MANY_WRITES_EXPECTED | |
| 111 | String::NO_NULL_TERMINATION | String::REPLACE_INVALID_UTF8; |
| 112 | if (is_one_byte) { |
| 113 | offset += |
| 114 | writeVarUint32(dst_data, offset, |
| 115 | (str->Length() << 2) | Encoding::LATIN1); // length |
| 116 | offset += str->WriteOneByte(isolate, dst_data + offset, 0, str->Length(), |
| 117 | flags); |
| 118 | } else { |
| 119 | offset += writeVarUint32(dst_data, offset, |
| 120 | ((str->Length() * 2) << 2) | |
| 121 | Encoding::UTF16); // length |
| 122 | offset += writeUCS2(isolate, dst_data + offset, str, flags); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | args.GetReturnValue().Set(offset); |
| 127 | } |
| 128 | |
| 129 | static uint32_t serializeStringFast(Local<Value> receiver, |
| 130 | const v8::FastApiTypedArray<uint8_t> &dst, |
no test coverage detected