Skip to content

Commit

Permalink
Properly internalize V8 strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Jan 2, 2019
1 parent 56f8502 commit 467ed46
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 2 additions & 8 deletions libdeno/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}

Expand Down
8 changes: 8 additions & 0 deletions libdeno/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 467ed46

Please sign in to comment.