26 : vector(source, source + strlen(source)) {}
29 : vector(source.begin(), source.end()) {}
34 if (value.IsEmpty() || !value->IsString())
37 v8::String::Value value_raw(
GetIsolate(), value);
38 const uint16_t* data = *value_raw;
39 const size_t length = value_raw.length();
40 if (length == 0 && value.As<
v8::String>()->Length() != 0)
42 #elif defined(USING_JSC) 44 if (!value || !JSValueIsString(cx, value))
48 LocalVar<JsString> str(JSValueToStringCopy(cx, value,
nullptr));
51 const uint16_t* data = JSStringGetCharactersPtr(str);
52 const size_t length = JSStringGetLength(str);
55 std::vector<uint8_t> results(length);
56 DCHECK_EQ(results.size(), length);
57 for (
size_t i = 0; i < length; i++) {
59 LOG(WARNING) <<
"The string to be encoded contains characters outside " 63 results[i] =
static_cast<uint8_t
>(data[i]);
71 return v8::String::NewFromOneByte(
GetIsolate(), data(),
72 v8::NewStringType::kNormal, size())
74 #elif defined(USING_JSC) 75 std::unique_ptr<uint16_t[]> temp_data(
new uint16_t[size()]);
77 std::copy(data(), data() + size(), temp_data.get());
78 LocalVar<JsString> str(JSStringCreateWithCharacters(temp_data.get(), size()));
ReturnVal< JsValue > ToJsValue() const override
bool TryConvert(Handle< JsValue > value) override
void swap(shared_lock< Mutex > &a, shared_lock< Mutex > &b)
ByteString(const char *source)
JSContextRef GetContext()
v8::Isolate * GetIsolate()