Skip to content

Commit

Permalink
try ToDetailString
Browse files Browse the repository at this point in the history
  • Loading branch information
targos committed Sep 5, 2017
1 parent bd90db9 commit 5f2c4fa
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "util-inl.h"
#include "v8-debug.h"

#include <sstream>
#include <string>

namespace node {
Expand Down Expand Up @@ -73,6 +74,11 @@ using v8::WeakCallbackInfo;

namespace {

std::ostream& operator<<(std::ostream& os, Local<Value> value) {
String::Utf8Value utf8(value);
return os << *utf8;
}

class ContextifyContext {
protected:
// V8 reserves the first field in context objects for the debugger. We use the
Expand Down Expand Up @@ -424,6 +430,8 @@ class ContextifyContext {
if (ctx->context_.IsEmpty())
return;

Local<Context> context = ctx->context();

auto attributes = PropertyAttribute::None;
bool is_declared =
ctx->sandbox()->GetRealNamedPropertyAttributes(ctx->context(),
Expand All @@ -435,12 +443,19 @@ class ContextifyContext {

if (is_declared && read_only) {
if (args.ShouldThrowOnError()) {
std::string error_message("Cannot assign to read only property '");
Local<String> property_name = property->ToDetailString();
String::Utf8Value utf8_name(property_name);
error_message += *utf8_name;
error_message += "' of object '#<Object>'";
env->ThrowTypeError(error_message.c_str());
std::ostringstream error_message;
error_message << "Cannot assign to read only property '";
Local<String> property_name =
property->ToDetailString(context).ToLocalChecked();
error_message << property_name;
error_message << "' of ";
error_message << ctx->sandbox()->TypeOf(isolate);
error_message << " '";
Local<String> sandbox_name =
ctx->sandbox()->ToDetailString(context).ToLocalChecked();
error_message << sandbox_name;
error_message << "'";
env->ThrowTypeError(error_message.str().c_str());
}
return;
}
Expand Down Expand Up @@ -537,6 +552,8 @@ class ContextifyContext {
if (ctx->context_.IsEmpty())
return;

Local<Context> context = ctx->context();

auto attributes = PropertyAttribute::None;
bool is_declared =
ctx->sandbox()->GetRealNamedPropertyAttributes(ctx->context(),
Expand All @@ -549,15 +566,15 @@ class ContextifyContext {
if (is_declared && non_enumerable) {
if (args.ShouldThrowOnError()) {
std::string error_message("Cannot redefine property: ");
Local<String> property_name = property->ToDetailString();
Local<String> property_name =
property->ToDetailString(context).ToLocalChecked();
String::Utf8Value utf8_name(property_name);
error_message += *utf8_name;
env->ThrowTypeError(error_message.c_str());
}
return;
}

Local<Context> context = ctx->context();
auto add_desc_copy_to_sandbox =
[&] (PropertyDescriptor* desc_copy) {
if (desc.has_enumerable()) {
Expand Down

0 comments on commit 5f2c4fa

Please sign in to comment.