Local<Boolean> Value::ToBoolean() const {
- return ToBoolean(Isolate::GetCurrent());
+ return ToBoolean(Isolate::GetCurrent()->GetCurrentContext())
+ .FromMaybe(Local<Boolean>());
}
Local<Number> Value::ToNumber() const {
- return ToNumber(Isolate::GetCurrent());
+ return ToNumber(Isolate::GetCurrent()->GetCurrentContext())
+ .FromMaybe(Local<Number>());
}
Local<String> Value::ToString() const {
- return ToString(Isolate::GetCurrent());
+ return ToString(Isolate::GetCurrent()->GetCurrentContext())
+ .FromMaybe(Local<String>());
}
Local<String> Value::ToDetailString() const {
- return ToDetailString(Isolate::GetCurrent());
+ return ToDetailString(Isolate::GetCurrent()->GetCurrentContext())
+ .FromMaybe(Local<String>());
}
Local<Object> Value::ToObject() const {
- return ToObject(Isolate::GetCurrent());
+ return ToObject(Isolate::GetCurrent()->GetCurrentContext())
+ .FromMaybe(Local<Object>());
}
Local<Integer> Value::ToInteger() const {
- return ToInteger(Isolate::GetCurrent());
+ return ToInteger(Isolate::GetCurrent()->GetCurrentContext())
+ .FromMaybe(Local<Integer>());
}
Local<Uint32> Value::ToUint32() const {
- return ToUint32(Isolate::GetCurrent());
+ return ToUint32(Isolate::GetCurrent()->GetCurrentContext())
+ .FromMaybe(Local<Uint32>());
}
-Local<Int32> Value::ToInt32() const { return ToInt32(Isolate::GetCurrent()); }
+Local<Int32> Value::ToInt32() const {
+ return ToInt32(Isolate::GetCurrent()->GetCurrentContext())
+ .FromMaybe(Local<Int32>());
+}
Boolean* Boolean::Cast(v8::Value* value) {
JSModule* instance = JSModule::cast(*v8::Utils::OpenHandle(*info.Holder()));
Context* context = Context::cast(instance->context());
DCHECK(context->IsModuleContext());
- int slot = info.Data()->Int32Value();
- Object* value = context->get(slot);
Isolate* isolate = instance->GetIsolate();
+ int slot = info.Data()
+ ->Int32Value(info.GetIsolate()->GetCurrentContext())
+ .FromMaybe(-1);
+ if (slot < 0 || slot >= context->length()) {
+ Handle<String> name = v8::Utils::OpenHandle(*property);
+
+ Handle<Object> exception = isolate->factory()->NewReferenceError(
+ MessageTemplate::kNotDefined, name);
+ isolate->ScheduleThrow(*exception);
+ return;
+ }
+ Object* value = context->get(slot);
if (value->IsTheHole()) {
Handle<String> name = v8::Utils::OpenHandle(*property);
JSModule* instance = JSModule::cast(*v8::Utils::OpenHandle(*info.Holder()));
Context* context = Context::cast(instance->context());
DCHECK(context->IsModuleContext());
- int slot = info.Data()->Int32Value();
+ Isolate* isolate = instance->GetIsolate();
+ int slot = info.Data()
+ ->Int32Value(info.GetIsolate()->GetCurrentContext())
+ .FromMaybe(-1);
+ if (slot < 0 || slot >= context->length()) {
+ Handle<String> name = v8::Utils::OpenHandle(*property);
+ Handle<Object> exception = isolate->factory()->NewReferenceError(
+ MessageTemplate::kNotDefined, name);
+ isolate->ScheduleThrow(*exception);
+ return;
+ }
Object* old_value = context->get(slot);
- Isolate* isolate = context->GetIsolate();
if (old_value->IsTheHole()) {
Handle<String> name = v8::Utils::OpenHandle(*property);
Handle<Object> exception = isolate->factory()->NewReferenceError(
}
-bool RunExtraCode(Isolate* isolate, const char* utf8_source) {
+bool RunExtraCode(Isolate* isolate, Local<Context> context,
+ const char* utf8_source) {
// Run custom script if provided.
base::ElapsedTimer timer;
timer.Start();
TryCatch try_catch(isolate);
- Local<String> source_string = String::NewFromUtf8(isolate, utf8_source);
- if (try_catch.HasCaught()) return false;
- ScriptOrigin origin(String::NewFromUtf8(isolate, "<embedded script>"));
+ Local<String> source_string;
+ if (!String::NewFromUtf8(isolate, utf8_source, NewStringType::kNormal)
+ .ToLocal(&source_string)) {
+ return false;
+ }
+ Local<String> resource_name =
+ String::NewFromUtf8(isolate, "<embedded script>", NewStringType::kNormal)
+ .ToLocalChecked();
+ ScriptOrigin origin(resource_name);
ScriptCompiler::Source source(source_string, origin);
- Local<Script> script = ScriptCompiler::Compile(isolate, &source);
- if (try_catch.HasCaught()) return false;
- script->Run();
+ Local<Script> script;
+ if (!ScriptCompiler::Compile(context, &source).ToLocal(&script)) return false;
+ if (script->Run(context).IsEmpty()) return false;
if (i::FLAG_profile_deserialization) {
i::PrintF("Executing custom snapshot script took %0.3f ms\n",
timer.Elapsed().InMillisecondsF());
}
timer.Stop();
- return !try_catch.HasCaught();
+ CHECK(!try_catch.HasCaught());
+ return true;
}
if (custom_source != NULL) {
metadata.set_embeds_script(true);
Context::Scope context_scope(new_context);
- if (!RunExtraCode(isolate, custom_source)) context.Reset();
+ if (!RunExtraCode(isolate, new_context, custom_source)) context.Reset();
}
}
if (!context.IsEmpty()) {
Local<Script> Script::Compile(v8::Handle<String> source,
v8::Handle<String> file_name) {
+ auto str = Utils::OpenHandle(*source);
+ auto context = ContextFromHeapObject(str);
ScriptOrigin origin(file_name);
- return Compile(source, &origin);
+ return Compile(context, source, &origin).FromMaybe(Local<Script>());
}
bool v8::Object::ForceSet(v8::Handle<Value> key, v8::Handle<Value> value,
v8::PropertyAttribute attribs) {
- auto context = ContextFromHeapObject(Utils::OpenHandle(this));
- return ForceSet(context, key, value, attribs).FromMaybe(false);
+ i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
+ PREPARE_FOR_EXECUTION_GENERIC(isolate, Local<Context>(),
+ "v8::Object::ForceSet", false, i::HandleScope,
+ false);
+ i::Handle<i::JSObject> self = Utils::OpenHandle(this);
+ i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
+ i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
+ has_pending_exception =
+ i::Runtime::DefineObjectProperty(self, key_obj, value_obj,
+ static_cast<PropertyAttributes>(attribs))
+ .is_null();
+ EXCEPTION_BAILOUT_CHECK_SCOPED(isolate, false);
+ return true;
}
// return "[object " + c + "]";
if (!name->IsString()) {
- return v8::String::NewFromUtf8(v8_isolate, "[object ]");
+ return v8::String::NewFromUtf8(v8_isolate, "[object ]",
+ NewStringType::kNormal);
}
auto class_name = i::Handle<i::String>::cast(name);
if (i::String::Equals(class_name, isolate->factory()->Arguments_string())) {
- return v8::String::NewFromUtf8(v8_isolate, "[object Object]");
+ return v8::String::NewFromUtf8(v8_isolate, "[object Object]",
+ NewStringType::kNormal);
}
if (internal::FLAG_harmony_tostring) {
PREPARE_FOR_EXECUTION(context, "v8::Object::ObjectProtoToString()", String);
i::MemCopy(ptr, postfix, postfix_len * v8::internal::kCharSize);
// Copy the buffer into a heap-allocated string and return it.
- return v8::String::NewFromUtf8(v8_isolate, buf.start(), String::kNormalString,
- buf_len);
+ return v8::String::NewFromUtf8(v8_isolate, buf.start(),
+ NewStringType::kNormal, buf_len);
}
Local<v8::Object> Function::NewInstance() const {
- return NewInstance(0, NULL);
+ return NewInstance(Isolate::GetCurrent()->GetCurrentContext(), 0, NULL)
+ .FromMaybe(Local<Object>());
}
if (!InternalFieldOK(obj, index, location)) return;
i::Handle<i::Object> val = Utils::OpenHandle(*value);
obj->SetInternalField(index, *val);
- DCHECK(value->Equals(GetInternalField(index)));
}
String::Utf8Value::Utf8Value(v8::Handle<v8::Value> obj)
: str_(NULL), length_(0) {
+ if (obj.IsEmpty()) return;
i::Isolate* isolate = i::Isolate::Current();
Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate);
- if (obj.IsEmpty()) return;
ENTER_V8(isolate);
i::HandleScope scope(isolate);
+ Local<Context> context = v8_isolate->GetCurrentContext();
TryCatch try_catch(v8_isolate);
- Handle<String> str = obj->ToString(v8_isolate);
- if (str.IsEmpty()) return;
+ Handle<String> str;
+ if (!obj->ToString(context).ToLocal(&str)) return;
i::Handle<i::String> i_str = Utils::OpenHandle(*str);
length_ = v8::Utf8Length(*i_str, isolate);
str_ = i::NewArray<char>(length_ + 1);
String::Value::Value(v8::Handle<v8::Value> obj)
: str_(NULL), length_(0) {
+ if (obj.IsEmpty()) return;
i::Isolate* isolate = i::Isolate::Current();
Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate);
- if (obj.IsEmpty()) return;
ENTER_V8(isolate);
i::HandleScope scope(isolate);
+ Local<Context> context = v8_isolate->GetCurrentContext();
TryCatch try_catch(v8_isolate);
- Handle<String> str = obj->ToString(v8_isolate);
- if (str.IsEmpty()) return;
+ Handle<String> str;
+ if (!obj->ToString(context).ToLocal(&str)) return;
length_ = str->Length();
str_ = i::NewArray<uint16_t>(length_ + 1);
str->Write(str_);
void ExternalizeStringExtension::Externalize(
const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() < 1 || !args[0]->IsString()) {
- args.GetIsolate()->ThrowException(v8::String::NewFromUtf8(
- args.GetIsolate(),
- "First parameter to externalizeString() must be a string."));
+ args.GetIsolate()->ThrowException(
+ v8::String::NewFromUtf8(
+ args.GetIsolate(),
+ "First parameter to externalizeString() must be a string.",
+ NewStringType::kNormal).ToLocalChecked());
return;
}
bool force_two_byte = false;
if (args.Length() >= 2) {
if (args[1]->IsBoolean()) {
- force_two_byte = args[1]->BooleanValue();
+ force_two_byte =
+ args[1]
+ ->BooleanValue(args.GetIsolate()->GetCurrentContext())
+ .FromJust();
} else {
- args.GetIsolate()->ThrowException(v8::String::NewFromUtf8(
- args.GetIsolate(),
- "Second parameter to externalizeString() must be a boolean."));
+ args.GetIsolate()->ThrowException(
+ v8::String::NewFromUtf8(
+ args.GetIsolate(),
+ "Second parameter to externalizeString() must be a boolean.",
+ NewStringType::kNormal).ToLocalChecked());
return;
}
}
bool result = false;
Handle<String> string = Utils::OpenHandle(*args[0].As<v8::String>());
if (string->IsExternalString()) {
- args.GetIsolate()->ThrowException(v8::String::NewFromUtf8(
- args.GetIsolate(),
- "externalizeString() can't externalize twice."));
+ args.GetIsolate()->ThrowException(
+ v8::String::NewFromUtf8(args.GetIsolate(),
+ "externalizeString() can't externalize twice.",
+ NewStringType::kNormal).ToLocalChecked());
return;
}
if (string->IsOneByteRepresentation() && !force_two_byte) {
if (!result) delete resource;
}
if (!result) {
- args.GetIsolate()->ThrowException(v8::String::NewFromUtf8(
- args.GetIsolate(), "externalizeString() failed."));
+ args.GetIsolate()->ThrowException(
+ v8::String::NewFromUtf8(args.GetIsolate(),
+ "externalizeString() failed.",
+ NewStringType::kNormal).ToLocalChecked());
return;
}
}
void ExternalizeStringExtension::IsOneByte(
const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 1 || !args[0]->IsString()) {
- args.GetIsolate()->ThrowException(v8::String::NewFromUtf8(
- args.GetIsolate(),
- "isOneByteString() requires a single string argument."));
+ args.GetIsolate()->ThrowException(
+ v8::String::NewFromUtf8(
+ args.GetIsolate(),
+ "isOneByteString() requires a single string argument.",
+ NewStringType::kNormal).ToLocalChecked());
return;
}
bool is_one_byte =
void GCExtension::GC(const v8::FunctionCallbackInfo<v8::Value>& args) {
args.GetIsolate()->RequestGarbageCollectionForTesting(
- args[0]->BooleanValue() ? v8::Isolate::kMinorGarbageCollection
- : v8::Isolate::kFullGarbageCollection);
+ args[0]
+ ->BooleanValue(args.GetIsolate()->GetCurrentContext())
+ .FromMaybe(false)
+ ? v8::Isolate::kMinorGarbageCollection
+ : v8::Isolate::kFullGarbageCollection);
}
} // namespace internal
StatsCounter* counter,
const char* name) {
if (counter->Enabled()) {
- object->Set(v8::String::NewFromUtf8(isolate, name),
- v8::Number::New(isolate, *counter->GetInternalPointer()));
+ object->Set(isolate->GetCurrentContext(),
+ v8::String::NewFromUtf8(isolate, name, NewStringType::kNormal)
+ .ToLocalChecked(),
+ v8::Number::New(isolate, *counter->GetInternalPointer()))
+ .FromJust();
}
}
v8::Local<v8::Object> object,
intptr_t value,
const char* name) {
- object->Set(v8::String::NewFromUtf8(isolate, name),
- v8::Number::New(isolate, static_cast<double>(value)));
+ object->Set(isolate->GetCurrentContext(),
+ v8::String::NewFromUtf8(isolate, name, NewStringType::kNormal)
+ .ToLocalChecked(),
+ v8::Number::New(isolate, static_cast<double>(value))).FromJust();
}
v8::Local<v8::Object> object,
int64_t value,
const char* name) {
- object->Set(v8::String::NewFromUtf8(isolate, name),
- v8::Number::New(isolate, static_cast<double>(value)));
+ object->Set(isolate->GetCurrentContext(),
+ v8::String::NewFromUtf8(isolate, name, NewStringType::kNormal)
+ .ToLocalChecked(),
+ v8::Number::New(isolate, static_cast<double>(value))).FromJust();
}
if (args.Length() > 0) { // GC if first argument evaluates to true.
if (args[0]->IsBoolean() &&
- args[0]->ToBoolean(args.GetIsolate())->Value()) {
+ args[0]
+ ->BooleanValue(args.GetIsolate()->GetCurrentContext())
+ .FromMaybe(false)) {
heap->CollectAllGarbage(Heap::kNoGCFlags, "counters extension");
}
}
NativeFunctionLiteral* expr) {
Comment cmnt(masm_, "[ NativeFunctionLiteral");
+ v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate());
+
// Compute the function template for the native function.
Handle<String> name = expr->name();
v8::Handle<v8::FunctionTemplate> fun_template =
- expr->extension()->GetNativeFunctionTemplate(
- reinterpret_cast<v8::Isolate*>(isolate()), v8::Utils::ToLocal(name));
+ expr->extension()->GetNativeFunctionTemplate(v8_isolate,
+ v8::Utils::ToLocal(name));
DCHECK(!fun_template.IsEmpty());
// Instantiate the function and create a shared function info from it.
- Handle<JSFunction> fun = Utils::OpenHandle(*fun_template->GetFunction());
+ Handle<JSFunction> fun = Utils::OpenHandle(
+ *fun_template->GetFunction(v8_isolate->GetCurrentContext())
+ .ToLocalChecked());
const int literals = fun->NumberOfLiterals();
Handle<Code> code = Handle<Code>(fun->shared()->code());
Handle<Code> construct_stub = Handle<Code>(fun->shared()->construct_stub());
}
if (!result.IsEmpty()) {
DCHECK(result->IsInt32());
- return Just(static_cast<PropertyAttributes>(result->Int32Value()));
+ return Just(static_cast<PropertyAttributes>(
+ result->Int32Value(reinterpret_cast<v8::Isolate*>(isolate)
+ ->GetCurrentContext()).FromJust()));
}
} else if (!interceptor->getter()->IsUndefined()) {
// TODO(verwaest): Use GetPropertyWithInterceptor?
RUNTIME_FUNCTION(Runtime_GetUndetectable) {
HandleScope scope(isolate);
DCHECK(args.length() == 0);
+ v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
- Local<v8::ObjectTemplate> desc =
- v8::ObjectTemplate::New((v8::Isolate*)isolate);
- desc->MarkAsUndetectable(); // undetectable
- Local<v8::Object> obj = desc->NewInstance();
+ Local<v8::ObjectTemplate> desc = v8::ObjectTemplate::New(v8_isolate);
+ desc->MarkAsUndetectable();
+ Local<v8::Object> obj;
+ if (!desc->NewInstance(v8_isolate->GetCurrentContext()).ToLocal(&obj)) {
+ return nullptr;
+ }
return *Utils::OpenHandle(*obj);
}
'include_dirs+': [
'../..',
],
+ 'defines': [
+ # TODO(jochen): Remove again after this is globally turned on.
+ 'V8_IMMINENT_DEPRECATION_WARNINGS',
+ ],
'sources': [ ### gcmole(all) ###
'../../src/accessors.cc',
'../../src/accessors.h',