#include "include/v8-profiler.h"
#include "include/v8-testing.h"
#include "src/assert-scope.h"
+#include "src/base/platform/platform.h"
+#include "src/base/platform/time.h"
+#include "src/base/utils/random-number-generator.h"
#include "src/bootstrapper.h"
#include "src/code-stubs.h"
#include "src/compiler.h"
#include "src/icu_util.h"
#include "src/json-parser.h"
#include "src/messages.h"
-#ifdef COMPRESS_STARTUP_DATA_BZ2
#include "src/natives.h"
-#endif
#include "src/parser.h"
-#include "src/platform.h"
-#include "src/platform/time.h"
#include "src/profile-generator-inl.h"
-#include "src/property-details.h"
#include "src/property.h"
+#include "src/property-details.h"
+#include "src/prototype.h"
#include "src/runtime.h"
#include "src/runtime-profiler.h"
#include "src/scanner-character-streams.h"
#include "src/simulator.h"
#include "src/snapshot.h"
#include "src/unicode-inl.h"
-#include "src/utils/random-number-generator.h"
#include "src/v8threads.h"
#include "src/version.h"
#include "src/vm-state-inl.h"
#define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr))
#define ENTER_V8(isolate) \
- ASSERT((isolate)->IsInitialized()); \
+ DCHECK((isolate)->IsInitialized()); \
i::VMState<i::OTHER> __state__((isolate))
namespace v8 {
#define EXCEPTION_PREAMBLE(isolate) \
(isolate)->handle_scope_implementer()->IncrementCallDepth(); \
- ASSERT(!(isolate)->external_caught_exception()); \
+ DCHECK(!(isolate)->external_caught_exception()); \
bool has_pending_exception = false
i::Isolate* isolate = i::Isolate::Current();
FatalErrorCallback callback = isolate->exception_behavior();
if (callback == NULL) {
- i::OS::PrintError("\n#\n# Fatal error in %s\n# %s\n#\n\n",
- location, message);
- i::OS::Abort();
+ base::OS::PrintError("\n#\n# Fatal error in %s\n# %s\n#\n\n", location,
+ message);
+ base::OS::Abort();
} else {
callback(location, message);
}
compressed_data[i].compressed_size);
if (result != 0) return result;
} else {
- ASSERT_EQ(0, compressed_data[i].raw_size);
+ DCHECK_EQ(0, compressed_data[i].raw_size);
}
compressed_data[i].data = decompressed;
}
void V8::SetDecompressedStartupData(StartupData* decompressed_data) {
#ifdef COMPRESS_STARTUP_DATA_BZ2
- ASSERT_EQ(i::Snapshot::raw_size(), decompressed_data[kSnapshot].raw_size);
+ DCHECK_EQ(i::Snapshot::raw_size(), decompressed_data[kSnapshot].raw_size);
i::Snapshot::set_raw_data(
reinterpret_cast<const i::byte*>(decompressed_data[kSnapshot].data));
- ASSERT_EQ(i::Snapshot::context_raw_size(),
+ DCHECK_EQ(i::Snapshot::context_raw_size(),
decompressed_data[kSnapshotContext].raw_size);
i::Snapshot::set_context_raw_data(
reinterpret_cast<const i::byte*>(
decompressed_data[kSnapshotContext].data));
- ASSERT_EQ(i::Natives::GetRawScriptsSize(),
+ DCHECK_EQ(i::Natives::GetRawScriptsSize(),
decompressed_data[kLibraries].raw_size);
i::Vector<const char> libraries_source(
decompressed_data[kLibraries].data,
decompressed_data[kLibraries].raw_size);
i::Natives::SetRawScriptsSource(libraries_source);
- ASSERT_EQ(i::ExperimentalNatives::GetRawScriptsSize(),
+ DCHECK_EQ(i::ExperimentalNatives::GetRawScriptsSize(),
decompressed_data[kExperimentalLibraries].raw_size);
i::Vector<const char> exp_libraries_source(
decompressed_data[kExperimentalLibraries].data,
}
+void V8::SetNativesDataBlob(StartupData* natives_blob) {
+#ifdef V8_USE_EXTERNAL_STARTUP_DATA
+ i::SetNativesFromFile(natives_blob);
+#else
+ CHECK(false);
+#endif
+}
+
+
+void V8::SetSnapshotDataBlob(StartupData* snapshot_blob) {
+#ifdef V8_USE_EXTERNAL_STARTUP_DATA
+ i::SetSnapshotFromFile(snapshot_blob);
+#else
+ CHECK(false);
+#endif
+}
+
+
void V8::SetFatalErrorHandler(FatalErrorCallback that) {
- i::Isolate* isolate = i::Isolate::UncheckedCurrent();
+ i::Isolate* isolate = i::Isolate::Current();
isolate->set_exception_behavior(that);
}
void V8::SetAllowCodeGenerationFromStringsCallback(
AllowCodeGenerationFromStringsCallback callback) {
- i::Isolate* isolate = i::Isolate::UncheckedCurrent();
+ i::Isolate* isolate = i::Isolate::Current();
isolate->set_allow_code_gen_callback(callback);
}
if (semi_space_size != 0 || old_space_size != 0 ||
max_executable_size != 0 || code_range_size != 0) {
// After initialization it's too late to change Heap constraints.
- ASSERT(!isolate->IsInitialized());
+ DCHECK(!isolate->IsInitialized());
bool result = isolate->heap()->ConfigureHeap(semi_space_size,
old_space_size,
max_executable_size,
i::Object** HandleScope::CreateHandle(i::HeapObject* heap_object,
i::Object* value) {
- ASSERT(heap_object->IsHeapObject());
+ DCHECK(heap_object->IsHeapObject());
return i::HandleScope::CreateHandle(heap_object->GetIsolate(), value);
}
if (data.is_null()) return;
i::Handle<i::Object> val = Utils::OpenHandle(*value);
data->set(index, *val);
- ASSERT_EQ(*Utils::OpenHandle(*value),
+ DCHECK_EQ(*Utils::OpenHandle(*value),
*Utils::OpenHandle(*GetEmbedderData(index)));
}
const char* location = "v8::Context::SetAlignedPointerInEmbedderData()";
i::Handle<i::FixedArray> data = EmbedderDataFor(this, index, true, location);
data->set(index, EncodeAlignedAsSmi(value, location));
- ASSERT_EQ(value, GetAlignedPointerFromEmbedderData(index));
+ DCHECK_EQ(value, GetAlignedPointerFromEmbedderData(index));
}
i::Object* NeanderArray::get(int offset) {
- ASSERT(0 <= offset);
- ASSERT(offset < length());
+ DCHECK(0 <= offset);
+ DCHECK(offset < length());
return obj_.get(offset + 1);
}
v8::Local<FunctionTemplate> setter,
v8::PropertyAttribute attribute,
v8::AccessControl access_control) {
+ // TODO(verwaest): Remove |access_control|.
+ DCHECK_EQ(v8::DEFAULT, access_control);
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ENTER_V8(isolate);
- ASSERT(!name.IsEmpty());
- ASSERT(!getter.IsEmpty() || !setter.IsEmpty());
+ DCHECK(!name.IsEmpty());
+ DCHECK(!getter.IsEmpty() || !setter.IsEmpty());
i::HandleScope scope(isolate);
const int kSize = 5;
v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
name,
getter,
setter,
- v8::Integer::New(v8_isolate, attribute),
- v8::Integer::New(v8_isolate, access_control)};
+ v8::Integer::New(v8_isolate, attribute)};
TemplateSet(isolate, this, kSize, data);
}
}
+Handle<Value> UnboundScript::GetSourceURL() {
+ i::Handle<i::SharedFunctionInfo> obj =
+ i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this));
+ i::Isolate* isolate = obj->GetIsolate();
+ ON_BAILOUT(isolate, "v8::UnboundScript::GetSourceURL()",
+ return Handle<String>());
+ LOG_API(isolate, "UnboundScript::GetSourceURL");
+ if (obj->script()->IsScript()) {
+ i::Object* url = i::Script::cast(obj->script())->source_url();
+ return Utils::ToLocal(i::Handle<i::Object>(url, isolate));
+ } else {
+ return Handle<String>();
+ }
+}
+
+
+Handle<Value> UnboundScript::GetSourceMappingURL() {
+ i::Handle<i::SharedFunctionInfo> obj =
+ i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this));
+ i::Isolate* isolate = obj->GetIsolate();
+ ON_BAILOUT(isolate, "v8::UnboundScript::GetSourceMappingURL()",
+ return Handle<String>());
+ LOG_API(isolate, "UnboundScript::GetSourceMappingURL");
+ if (obj->script()->IsScript()) {
+ i::Object* url = i::Script::cast(obj->script())->source_mapping_url();
+ return Utils::ToLocal(i::Handle<i::Object>(url, isolate));
+ } else {
+ return Handle<String>();
+ }
+}
+
+
Local<Value> Script::Run() {
i::Handle<i::Object> obj = Utils::OpenHandle(this, true);
// If execution is terminating, Compile(..)->Run() requires this
ON_BAILOUT(isolate, "v8::Script::Run()", return Local<Value>());
LOG_API(isolate, "Script::Run");
ENTER_V8(isolate);
- i::Logger::TimerEventScope timer_scope(
- isolate, i::Logger::TimerEventScope::v8_execute);
+ i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
i::HandleScope scope(isolate);
i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(obj);
EXCEPTION_PREAMBLE(isolate);
- i::Handle<i::Object> receiver(
- isolate->context()->global_proxy(), isolate);
+ i::Handle<i::Object> receiver(isolate->global_proxy(), isolate);
i::Handle<i::Object> result;
has_pending_exception = !i::Execution::Call(
isolate, fun, receiver, 0, NULL).ToHandle(&result);
Isolate* v8_isolate,
Source* source,
CompileOptions options) {
- i::ScriptData* script_data_impl = NULL;
- i::CachedDataMode cached_data_mode = i::NO_CACHED_DATA;
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
ON_BAILOUT(isolate, "v8::ScriptCompiler::CompileUnbound()",
return Local<UnboundScript>());
- if (options & kProduceDataToCache) {
- cached_data_mode = i::PRODUCE_CACHED_DATA;
- ASSERT(source->cached_data == NULL);
- if (source->cached_data) {
- // Asked to produce cached data even though there is some already -> not
- // good. Fail the compilation.
- EXCEPTION_PREAMBLE(isolate);
- i::Handle<i::Object> result = isolate->factory()->NewSyntaxError(
- "invalid_cached_data", isolate->factory()->NewJSArray(0));
- isolate->Throw(*result);
- isolate->ReportPendingMessages();
- has_pending_exception = true;
- EXCEPTION_BAILOUT_CHECK(isolate, Local<UnboundScript>());
- }
- } else if (source->cached_data) {
- cached_data_mode = i::CONSUME_CACHED_DATA;
- // ScriptData takes care of aligning, in case the data is not aligned
- // correctly.
- script_data_impl = i::ScriptData::New(
- reinterpret_cast<const char*>(source->cached_data->data),
- source->cached_data->length);
- // If the cached data is not valid, fail the compilation.
- if (script_data_impl == NULL || !script_data_impl->SanityCheck()) {
- EXCEPTION_PREAMBLE(isolate);
- i::Handle<i::Object> result = isolate->factory()->NewSyntaxError(
- "invalid_cached_data", isolate->factory()->NewJSArray(0));
- isolate->Throw(*result);
- isolate->ReportPendingMessages();
- delete script_data_impl;
- has_pending_exception = true;
- EXCEPTION_BAILOUT_CHECK(isolate, Local<UnboundScript>());
- }
+
+ // Support the old API for a transition period:
+ // - kProduceToCache -> kProduceParserCache
+ // - kNoCompileOptions + cached_data != NULL -> kConsumeParserCache
+ if (options == kProduceDataToCache) {
+ options = kProduceParserCache;
+ } else if (options == kNoCompileOptions && source->cached_data) {
+ options = kConsumeParserCache;
+ }
+
+ i::ScriptData* script_data = NULL;
+ if (options == kConsumeParserCache || options == kConsumeCodeCache) {
+ DCHECK(source->cached_data);
+ // ScriptData takes care of pointer-aligning the data.
+ script_data = new i::ScriptData(source->cached_data->data,
+ source->cached_data->length);
}
i::Handle<i::String> str = Utils::OpenHandle(*(source->source_string));
source->resource_is_shared_cross_origin == v8::True(v8_isolate);
}
EXCEPTION_PREAMBLE(isolate);
- i::Handle<i::SharedFunctionInfo> result =
- i::Compiler::CompileScript(str,
- name_obj,
- line_offset,
- column_offset,
- is_shared_cross_origin,
- isolate->global_context(),
- NULL,
- &script_data_impl,
- cached_data_mode,
- i::NOT_NATIVES_CODE);
+ i::Handle<i::SharedFunctionInfo> result = i::Compiler::CompileScript(
+ str, name_obj, line_offset, column_offset, is_shared_cross_origin,
+ isolate->global_context(), NULL, &script_data, options,
+ i::NOT_NATIVES_CODE);
has_pending_exception = result.is_null();
- if (has_pending_exception && cached_data_mode == i::CONSUME_CACHED_DATA) {
+ if (has_pending_exception && script_data != NULL) {
// This case won't happen during normal operation; we have compiled
// successfully and produced cached data, and but the second compilation
// of the same source code fails.
- delete script_data_impl;
- script_data_impl = NULL;
+ delete script_data;
+ script_data = NULL;
}
EXCEPTION_BAILOUT_CHECK(isolate, Local<UnboundScript>());
raw_result = *result;
- if ((options & kProduceDataToCache) && script_data_impl != NULL) {
- // script_data_impl now contains the data that was generated. source will
+
+ if ((options == kProduceParserCache || options == kProduceCodeCache) &&
+ script_data != NULL) {
+ // script_data now contains the data that was generated. source will
// take the ownership.
source->cached_data = new CachedData(
- reinterpret_cast<const uint8_t*>(script_data_impl->Data()),
- script_data_impl->Length(), CachedData::BufferOwned);
- script_data_impl->owns_store_ = false;
+ script_data->data(), script_data->length(), CachedData::BufferOwned);
+ script_data->ReleaseDataOwnership();
}
- delete script_data_impl;
+ delete script_data;
}
i::Handle<i::SharedFunctionInfo> result(raw_result, isolate);
return ToApiHandle<UnboundScript>(result);
capture_message_(true),
rethrow_(false),
has_terminated_(false) {
- Reset();
- js_stack_comparable_address_ = this;
-#ifdef V8_USE_ADDRESS_SANITIZER
- void* asan_fake_stack_handle = __asan_get_current_fake_stack();
- if (asan_fake_stack_handle != NULL) {
- js_stack_comparable_address_ = __asan_addr_is_in_fake_stack(
- asan_fake_stack_handle, js_stack_comparable_address_, NULL, NULL);
- CHECK(js_stack_comparable_address_ != NULL);
- }
-#endif
+ ResetInternal();
// Special handling for simulators which have a separate JS stack.
- js_stack_comparable_address_ = reinterpret_cast<void*>(
- v8::internal::SimulatorStack::RegisterCTryCatch(
- reinterpret_cast<uintptr_t>(js_stack_comparable_address_)));
+ js_stack_comparable_address_ =
+ reinterpret_cast<void*>(v8::internal::SimulatorStack::RegisterCTryCatch(
+ GetCurrentStackPosition()));
isolate_->RegisterTryCatchHandler(this);
}
v8::TryCatch::~TryCatch() {
- ASSERT(isolate_ == i::Isolate::Current());
+ DCHECK(isolate_ == i::Isolate::Current());
if (rethrow_) {
v8::Isolate* isolate = reinterpret_cast<Isolate*>(isolate_);
v8::HandleScope scope(isolate);
isolate_->UnregisterTryCatchHandler(this);
v8::internal::SimulatorStack::UnregisterCTryCatch();
reinterpret_cast<Isolate*>(isolate_)->ThrowException(exc);
- ASSERT(!isolate_->thread_local_top()->rethrowing_message_);
+ DCHECK(!isolate_->thread_local_top()->rethrowing_message_);
} else {
+ if (HasCaught() && isolate_->has_scheduled_exception()) {
+ // If an exception was caught but is still scheduled because no API call
+ // promoted it, then it is canceled to prevent it from being propagated.
+ // Note that this will not cancel termination exceptions.
+ isolate_->CancelScheduledExceptionFromTryCatch(this);
+ }
isolate_->UnregisterTryCatchHandler(this);
v8::internal::SimulatorStack::UnregisterCTryCatch();
}
v8::Local<Value> v8::TryCatch::Exception() const {
- ASSERT(isolate_ == i::Isolate::Current());
+ DCHECK(isolate_ == i::Isolate::Current());
if (HasCaught()) {
// Check for out of memory exception.
i::Object* exception = reinterpret_cast<i::Object*>(exception_);
v8::Local<Value> v8::TryCatch::StackTrace() const {
- ASSERT(isolate_ == i::Isolate::Current());
+ DCHECK(isolate_ == i::Isolate::Current());
if (HasCaught()) {
i::Object* raw_obj = reinterpret_cast<i::Object*>(exception_);
if (!raw_obj->IsJSObject()) return v8::Local<Value>();
i::HandleScope scope(isolate_);
i::Handle<i::JSObject> obj(i::JSObject::cast(raw_obj), isolate_);
i::Handle<i::String> name = isolate_->factory()->stack_string();
- if (!i::JSReceiver::HasProperty(obj, name)) return v8::Local<Value>();
+ EXCEPTION_PREAMBLE(isolate_);
+ Maybe<bool> maybe = i::JSReceiver::HasProperty(obj, name);
+ has_pending_exception = !maybe.has_value;
+ EXCEPTION_BAILOUT_CHECK(isolate_, v8::Local<Value>());
+ if (!maybe.value) return v8::Local<Value>();
i::Handle<i::Object> value;
if (!i::Object::GetProperty(obj, name).ToHandle(&value)) {
return v8::Local<Value>();
v8::Local<v8::Message> v8::TryCatch::Message() const {
- ASSERT(isolate_ == i::Isolate::Current());
+ DCHECK(isolate_ == i::Isolate::Current());
i::Object* message = reinterpret_cast<i::Object*>(message_obj_);
- ASSERT(message->IsJSMessageObject() || message->IsTheHole());
+ DCHECK(message->IsJSMessageObject() || message->IsTheHole());
if (HasCaught() && !message->IsTheHole()) {
return v8::Utils::MessageToLocal(i::Handle<i::Object>(message, isolate_));
} else {
void v8::TryCatch::Reset() {
- ASSERT(isolate_ == i::Isolate::Current());
+ DCHECK(isolate_ == i::Isolate::Current());
+ if (!rethrow_ && HasCaught() && isolate_->has_scheduled_exception()) {
+ // If an exception was caught but is still scheduled because no API call
+ // promoted it, then it is canceled to prevent it from being propagated.
+ // Note that this will not cancel termination exceptions.
+ isolate_->CancelScheduledExceptionFromTryCatch(this);
+ }
+ ResetInternal();
+}
+
+
+void v8::TryCatch::ResetInternal() {
i::Object* the_hole = isolate_->heap()->the_hole_value();
exception_ = the_hole;
message_obj_ = the_hole;
}
-v8::Handle<Value> Message::GetScriptResourceName() const {
+ScriptOrigin Message::GetScriptOrigin() const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
- ENTER_V8(isolate);
- EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
i::Handle<i::JSMessageObject> message =
i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
- // Return this.script.name.
- i::Handle<i::JSValue> script =
- i::Handle<i::JSValue>::cast(i::Handle<i::Object>(message->script(),
- isolate));
- i::Handle<i::Object> resource_name(i::Script::cast(script->value())->name(),
- isolate);
- return scope.Escape(Utils::ToLocal(resource_name));
+ i::Handle<i::Object> script_wraper =
+ i::Handle<i::Object>(message->script(), isolate);
+ i::Handle<i::JSValue> script_value =
+ i::Handle<i::JSValue>::cast(script_wraper);
+ i::Handle<i::Script> script(i::Script::cast(script_value->value()));
+ i::Handle<i::Object> scriptName(i::Script::GetNameOrSourceURL(script));
+ v8::Isolate* v8_isolate =
+ reinterpret_cast<v8::Isolate*>(script->GetIsolate());
+ v8::ScriptOrigin origin(
+ Utils::ToLocal(scriptName),
+ v8::Integer::New(v8_isolate, script->line_offset()->value()),
+ v8::Integer::New(v8_isolate, script->column_offset()->value()),
+ Handle<Boolean>(),
+ v8::Integer::New(v8_isolate, script->id()->value()));
+ return origin;
+}
+
+
+v8::Handle<Value> Message::GetScriptResourceName() const {
+ return GetScriptOrigin().ResourceName();
}
int Message::GetStartColumn() const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
+ ON_BAILOUT(isolate, "v8::Message::GetStartColumn()", return kNoColumnInfo);
ENTER_V8(isolate);
i::HandleScope scope(isolate);
i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this);
int Message::GetEndColumn() const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
+ ON_BAILOUT(isolate, "v8::Message::GetEndColumn()", return kNoColumnInfo);
ENTER_V8(isolate);
i::HandleScope scope(isolate);
i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this);
// --- S t a c k F r a m e ---
-int StackFrame::GetLineNumber() const {
- i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
+static int getIntProperty(const StackFrame* f, const char* propertyName,
+ int defaultValue) {
+ i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate();
ENTER_V8(isolate);
i::HandleScope scope(isolate);
- i::Handle<i::JSObject> self = Utils::OpenHandle(this);
- i::Handle<i::Object> line = i::Object::GetProperty(
- isolate, self, "lineNumber").ToHandleChecked();
- if (!line->IsSmi()) {
- return Message::kNoLineNumberInfo;
- }
- return i::Smi::cast(*line)->value();
+ i::Handle<i::JSObject> self = Utils::OpenHandle(f);
+ i::Handle<i::Object> obj =
+ i::Object::GetProperty(isolate, self, propertyName).ToHandleChecked();
+ return obj->IsSmi() ? i::Smi::cast(*obj)->value() : defaultValue;
+}
+
+
+int StackFrame::GetLineNumber() const {
+ return getIntProperty(this, "lineNumber", Message::kNoLineNumberInfo);
}
int StackFrame::GetColumn() const {
- i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
- ENTER_V8(isolate);
- i::HandleScope scope(isolate);
- i::Handle<i::JSObject> self = Utils::OpenHandle(this);
- i::Handle<i::Object> column = i::Object::GetProperty(
- isolate, self, "column").ToHandleChecked();
- if (!column->IsSmi()) {
- return Message::kNoColumnInfo;
- }
- return i::Smi::cast(*column)->value();
+ return getIntProperty(this, "column", Message::kNoColumnInfo);
}
int StackFrame::GetScriptId() const {
- i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
- ENTER_V8(isolate);
- i::HandleScope scope(isolate);
- i::Handle<i::JSObject> self = Utils::OpenHandle(this);
- i::Handle<i::Object> scriptId = i::Object::GetProperty(
- isolate, self, "scriptId").ToHandleChecked();
- if (!scriptId->IsSmi()) {
- return Message::kNoScriptIdInfo;
- }
- return i::Smi::cast(*scriptId)->value();
+ return getIntProperty(this, "scriptId", Message::kNoScriptIdInfo);
}
-Local<String> StackFrame::GetScriptName() const {
- i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
+static Local<String> getStringProperty(const StackFrame* f,
+ const char* propertyName) {
+ i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate();
ENTER_V8(isolate);
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
- i::Handle<i::JSObject> self = Utils::OpenHandle(this);
- i::Handle<i::Object> name = i::Object::GetProperty(
- isolate, self, "scriptName").ToHandleChecked();
- if (!name->IsString()) {
- return Local<String>();
- }
- return scope.Escape(Local<String>::Cast(Utils::ToLocal(name)));
+ i::Handle<i::JSObject> self = Utils::OpenHandle(f);
+ i::Handle<i::Object> obj =
+ i::Object::GetProperty(isolate, self, propertyName).ToHandleChecked();
+ return obj->IsString()
+ ? scope.Escape(Local<String>::Cast(Utils::ToLocal(obj)))
+ : Local<String>();
+}
+
+
+Local<String> StackFrame::GetScriptName() const {
+ return getStringProperty(this, "scriptName");
}
Local<String> StackFrame::GetScriptNameOrSourceURL() const {
- i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
- ENTER_V8(isolate);
- EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
- i::Handle<i::JSObject> self = Utils::OpenHandle(this);
- i::Handle<i::Object> name = i::Object::GetProperty(
- isolate, self, "scriptNameOrSourceURL").ToHandleChecked();
- if (!name->IsString()) {
- return Local<String>();
- }
- return scope.Escape(Local<String>::Cast(Utils::ToLocal(name)));
+ return getStringProperty(this, "scriptNameOrSourceURL");
}
Local<String> StackFrame::GetFunctionName() const {
- i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
- ENTER_V8(isolate);
- EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
- i::Handle<i::JSObject> self = Utils::OpenHandle(this);
- i::Handle<i::Object> name = i::Object::GetProperty(
- isolate, self, "functionName").ToHandleChecked();
- if (!name->IsString()) {
- return Local<String>();
- }
- return scope.Escape(Local<String>::Cast(Utils::ToLocal(name)));
+ return getStringProperty(this, "functionName");
}
-bool StackFrame::IsEval() const {
- i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
+static bool getBoolProperty(const StackFrame* f, const char* propertyName) {
+ i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate();
ENTER_V8(isolate);
i::HandleScope scope(isolate);
- i::Handle<i::JSObject> self = Utils::OpenHandle(this);
- i::Handle<i::Object> is_eval = i::Object::GetProperty(
- isolate, self, "isEval").ToHandleChecked();
- return is_eval->IsTrue();
+ i::Handle<i::JSObject> self = Utils::OpenHandle(f);
+ i::Handle<i::Object> obj =
+ i::Object::GetProperty(isolate, self, propertyName).ToHandleChecked();
+ return obj->IsTrue();
}
+bool StackFrame::IsEval() const { return getBoolProperty(this, "isEval"); }
+
bool StackFrame::IsConstructor() const {
- i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
- ENTER_V8(isolate);
- i::HandleScope scope(isolate);
- i::Handle<i::JSObject> self = Utils::OpenHandle(this);
- i::Handle<i::Object> is_constructor = i::Object::GetProperty(
- isolate, self, "isConstructor").ToHandleChecked();
- return is_constructor->IsTrue();
+ return getBoolProperty(this, "isConstructor");
}
bool Value::FullIsUndefined() const {
bool result = Utils::OpenHandle(this)->IsUndefined();
- ASSERT_EQ(result, QuickIsUndefined());
+ DCHECK_EQ(result, QuickIsUndefined());
return result;
}
bool Value::FullIsNull() const {
bool result = Utils::OpenHandle(this)->IsNull();
- ASSERT_EQ(result, QuickIsNull());
+ DCHECK_EQ(result, QuickIsNull());
return result;
}
bool Value::FullIsString() const {
bool result = Utils::OpenHandle(this)->IsString();
- ASSERT_EQ(result, QuickIsString());
+ DCHECK_EQ(result, QuickIsString());
return result;
}
EXCEPTION_PREAMBLE(isolate);
has_pending_exception = !i::Execution::ToNumber(
isolate, obj).ToHandle(&num);
- EXCEPTION_BAILOUT_CHECK(isolate, i::OS::nan_value());
+ EXCEPTION_BAILOUT_CHECK(isolate, base::OS::nan_value());
}
return num->Number();
}
}
-bool v8::Object::Set(v8::Handle<Value> key, v8::Handle<Value> value,
- v8::PropertyAttribute attribs) {
+bool v8::Object::Set(v8::Handle<Value> key, v8::Handle<Value> value) {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ON_BAILOUT(isolate, "v8::Object::Set()", return false);
ENTER_V8(isolate);
i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
EXCEPTION_PREAMBLE(isolate);
- has_pending_exception = i::Runtime::SetObjectProperty(
- isolate,
- self,
- key_obj,
- value_obj,
- static_cast<PropertyAttributes>(attribs),
- i::SLOPPY).is_null();
+ has_pending_exception =
+ i::Runtime::SetObjectProperty(isolate, self, key_obj, value_obj,
+ i::SLOPPY).is_null();
EXCEPTION_BAILOUT_CHECK(isolate, false);
return true;
}
i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
EXCEPTION_PREAMBLE(isolate);
- has_pending_exception = i::Runtime::ForceSetObjectProperty(
+ has_pending_exception = i::Runtime::DefineObjectProperty(
self,
key_obj,
value_obj,
EXCEPTION_BAILOUT_CHECK(isolate, static_cast<PropertyAttribute>(NONE));
}
i::Handle<i::Name> key_name = i::Handle<i::Name>::cast(key_obj);
- PropertyAttributes result =
+ EXCEPTION_PREAMBLE(isolate);
+ Maybe<PropertyAttributes> result =
i::JSReceiver::GetPropertyAttributes(self, key_name);
- if (result == ABSENT) return static_cast<PropertyAttribute>(NONE);
- return static_cast<PropertyAttribute>(result);
+ has_pending_exception = !result.has_value;
+ EXCEPTION_BAILOUT_CHECK(isolate, static_cast<PropertyAttribute>(NONE));
+ if (result.value == ABSENT) return static_cast<PropertyAttribute>(NONE);
+ return static_cast<PropertyAttribute>(result.value);
+}
+
+
+Local<Value> v8::Object::GetOwnPropertyDescriptor(Local<String> key) {
+ i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
+ ON_BAILOUT(isolate, "v8::Object::GetOwnPropertyDescriptor()",
+ return Local<Value>());
+ ENTER_V8(isolate);
+ i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
+ i::Handle<i::Name> key_name = Utils::OpenHandle(*key);
+ i::Handle<i::Object> args[] = { obj, key_name };
+ EXCEPTION_PREAMBLE(isolate);
+ i::Handle<i::Object> result;
+ has_pending_exception = !CallV8HeapFunction(
+ "ObjectGetOwnPropertyDescriptor",
+ isolate->factory()->undefined_value(),
+ ARRAY_SIZE(args),
+ args).ToHandle(&result);
+ EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>());
+ return Utils::ToLocal(result);
}
ON_BAILOUT(isolate, "v8::Object::GetPrototype()", return Local<v8::Value>());
ENTER_V8(isolate);
i::Handle<i::Object> self = Utils::OpenHandle(this);
- i::Handle<i::Object> result(self->GetPrototype(isolate), isolate);
- return Utils::ToLocal(result);
+ i::PrototypeIterator iter(isolate, self);
+ return Utils::ToLocal(i::PrototypeIterator::GetCurrent(iter));
}
// to propagate outside.
TryCatch try_catch;
EXCEPTION_PREAMBLE(isolate);
- i::MaybeHandle<i::Object> result = i::JSObject::SetPrototype(
- self, value_obj);
+ i::MaybeHandle<i::Object> result =
+ i::JSObject::SetPrototype(self, value_obj, false);
has_pending_exception = result.is_null();
EXCEPTION_BAILOUT_CHECK(isolate, false);
return true;
"v8::Object::FindInstanceInPrototypeChain()",
return Local<v8::Object>());
ENTER_V8(isolate);
- i::JSObject* object = *Utils::OpenHandle(this);
+ i::PrototypeIterator iter(isolate, *Utils::OpenHandle(this),
+ i::PrototypeIterator::START_AT_RECEIVER);
i::FunctionTemplateInfo* tmpl_info = *Utils::OpenHandle(*tmpl);
- while (!tmpl_info->IsTemplateFor(object)) {
- i::Object* prototype = object->GetPrototype();
- if (!prototype->IsJSObject()) return Local<Object>();
- object = i::JSObject::cast(prototype);
+ while (!tmpl_info->IsTemplateFor(iter.GetCurrent())) {
+ iter.Advance();
+ if (iter.IsAtEnd()) {
+ return Local<Object>();
+ }
}
- return Utils::ToLocal(i::Handle<i::JSObject>(object));
+ return Utils::ToLocal(
+ i::handle(i::JSObject::cast(iter.GetCurrent()), isolate));
}
}
-Local<Value> v8::Object::GetConstructor() {
- i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
- ON_BAILOUT(isolate, "v8::Object::GetConstructor()",
- return Local<v8::Function>());
- ENTER_V8(isolate);
- i::Handle<i::JSObject> self = Utils::OpenHandle(this);
- i::Handle<i::Object> constructor(self->GetConstructor(), isolate);
- return Utils::ToLocal(constructor);
-}
-
-
Local<String> v8::Object::GetConstructorName() {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ON_BAILOUT(isolate, "v8::Object::GetConstructorName()",
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ON_BAILOUT(isolate, "v8::Object::HasProperty()", return false);
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
- return i::JSReceiver::HasElement(self, index);
+ EXCEPTION_PREAMBLE(isolate);
+ Maybe<bool> maybe = i::JSReceiver::HasElement(self, index);
+ has_pending_exception = !maybe.has_value;
+ EXCEPTION_BAILOUT_CHECK(isolate, false);
+ return maybe.value;
}
i::JSObject::SetAccessor(Utils::OpenHandle(obj), info),
false);
if (result->IsUndefined()) return false;
- if (fast) i::JSObject::TransformToFastProperties(Utils::OpenHandle(obj), 0);
+ if (fast) i::JSObject::MigrateSlowToFast(Utils::OpenHandle(obj), 0);
return true;
}
Handle<Function> setter,
PropertyAttribute attribute,
AccessControl settings) {
+ // TODO(verwaest): Remove |settings|.
+ DCHECK_EQ(v8::DEFAULT, settings);
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ON_BAILOUT(isolate, "v8::Object::SetAccessorProperty()", return);
ENTER_V8(isolate);
v8::Utils::OpenHandle(*name),
getter_i,
setter_i,
- static_cast<PropertyAttributes>(attribute),
- settings);
+ static_cast<PropertyAttributes>(attribute));
}
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ON_BAILOUT(isolate, "v8::Object::HasOwnProperty()",
return false);
- return i::JSReceiver::HasOwnProperty(
- Utils::OpenHandle(this), Utils::OpenHandle(*key));
+ EXCEPTION_PREAMBLE(isolate);
+ Maybe<bool> maybe = i::JSReceiver::HasOwnProperty(Utils::OpenHandle(this),
+ Utils::OpenHandle(*key));
+ has_pending_exception = !maybe.has_value;
+ EXCEPTION_BAILOUT_CHECK(isolate, false);
+ return maybe.value;
}
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ON_BAILOUT(isolate, "v8::Object::HasRealNamedProperty()",
return false);
- return i::JSObject::HasRealNamedProperty(Utils::OpenHandle(this),
- Utils::OpenHandle(*key));
+ EXCEPTION_PREAMBLE(isolate);
+ Maybe<bool> maybe = i::JSObject::HasRealNamedProperty(
+ Utils::OpenHandle(this), Utils::OpenHandle(*key));
+ has_pending_exception = !maybe.has_value;
+ EXCEPTION_BAILOUT_CHECK(isolate, false);
+ return maybe.value;
}
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ON_BAILOUT(isolate, "v8::Object::HasRealIndexedProperty()",
return false);
- return i::JSObject::HasRealElementProperty(Utils::OpenHandle(this), index);
+ EXCEPTION_PREAMBLE(isolate);
+ Maybe<bool> maybe =
+ i::JSObject::HasRealElementProperty(Utils::OpenHandle(this), index);
+ has_pending_exception = !maybe.has_value;
+ EXCEPTION_BAILOUT_CHECK(isolate, false);
+ return maybe.value;
}
"v8::Object::HasRealNamedCallbackProperty()",
return false);
ENTER_V8(isolate);
- return i::JSObject::HasRealNamedCallbackProperty(Utils::OpenHandle(this),
- Utils::OpenHandle(*key));
+ EXCEPTION_PREAMBLE(isolate);
+ Maybe<bool> maybe = i::JSObject::HasRealNamedCallbackProperty(
+ Utils::OpenHandle(this), Utils::OpenHandle(*key));
+ has_pending_exception = !maybe.has_value;
+ EXCEPTION_BAILOUT_CHECK(isolate, false);
+ return maybe.value;
}
i::Handle<i::Map> new_map = i::Map::Copy(i::Handle<i::Map>(obj->map()));
new_map->set_is_access_check_needed(true);
- obj->set_map(*new_map);
+ i::JSObject::MigrateToMap(obj, new_map);
}
return Local<v8::Value>());
LOG_API(isolate, "Object::CallAsFunction");
ENTER_V8(isolate);
- i::Logger::TimerEventScope timer_scope(
- isolate, i::Logger::TimerEventScope::v8_execute);
+ i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
i::HandleScope scope(isolate);
i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv);
return Local<v8::Object>());
LOG_API(isolate, "Object::CallAsConstructor");
ENTER_V8(isolate);
- i::Logger::TimerEventScope timer_scope(
- isolate, i::Logger::TimerEventScope::v8_execute);
+ i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
i::HandleScope scope(isolate);
i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**));
has_pending_exception = !i::Execution::Call(
isolate, fun, obj, argc, args).ToHandle(&returned);
EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<v8::Object>());
- ASSERT(!delegate->IsUndefined());
+ DCHECK(!delegate->IsUndefined());
return Utils::ToLocal(scope.CloseAndEscape(returned));
}
return Local<v8::Object>();
return Local<v8::Object>());
LOG_API(isolate, "Function::NewInstance");
ENTER_V8(isolate);
- i::Logger::TimerEventScope timer_scope(
- isolate, i::Logger::TimerEventScope::v8_execute);
+ i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
i::Handle<i::JSFunction> function = Utils::OpenHandle(this);
STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**));
ON_BAILOUT(isolate, "v8::Function::Call()", return Local<v8::Value>());
LOG_API(isolate, "Function::Call");
ENTER_V8(isolate);
- i::Logger::TimerEventScope timer_scope(
- isolate, i::Logger::TimerEventScope::v8_execute);
+ i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
i::HandleScope scope(isolate);
i::Handle<i::JSFunction> fun = Utils::OpenHandle(this);
i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv);
class Visitor {
public:
- inline explicit Visitor()
- : utf8_length_(0),
- state_(kInitialState) {}
+ Visitor() : utf8_length_(0), state_(kInitialState) {}
void VisitOneByteString(const uint8_t* chars, int length) {
int utf8_length = 0;
uint8_t leaf_state) {
bool edge_surrogate = StartsWithSurrogate(leaf_state);
if (!(*state & kLeftmostEdgeIsCalculated)) {
- ASSERT(!(*state & kLeftmostEdgeIsSurrogate));
+ DCHECK(!(*state & kLeftmostEdgeIsSurrogate));
*state |= kLeftmostEdgeIsCalculated
| (edge_surrogate ? kLeftmostEdgeIsSurrogate : 0);
} else if (EndsWithSurrogate(*state) && edge_surrogate) {
uint8_t leaf_state) {
bool edge_surrogate = EndsWithSurrogate(leaf_state);
if (!(*state & kRightmostEdgeIsCalculated)) {
- ASSERT(!(*state & kRightmostEdgeIsSurrogate));
+ DCHECK(!(*state & kRightmostEdgeIsSurrogate));
*state |= (kRightmostEdgeIsCalculated
| (edge_surrogate ? kRightmostEdgeIsSurrogate : 0));
} else if (edge_surrogate && StartsWithSurrogate(*state)) {
static inline void MergeTerminal(int* length,
uint8_t state,
uint8_t* state_out) {
- ASSERT((state & kLeftmostEdgeIsCalculated) &&
+ DCHECK((state & kLeftmostEdgeIsCalculated) &&
(state & kRightmostEdgeIsCalculated));
if (EndsWithSurrogate(state) && StartsWithSurrogate(state)) {
*length -= unibrow::Utf8::kBytesSavedByCombiningSurrogates;
char* const buffer,
bool replace_invalid_utf8) {
using namespace unibrow;
- ASSERT(remaining > 0);
+ DCHECK(remaining > 0);
// We can't use a local buffer here because Encode needs to modify
// previous characters in the stream. We know, however, that
// exactly one character will be advanced.
character,
last_character,
replace_invalid_utf8);
- ASSERT(written == 1);
+ DCHECK(written == 1);
return written;
}
// Use a scratch buffer to check the required characters.
template<typename Char>
void Visit(const Char* chars, const int length) {
using namespace unibrow;
- ASSERT(!early_termination_);
+ DCHECK(!early_termination_);
if (length == 0) return;
// Copy state to stack.
char* buffer = buffer_;
for (; i < fast_length; i++) {
buffer +=
Utf8::EncodeOneByte(buffer, static_cast<uint8_t>(*chars++));
- ASSERT(capacity_ == -1 || (buffer - start_) <= capacity_);
+ DCHECK(capacity_ == -1 || (buffer - start_) <= capacity_);
}
} else {
for (; i < fast_length; i++) {
last_character,
replace_invalid_utf8_);
last_character = character;
- ASSERT(capacity_ == -1 || (buffer - start_) <= capacity_);
+ DCHECK(capacity_ == -1 || (buffer - start_) <= capacity_);
}
}
// Array is fully written. Exit.
return;
}
}
- ASSERT(!skip_capacity_check_);
+ DCHECK(!skip_capacity_check_);
// Slow loop. Must check capacity on each iteration.
int remaining_capacity = capacity_ - static_cast<int>(buffer - start_);
- ASSERT(remaining_capacity >= 0);
+ DCHECK(remaining_capacity >= 0);
for (; i < length && remaining_capacity > 0; i++) {
uint16_t character = *chars++;
// remaining_capacity is <= 3 bytes at this point, so we do not write out
i::Isolate* isolate = Utils::OpenHandle(string)->GetIsolate();
LOG_API(isolate, "String::Write");
ENTER_V8(isolate);
- ASSERT(start >= 0 && length >= -1);
+ DCHECK(start >= 0 && length >= -1);
i::Handle<i::String> str = Utils::OpenHandle(string);
isolate->string_tracker()->RecordWrite(str);
if (options & String::HINT_MANY_WRITES_EXPECTED) {
if (!InternalFieldOK(obj, index, location)) return;
i::Handle<i::Object> val = Utils::OpenHandle(*value);
obj->SetInternalField(index, *val);
- ASSERT_EQ(value, GetInternalField(index));
+ DCHECK_EQ(value, GetInternalField(index));
}
const char* location = "v8::Object::SetAlignedPointerInInternalField()";
if (!InternalFieldOK(obj, index, location)) return;
obj->SetInternalField(index, EncodeAlignedAsSmi(value, location));
- ASSERT_EQ(value, GetAlignedPointerFromInternalField(index));
+ DCHECK_EQ(value, GetAlignedPointerFromInternalField(index));
}
void v8::V8::InitializePlatform(Platform* platform) {
-#ifdef V8_USE_DEFAULT_PLATFORM
- FATAL("Can't override v8::Platform when using default implementation");
-#else
i::V8::InitializePlatform(platform);
-#endif
}
void v8::V8::ShutdownPlatform() {
-#ifdef V8_USE_DEFAULT_PLATFORM
- FATAL("Can't override v8::Platform when using default implementation");
-#else
i::V8::ShutdownPlatform();
-#endif
}
void v8::V8::SetEntropySource(EntropySource entropy_source) {
- i::RandomNumberGenerator::SetEntropySource(entropy_source);
+ base::RandomNumberGenerator::SetEntropySource(entropy_source);
}
bool v8::V8::SetFunctionEntryHook(Isolate* ext_isolate,
FunctionEntryHook entry_hook) {
- ASSERT(ext_isolate != NULL);
- ASSERT(entry_hook != NULL);
+ DCHECK(ext_isolate != NULL);
+ DCHECK(entry_hook != NULL);
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(ext_isolate);
void v8::V8::VisitHandlesForPartialDependence(
Isolate* exported_isolate, PersistentHandleVisitor* visitor) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(exported_isolate);
- ASSERT(isolate == i::Isolate::Current());
+ DCHECK(isolate == i::Isolate::Current());
i::DisallowHeapAllocation no_allocation;
VisitorAdapter visitor_adapter(visitor);
}
-bool v8::V8::IdleNotification(int hint) {
- // Returning true tells the caller that it need not
- // continue to call IdleNotification.
- i::Isolate* isolate = i::Isolate::Current();
- if (isolate == NULL || !isolate->IsInitialized()) return true;
- if (!i::FLAG_use_idle_notification) return true;
- return isolate->heap()->IdleNotification(hint);
-}
-
-
-void v8::V8::LowMemoryNotification() {
- i::Isolate* isolate = i::Isolate::Current();
- if (isolate == NULL || !isolate->IsInitialized()) return;
- isolate->heap()->CollectAllAvailableGarbage("low memory notification");
-}
-
-
-int v8::V8::ContextDisposedNotification() {
- i::Isolate* isolate = i::Isolate::Current();
- if (!isolate->IsInitialized()) return 0;
- return isolate->heap()->NotifyContextDisposed();
-}
-
-
bool v8::V8::InitializeICU(const char* icu_data_file) {
return i::InitializeICU(icu_data_file);
}
i::Isolate* isolate,
v8::ExtensionConfiguration* extensions,
v8::Handle<ObjectTemplate> global_template,
- v8::Handle<Value> global_object) {
+ v8::Handle<Value> maybe_global_proxy) {
i::Handle<i::Context> env;
// Enter V8 via an ENTER_V8 scope.
}
}
+ i::Handle<i::Object> proxy = Utils::OpenHandle(*maybe_global_proxy, true);
+ i::MaybeHandle<i::JSGlobalProxy> maybe_proxy;
+ if (!proxy.is_null()) {
+ maybe_proxy = i::Handle<i::JSGlobalProxy>::cast(proxy);
+ }
// Create the environment.
env = isolate->bootstrapper()->CreateEnvironment(
- Utils::OpenHandle(*global_object, true),
- proxy_template,
- extensions);
+ maybe_proxy, proxy_template, extensions);
// Restore the access check info on the global template.
if (!global_template.IsEmpty()) {
- ASSERT(!global_constructor.is_null());
- ASSERT(!proxy_constructor.is_null());
+ DCHECK(!global_constructor.is_null());
+ DCHECK(!proxy_constructor.is_null());
global_constructor->set_access_check_info(
proxy_constructor->access_check_info());
global_constructor->set_needs_access_check(
bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) {
i::Handle<i::String> obj = Utils::OpenHandle(this);
i::Isolate* isolate = obj->GetIsolate();
- if (i::StringShape(*obj).IsExternalTwoByte()) {
+ if (i::StringShape(*obj).IsExternal()) {
return false; // Already an external string.
}
ENTER_V8(isolate);
CHECK(resource && resource->data());
bool result = obj->MakeExternal(resource);
+ // Assert that if CanMakeExternal(), then externalizing actually succeeds.
+ DCHECK(!CanMakeExternal() || result);
if (result) {
- ASSERT(obj->IsExternalString());
+ DCHECK(obj->IsExternalString());
isolate->heap()->external_string_table()->AddString(*obj);
}
return result;
v8::String::ExternalAsciiStringResource* resource) {
i::Handle<i::String> obj = Utils::OpenHandle(this);
i::Isolate* isolate = obj->GetIsolate();
- if (i::StringShape(*obj).IsExternalTwoByte()) {
+ if (i::StringShape(*obj).IsExternal()) {
return false; // Already an external string.
}
ENTER_V8(isolate);
CHECK(resource && resource->data());
bool result = obj->MakeExternal(resource);
+ // Assert that if CanMakeExternal(), then externalizing actually succeeds.
+ DCHECK(!CanMakeExternal() || result);
if (result) {
- ASSERT(obj->IsExternalString());
+ DCHECK(obj->IsExternalString());
isolate->heap()->external_string_table()->AddString(*obj);
}
return result;
LOG_API(i_isolate, "Date::New");
if (std::isnan(time)) {
// Introduce only canonical NaN value into the VM, to avoid signaling NaNs.
- time = i::OS::nan_value();
+ time = base::OS::nan_value();
}
ENTER_V8(i_isolate);
EXCEPTION_PREAMBLE(i_isolate);
i::Handle<i::FixedArray> date_cache_version =
i::Handle<i::FixedArray>::cast(i_isolate->eternal_handles()->GetSingleton(
i::EternalHandles::DATE_CACHE_VERSION));
- ASSERT_EQ(1, date_cache_version->length());
+ DCHECK_EQ(1, date_cache_version->length());
CHECK(date_cache_version->get(0)->IsSmi());
date_cache_version->set(
0,
if ((flags & RegExp::kGlobal) != 0) flags_buf[num_flags++] = 'g';
if ((flags & RegExp::kMultiline) != 0) flags_buf[num_flags++] = 'm';
if ((flags & RegExp::kIgnoreCase) != 0) flags_buf[num_flags++] = 'i';
- ASSERT(num_flags <= static_cast<int>(ARRAY_SIZE(flags_buf)));
+ DCHECK(num_flags <= static_cast<int>(ARRAY_SIZE(flags_buf)));
return isolate->factory()->InternalizeOneByteString(
i::Vector<const uint8_t>(flags_buf, num_flags));
}
i::Handle<i::Object> b;
has_pending_exception = !i::Execution::Call(
isolate,
- handle(
- isolate->context()->global_object()->native_context()->is_promise()),
+ isolate->is_promise(),
isolate->factory()->undefined_value(),
ARRAY_SIZE(argv), argv,
false).ToHandle(&b);
i::Handle<i::Object> result;
has_pending_exception = !i::Execution::Call(
isolate,
- handle(isolate->context()->global_object()->native_context()->
- promise_create()),
+ isolate->promise_create(),
isolate->factory()->undefined_value(),
0, NULL,
false).ToHandle(&result);
i::Handle<i::Object> argv[] = { promise, Utils::OpenHandle(*value) };
has_pending_exception = i::Execution::Call(
isolate,
- handle(isolate->context()->global_object()->native_context()->
- promise_resolve()),
+ isolate->promise_resolve(),
isolate->factory()->undefined_value(),
ARRAY_SIZE(argv), argv,
false).is_null();
i::Handle<i::Object> argv[] = { promise, Utils::OpenHandle(*value) };
has_pending_exception = i::Execution::Call(
isolate,
- handle(isolate->context()->global_object()->native_context()->
- promise_reject()),
+ isolate->promise_reject(),
isolate->factory()->undefined_value(),
ARRAY_SIZE(argv), argv,
false).is_null();
i::Handle<i::Object> result;
has_pending_exception = !i::Execution::Call(
isolate,
- handle(isolate->context()->global_object()->native_context()->
- promise_chain()),
+ isolate->promise_chain(),
promise,
ARRAY_SIZE(argv), argv,
false).ToHandle(&result);
i::Handle<i::Object> result;
has_pending_exception = !i::Execution::Call(
isolate,
- handle(isolate->context()->global_object()->native_context()->
- promise_catch()),
+ isolate->promise_catch(),
promise,
ARRAY_SIZE(argv), argv,
false).ToHandle(&result);
i::Handle<i::Object> result;
has_pending_exception = !i::Execution::Call(
isolate,
- handle(isolate->context()->global_object()->native_context()->
- promise_then()),
+ isolate->promise_then(),
promise,
ARRAY_SIZE(argv), argv,
false).ToHandle(&result);
i::Handle<i::JSArrayBuffer> buffer;
if (obj->IsJSDataView()) {
i::Handle<i::JSDataView> data_view(i::JSDataView::cast(*obj));
- ASSERT(data_view->buffer()->IsJSArrayBuffer());
+ DCHECK(data_view->buffer()->IsJSArrayBuffer());
buffer = i::handle(i::JSArrayBuffer::cast(data_view->buffer()));
} else {
- ASSERT(obj->IsJSTypedArray());
+ DCHECK(obj->IsJSTypedArray());
buffer = i::JSTypedArray::cast(*obj)->GetBuffer();
}
return Utils::ToLocal(buffer);
i::Handle<i::JSArrayBuffer> buffer,
size_t byte_offset,
size_t byte_length) {
- ASSERT(byte_offset + byte_length <=
+ DCHECK(byte_offset + byte_length <=
static_cast<size_t>(buffer->byte_length()->Number()));
obj->set_buffer(*buffer);
isolate->factory()->NewJSTypedArray(array_type);
i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer);
- ASSERT(byte_offset % sizeof(ElementType) == 0);
+ DCHECK(byte_offset % sizeof(ElementType) == 0);
CHECK(length <= (std::numeric_limits<size_t>::max() / sizeof(ElementType)));
CHECK(length <= static_cast<size_t>(i::Smi::kMaxValue));
i::Handle<i::Object> symbol =
i::Object::GetPropertyOrElement(symbols, i_name).ToHandleChecked();
if (!symbol->IsSymbol()) {
- ASSERT(symbol->IsUndefined());
+ DCHECK(symbol->IsUndefined());
symbol = i_isolate->factory()->NewSymbol();
i::Handle<i::Symbol>::cast(symbol)->set_name(*i_name);
- i::JSObject::SetProperty(
- symbols, i_name, symbol, NONE, i::STRICT).Assert();
+ i::JSObject::SetProperty(symbols, i_name, symbol, i::STRICT).Assert();
}
return Utils::ToLocal(i::Handle<i::Symbol>::cast(symbol));
}
i::Handle<i::Object> symbol =
i::Object::GetPropertyOrElement(symbols, i_name).ToHandleChecked();
if (!symbol->IsSymbol()) {
- ASSERT(symbol->IsUndefined());
+ DCHECK(symbol->IsUndefined());
symbol = i_isolate->factory()->NewSymbol();
i::Handle<i::Symbol>::cast(symbol)->set_name(*i_name);
- i::JSObject::SetProperty(
- symbols, i_name, symbol, NONE, i::STRICT).Assert();
+ i::JSObject::SetProperty(symbols, i_name, symbol, i::STRICT).Assert();
}
return Utils::ToLocal(i::Handle<i::Symbol>::cast(symbol));
}
i::Handle<i::Object> symbol =
i::Object::GetPropertyOrElement(privates, i_name).ToHandleChecked();
if (!symbol->IsSymbol()) {
- ASSERT(symbol->IsUndefined());
+ DCHECK(symbol->IsUndefined());
symbol = i_isolate->factory()->NewPrivateSymbol();
i::Handle<i::Symbol>::cast(symbol)->set_name(*i_name);
- i::JSObject::SetProperty(
- privates, i_name, symbol, NONE, i::STRICT).Assert();
+ i::JSObject::SetProperty(privates, i_name, symbol, i::STRICT).Assert();
}
Local<Symbol> result = Utils::ToLocal(i::Handle<i::Symbol>::cast(symbol));
return v8::Handle<Private>(reinterpret_cast<Private*>(*result));
Local<Number> v8::Number::New(Isolate* isolate, double value) {
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
- ASSERT(internal_isolate->IsInitialized());
+ DCHECK(internal_isolate->IsInitialized());
if (std::isnan(value)) {
// Introduce only canonical NaN value into the VM, to avoid signaling NaNs.
- value = i::OS::nan_value();
+ value = base::OS::nan_value();
}
ENTER_V8(internal_isolate);
i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value);
Local<Integer> v8::Integer::New(Isolate* isolate, int32_t value) {
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
- ASSERT(internal_isolate->IsInitialized());
+ DCHECK(internal_isolate->IsInitialized());
if (i::Smi::IsValid(value)) {
return Utils::IntegerToLocal(i::Handle<i::Object>(i::Smi::FromInt(value),
internal_isolate));
Local<Integer> v8::Integer::NewFromUnsigned(Isolate* isolate, uint32_t value) {
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
- ASSERT(internal_isolate->IsInitialized());
+ DCHECK(internal_isolate->IsInitialized());
bool fits_into_int32_t = (value & (1 << 31)) == 0;
if (fits_into_int32_t) {
return Integer::New(isolate, static_cast<int32_t>(value));
}
-void V8::SetCounterFunction(CounterLookupCallback callback) {
- i::Isolate* isolate = i::Isolate::UncheckedCurrent();
- // TODO(svenpanne) The Isolate should really be a parameter.
- if (isolate == NULL) return;
- isolate->stats_table()->SetCounterFunction(callback);
-}
-
-
-void V8::SetCreateHistogramFunction(CreateHistogramCallback callback) {
- i::Isolate* isolate = i::Isolate::UncheckedCurrent();
- // TODO(svenpanne) The Isolate should really be a parameter.
- if (isolate == NULL) return;
- isolate->stats_table()->SetCreateHistogramFunction(callback);
- isolate->InitializeLoggingAndCounters();
- isolate->counters()->ResetHistograms();
-}
-
-
-void V8::SetAddHistogramSampleFunction(AddHistogramSampleCallback callback) {
- i::Isolate* isolate = i::Isolate::UncheckedCurrent();
- // TODO(svenpanne) The Isolate should really be a parameter.
- if (isolate == NULL) return;
- isolate->stats_table()->
- SetAddHistogramSampleFunction(callback);
-}
-
void V8::SetFailedAccessCheckCallbackFunction(
FailedAccessCheckCallback callback) {
i::Isolate* isolate = i::Isolate::Current();
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
i::Context* context = isolate->context();
if (context == NULL) return Local<Context>();
- i::Context* native_context = context->global_object()->native_context();
+ i::Context* native_context = context->native_context();
if (native_context == NULL) return Local<Context>();
return Utils::ToLocal(i::Handle<i::Context>(native_context));
}
i::NEW_SPACE, "Isolate::RequestGarbageCollection",
kGCCallbackFlagForced);
} else {
- ASSERT_EQ(kFullGarbageCollection, type);
+ DCHECK_EQ(kFullGarbageCollection, type);
reinterpret_cast<i::Isolate*>(this)->heap()->CollectAllGarbage(
i::Heap::kAbortIncrementalMarkingMask,
"Isolate::RequestGarbageCollection", kGCCallbackFlagForced);
Isolate* Isolate::GetCurrent() {
- i::Isolate* isolate = i::Isolate::UncheckedCurrent();
+ i::Isolate* isolate = i::Isolate::Current();
return reinterpret_cast<Isolate*>(isolate);
}
internal_ = reinterpret_cast<void*>(
new i::DisallowJavascriptExecution(i_isolate));
} else {
- ASSERT_EQ(THROW_ON_FAILURE, on_failure);
+ DCHECK_EQ(THROW_ON_FAILURE, on_failure);
internal_ = reinterpret_cast<void*>(
new i::ThrowOnJavascriptExecution(i_isolate));
}
}
+void Isolate::SetUseCounterCallback(UseCounterCallback callback) {
+ reinterpret_cast<i::Isolate*>(this)->SetUseCounterCallback(callback);
+}
+
+
void Isolate::SetCounterFunction(CounterLookupCallback callback) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
isolate->stats_table()->SetCounterFunction(callback);
}
+bool v8::Isolate::IdleNotification(int idle_time_in_ms) {
+ // Returning true tells the caller that it need not
+ // continue to call IdleNotification.
+ i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
+ if (!i::FLAG_use_idle_notification) return true;
+ return isolate->heap()->IdleNotification(idle_time_in_ms);
+}
+
+
+void v8::Isolate::LowMemoryNotification() {
+ i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
+ {
+ i::HistogramTimerScope idle_notification_scope(
+ isolate->counters()->gc_low_memory_notification());
+ isolate->heap()->CollectAllAvailableGarbage("low memory notification");
+ }
+}
+
+
+int v8::Isolate::ContextDisposedNotification() {
+ i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
+ return isolate->heap()->NotifyContextDisposed();
+}
+
+
String::Utf8Value::Utf8Value(v8::Handle<v8::Value> obj)
: str_(NULL), length_(0) {
i::Isolate* isolate = i::Isolate::Current();
}
-unsigned int CpuProfileNode::GetHitLineCount() const {
- const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
- return node->GetHitLineCount();
-}
-
-
-bool CpuProfileNode::GetLineTicks(LineTick* entries,
- unsigned int number) const {
- const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
- return node->GetLineTicks(entries, number);
-}
-
-
const char* CpuProfileNode::GetBailoutReason() const {
const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
return node->entry()->bailout_reason();
void CpuProfile::Delete() {
i::Isolate* isolate = i::Isolate::Current();
i::CpuProfiler* profiler = isolate->cpu_profiler();
- ASSERT(profiler != NULL);
+ DCHECK(profiler != NULL);
profiler->DeleteProfile(reinterpret_cast<i::CpuProfile*>(this));
}
int64_t CpuProfile::GetSampleTimestamp(int index) const {
const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
- return (profile->sample_timestamp(index) - i::TimeTicks()).InMicroseconds();
+ return (profile->sample_timestamp(index) - base::TimeTicks())
+ .InMicroseconds();
}
int64_t CpuProfile::GetStartTime() const {
const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
- return (profile->start_time() - i::TimeTicks()).InMicroseconds();
+ return (profile->start_time() - base::TimeTicks()).InMicroseconds();
}
int64_t CpuProfile::GetEndTime() const {
const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
- return (profile->end_time() - i::TimeTicks()).InMicroseconds();
+ return (profile->end_time() - base::TimeTicks()).InMicroseconds();
}
void CpuProfiler::SetSamplingInterval(int us) {
- ASSERT(us >= 0);
+ DCHECK(us >= 0);
return reinterpret_cast<i::CpuProfiler*>(this)->set_sampling_interval(
- i::TimeDelta::FromMicroseconds(us));
+ base::TimeDelta::FromMicroseconds(us));
}
void CpuProfiler::SetIdle(bool is_idle) {
i::Isolate* isolate = reinterpret_cast<i::CpuProfiler*>(this)->isolate();
i::StateTag state = isolate->current_vm_state();
- ASSERT(state == i::EXTERNAL || state == i::IDLE);
+ DCHECK(state == i::EXTERNAL || state == i::IDLE);
if (isolate->js_entry_sp() != NULL) return;
if (is_idle) {
isolate->set_current_vm_state(i::IDLE);
(last_handle_before_deferred_block_ <= &block[kHandleBlockSize]) &&
(last_handle_before_deferred_block_ >= block)) {
v->VisitPointers(block, last_handle_before_deferred_block_);
- ASSERT(!found_block_before_deferred);
+ DCHECK(!found_block_before_deferred);
#ifdef DEBUG
found_block_before_deferred = true;
#endif
}
}
- ASSERT(last_handle_before_deferred_block_ == NULL ||
+ DCHECK(last_handle_before_deferred_block_ == NULL ||
found_block_before_deferred);
// Iterate over live handles in the last block (if any).
Object** block_start = blocks_.last();
Object** block_limit = &block_start[kHandleBlockSize];
// We should not need to check for SealHandleScope here. Assert this.
- ASSERT(prev_limit == block_limit ||
+ DCHECK(prev_limit == block_limit ||
!(block_start <= prev_limit && prev_limit <= block_limit));
if (prev_limit == block_limit) break;
deferred->blocks_.Add(blocks_.last());
// HandleScope stack since BeginDeferredScope was called, but in
// reverse order.
- ASSERT(prev_limit == NULL || !blocks_.is_empty());
+ DCHECK(prev_limit == NULL || !blocks_.is_empty());
- ASSERT(!blocks_.is_empty() && prev_limit != NULL);
- ASSERT(last_handle_before_deferred_block_ != NULL);
+ DCHECK(!blocks_.is_empty() && prev_limit != NULL);
+ DCHECK(last_handle_before_deferred_block_ != NULL);
last_handle_before_deferred_block_ = NULL;
return deferred;
}
void HandleScopeImplementer::BeginDeferredScope() {
- ASSERT(last_handle_before_deferred_block_ == NULL);
+ DCHECK(last_handle_before_deferred_block_ == NULL);
last_handle_before_deferred_block_ = isolate()->handle_scope_data()->next;
}
void DeferredHandles::Iterate(ObjectVisitor* v) {
- ASSERT(!blocks_.is_empty());
+ DCHECK(!blocks_.is_empty());
- ASSERT((first_block_limit_ >= blocks_.first()) &&
+ DCHECK((first_block_limit_ >= blocks_.first()) &&
(first_block_limit_ <= &(blocks_.first())[kHandleBlockSize]));
v->VisitPointers(blocks_.first(), first_block_limit_);