1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

Properly internalize V8 strings.

This commit is contained in:
Ryan Dahl 2019-01-01 11:22:23 -05:00
parent d2b85d4904
commit cbb18a596a
2 changed files with 10 additions and 8 deletions

View file

@ -66,12 +66,6 @@ const char* ToCString(const v8::String::Utf8Value& value) {
return *value ? *value : "<string conversion failed>";
}
static inline v8::Local<v8::String> v8_str(const char* x) {
return v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), x,
v8::NewStringType::kNormal)
.ToLocalChecked();
}
std::string EncodeExceptionAsJSON(v8::Local<v8::Context> context,
v8::Local<v8::Value> exception) {
auto* isolate = context->GetIsolate();
@ -360,7 +354,7 @@ bool ExecuteV8StringSource(v8::Local<v8::Context> context,
v8::TryCatch try_catch(isolate);
auto name = v8_str(js_filename);
auto name = v8_str(js_filename, true);
v8::ScriptOrigin origin(name);
@ -388,7 +382,7 @@ bool Execute(v8::Local<v8::Context> context, const char* js_filename,
auto* isolate = context->GetIsolate();
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);
auto source = v8_str(js_source);
auto source = v8_str(js_source, true);
return ExecuteV8StringSource(context, js_filename, source);
}

View file

@ -83,6 +83,14 @@ struct InternalFieldData {
uint32_t data;
};
static inline v8::Local<v8::String> v8_str(const char* x,
bool internalize = false) {
return v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), x,
internalize ? v8::NewStringType::kInternalized
: v8::NewStringType::kNormal)
.ToLocalChecked();
}
void Print(const v8::FunctionCallbackInfo<v8::Value>& args);
void Recv(const v8::FunctionCallbackInfo<v8::Value>& args);
void Send(const v8::FunctionCallbackInfo<v8::Value>& args);