2012-01-10 10:05:45 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
#include "api.h"
|
2010-10-01 14:10:47 +00:00
|
|
|
|
2012-01-25 16:31:25 +00:00
|
|
|
#include <string.h> // For memcpy, strlen.
|
2014-05-20 10:13:46 +00:00
|
|
|
#ifdef V8_USE_ADDRESS_SANITIZER
|
|
|
|
#include <sanitizer/asan_interface.h>
|
|
|
|
#endif // V8_USE_ADDRESS_SANITIZER
|
2014-05-22 15:27:57 +00:00
|
|
|
#include <cmath> // For isnan.
|
2012-01-25 16:31:25 +00:00
|
|
|
#include "../include/v8-debug.h"
|
|
|
|
#include "../include/v8-profiler.h"
|
|
|
|
#include "../include/v8-testing.h"
|
2013-06-03 15:32:22 +00:00
|
|
|
#include "assert-scope.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "bootstrapper.h"
|
2012-07-17 15:18:15 +00:00
|
|
|
#include "code-stubs.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "compiler.h"
|
2012-01-25 16:31:25 +00:00
|
|
|
#include "conversions-inl.h"
|
|
|
|
#include "counters.h"
|
2013-07-03 15:39:18 +00:00
|
|
|
#include "cpu-profiler.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "debug.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
#include "deoptimizer.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "execution.h"
|
|
|
|
#include "global-handles.h"
|
2010-06-15 11:44:07 +00:00
|
|
|
#include "heap-profiler.h"
|
2013-02-21 12:10:40 +00:00
|
|
|
#include "heap-snapshot-generator-inl.h"
|
2013-07-11 09:58:54 +00:00
|
|
|
#include "icu_util.h"
|
2013-08-05 11:14:46 +00:00
|
|
|
#include "json-parser.h"
|
2010-03-09 06:38:33 +00:00
|
|
|
#include "messages.h"
|
2012-02-20 11:01:17 +00:00
|
|
|
#ifdef COMPRESS_STARTUP_DATA_BZ2
|
|
|
|
#include "natives.h"
|
|
|
|
#endif
|
2010-10-01 14:10:47 +00:00
|
|
|
#include "parser.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "platform.h"
|
2013-09-04 11:55:28 +00:00
|
|
|
#include "platform/time.h"
|
2010-04-06 14:54:20 +00:00
|
|
|
#include "profile-generator-inl.h"
|
2012-01-25 16:31:25 +00:00
|
|
|
#include "property-details.h"
|
|
|
|
#include "property.h"
|
2013-04-25 12:02:23 +00:00
|
|
|
#include "runtime.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
#include "runtime-profiler.h"
|
2011-09-08 13:06:44 +00:00
|
|
|
#include "scanner-character-streams.h"
|
2014-05-20 10:13:46 +00:00
|
|
|
#include "simulator.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "snapshot.h"
|
2012-01-25 16:31:25 +00:00
|
|
|
#include "unicode-inl.h"
|
2013-09-10 11:13:55 +00:00
|
|
|
#include "utils/random-number-generator.h"
|
2009-01-23 17:22:23 +00:00
|
|
|
#include "v8threads.h"
|
2009-04-30 09:29:15 +00:00
|
|
|
#include "version.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
#include "vm-state-inl.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
#define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr))
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-04-24 14:44:08 +00:00
|
|
|
#define ENTER_V8(isolate) \
|
|
|
|
ASSERT((isolate)->IsInitialized()); \
|
|
|
|
i::VMState<i::OTHER> __state__((isolate))
|
2009-03-30 13:32:28 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
namespace v8 {
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
#define ON_BAILOUT(isolate, location, code) \
|
2013-09-23 14:15:21 +00:00
|
|
|
if (IsExecutionTerminatingCheck(isolate)) { \
|
2010-05-21 20:52:19 +00:00
|
|
|
code; \
|
|
|
|
UNREACHABLE(); \
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-24 18:49:45 +00:00
|
|
|
#define EXCEPTION_PREAMBLE(isolate) \
|
|
|
|
(isolate)->handle_scope_implementer()->IncrementCallDepth(); \
|
|
|
|
ASSERT(!(isolate)->external_caught_exception()); \
|
2008-07-03 15:10:15 +00:00
|
|
|
bool has_pending_exception = false
|
|
|
|
|
|
|
|
|
2012-01-04 08:48:35 +00:00
|
|
|
#define EXCEPTION_BAILOUT_CHECK_GENERIC(isolate, value, do_callback) \
|
2008-07-03 15:10:15 +00:00
|
|
|
do { \
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScopeImplementer* handle_scope_implementer = \
|
2011-03-24 18:49:45 +00:00
|
|
|
(isolate)->handle_scope_implementer(); \
|
2011-03-18 20:35:07 +00:00
|
|
|
handle_scope_implementer->DecrementCallDepth(); \
|
2008-07-03 15:10:15 +00:00
|
|
|
if (has_pending_exception) { \
|
2011-03-18 20:35:07 +00:00
|
|
|
bool call_depth_is_zero = handle_scope_implementer->CallDepthIsZero(); \
|
2011-03-24 18:49:45 +00:00
|
|
|
(isolate)->OptionalRescheduleException(call_depth_is_zero); \
|
2012-01-04 08:48:35 +00:00
|
|
|
do_callback \
|
2008-07-03 15:10:15 +00:00
|
|
|
return value; \
|
|
|
|
} \
|
2012-01-04 08:48:35 +00:00
|
|
|
do_callback \
|
2008-07-03 15:10:15 +00:00
|
|
|
} while (false)
|
|
|
|
|
|
|
|
|
2012-01-04 08:48:35 +00:00
|
|
|
#define EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, value) \
|
|
|
|
EXCEPTION_BAILOUT_CHECK_GENERIC( \
|
2014-04-25 13:49:22 +00:00
|
|
|
isolate, value, isolate->FireCallCompletedCallback();)
|
2012-01-04 08:48:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define EXCEPTION_BAILOUT_CHECK(isolate, value) \
|
|
|
|
EXCEPTION_BAILOUT_CHECK_GENERIC(isolate, value, ;)
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// --- E x c e p t i o n B e h a v i o r ---
|
|
|
|
|
|
|
|
|
2010-11-15 13:23:30 +00:00
|
|
|
void i::FatalProcessOutOfMemory(const char* location) {
|
|
|
|
i::V8::FatalProcessOutOfMemory(location, false);
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// When V8 cannot allocated memory FatalProcessOutOfMemory is called.
|
|
|
|
// The default fatal error handler is called and execution is stopped.
|
2010-08-05 14:12:50 +00:00
|
|
|
void i::V8::FatalProcessOutOfMemory(const char* location, bool take_snapshot) {
|
2009-12-04 10:18:30 +00:00
|
|
|
i::HeapStats heap_stats;
|
|
|
|
int start_marker;
|
|
|
|
heap_stats.start_marker = &start_marker;
|
|
|
|
int new_space_size;
|
|
|
|
heap_stats.new_space_size = &new_space_size;
|
|
|
|
int new_space_capacity;
|
|
|
|
heap_stats.new_space_capacity = &new_space_capacity;
|
2010-09-30 07:22:53 +00:00
|
|
|
intptr_t old_pointer_space_size;
|
2009-12-04 10:18:30 +00:00
|
|
|
heap_stats.old_pointer_space_size = &old_pointer_space_size;
|
2010-09-30 07:22:53 +00:00
|
|
|
intptr_t old_pointer_space_capacity;
|
2009-12-04 10:18:30 +00:00
|
|
|
heap_stats.old_pointer_space_capacity = &old_pointer_space_capacity;
|
2010-09-30 07:22:53 +00:00
|
|
|
intptr_t old_data_space_size;
|
2009-12-04 10:18:30 +00:00
|
|
|
heap_stats.old_data_space_size = &old_data_space_size;
|
2010-09-30 07:22:53 +00:00
|
|
|
intptr_t old_data_space_capacity;
|
2009-12-04 10:18:30 +00:00
|
|
|
heap_stats.old_data_space_capacity = &old_data_space_capacity;
|
2010-09-30 07:22:53 +00:00
|
|
|
intptr_t code_space_size;
|
2009-12-04 10:18:30 +00:00
|
|
|
heap_stats.code_space_size = &code_space_size;
|
2010-09-30 07:22:53 +00:00
|
|
|
intptr_t code_space_capacity;
|
2009-12-04 10:18:30 +00:00
|
|
|
heap_stats.code_space_capacity = &code_space_capacity;
|
2010-09-30 07:22:53 +00:00
|
|
|
intptr_t map_space_size;
|
2009-12-04 10:18:30 +00:00
|
|
|
heap_stats.map_space_size = &map_space_size;
|
2010-09-30 07:22:53 +00:00
|
|
|
intptr_t map_space_capacity;
|
2009-12-04 10:18:30 +00:00
|
|
|
heap_stats.map_space_capacity = &map_space_capacity;
|
2010-09-30 07:22:53 +00:00
|
|
|
intptr_t cell_space_size;
|
2009-12-04 10:18:30 +00:00
|
|
|
heap_stats.cell_space_size = &cell_space_size;
|
2010-09-30 07:22:53 +00:00
|
|
|
intptr_t cell_space_capacity;
|
2009-12-04 10:18:30 +00:00
|
|
|
heap_stats.cell_space_capacity = &cell_space_capacity;
|
2013-06-12 15:03:44 +00:00
|
|
|
intptr_t property_cell_space_size;
|
|
|
|
heap_stats.property_cell_space_size = &property_cell_space_size;
|
|
|
|
intptr_t property_cell_space_capacity;
|
|
|
|
heap_stats.property_cell_space_capacity = &property_cell_space_capacity;
|
2010-09-30 07:22:53 +00:00
|
|
|
intptr_t lo_space_size;
|
2009-12-04 10:18:30 +00:00
|
|
|
heap_stats.lo_space_size = &lo_space_size;
|
|
|
|
int global_handle_count;
|
|
|
|
heap_stats.global_handle_count = &global_handle_count;
|
|
|
|
int weak_global_handle_count;
|
|
|
|
heap_stats.weak_global_handle_count = &weak_global_handle_count;
|
|
|
|
int pending_global_handle_count;
|
|
|
|
heap_stats.pending_global_handle_count = &pending_global_handle_count;
|
|
|
|
int near_death_global_handle_count;
|
|
|
|
heap_stats.near_death_global_handle_count = &near_death_global_handle_count;
|
2011-06-06 15:23:04 +00:00
|
|
|
int free_global_handle_count;
|
|
|
|
heap_stats.free_global_handle_count = &free_global_handle_count;
|
2010-09-30 07:22:53 +00:00
|
|
|
intptr_t memory_allocator_size;
|
2010-08-05 14:12:50 +00:00
|
|
|
heap_stats.memory_allocator_size = &memory_allocator_size;
|
2010-09-30 07:22:53 +00:00
|
|
|
intptr_t memory_allocator_capacity;
|
2010-08-05 14:12:50 +00:00
|
|
|
heap_stats.memory_allocator_capacity = &memory_allocator_capacity;
|
|
|
|
int objects_per_type[LAST_TYPE + 1] = {0};
|
|
|
|
heap_stats.objects_per_type = objects_per_type;
|
|
|
|
int size_per_type[LAST_TYPE + 1] = {0};
|
|
|
|
heap_stats.size_per_type = size_per_type;
|
2010-08-13 11:11:36 +00:00
|
|
|
int os_error;
|
|
|
|
heap_stats.os_error = &os_error;
|
2009-12-04 10:18:30 +00:00
|
|
|
int end_marker;
|
|
|
|
heap_stats.end_marker = &end_marker;
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2013-01-10 15:53:11 +00:00
|
|
|
if (isolate->heap()->HasBeenSetUp()) {
|
|
|
|
// BUG(1718): Don't use the take_snapshot since we don't support
|
|
|
|
// HeapIterator here without doing a special GC.
|
|
|
|
isolate->heap()->RecordStats(&heap_stats, false);
|
|
|
|
}
|
2014-01-13 09:42:23 +00:00
|
|
|
Utils::ApiCheck(false, location, "Allocation failed - process out of memory");
|
|
|
|
// If the fatal error handler returns, we stop execution.
|
2013-09-03 09:45:55 +00:00
|
|
|
FATAL("API fatal error handler returned after process out of memory");
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-13 09:42:23 +00:00
|
|
|
void Utils::ReportApiFailure(const char* location, const char* message) {
|
2013-09-03 09:35:26 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2014-01-14 09:37:45 +00:00
|
|
|
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();
|
|
|
|
} else {
|
|
|
|
callback(location, message);
|
|
|
|
}
|
2013-09-03 09:35:26 +00:00
|
|
|
isolate->SignalFatalError();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool V8::IsDead() {
|
2013-09-03 09:35:26 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
return isolate->IsDead();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-25 13:32:06 +00:00
|
|
|
static inline bool IsExecutionTerminatingCheck(i::Isolate* isolate) {
|
|
|
|
if (!isolate->IsInitialized()) return false;
|
|
|
|
if (isolate->has_scheduled_exception()) {
|
|
|
|
return isolate->scheduled_exception() ==
|
|
|
|
isolate->heap()->termination_exception();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// --- S t a t i c s ---
|
|
|
|
|
|
|
|
|
2013-06-28 13:40:41 +00:00
|
|
|
static bool InitializeHelper(i::Isolate* isolate) {
|
|
|
|
// If the isolate has a function entry hook, it needs to re-build all its
|
|
|
|
// code stubs with entry hooks embedded, so let's deserialize a snapshot.
|
|
|
|
if (isolate == NULL || isolate->function_entry_hook() == NULL) {
|
|
|
|
if (i::Snapshot::Initialize())
|
|
|
|
return true;
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
return i::V8::Initialize(NULL);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
static inline bool EnsureInitializedForIsolate(i::Isolate* isolate,
|
|
|
|
const char* location) {
|
2014-01-13 09:42:23 +00:00
|
|
|
return (isolate != NULL && isolate->IsInitialized()) ||
|
|
|
|
Utils::ApiCheck(InitializeHelper(isolate),
|
|
|
|
location,
|
|
|
|
"Error initializing V8");
|
2011-03-18 18:49:56 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2011-06-06 20:47:30 +00:00
|
|
|
StartupDataDecompressor::StartupDataDecompressor()
|
|
|
|
: raw_data(i::NewArray<char*>(V8::GetCompressedStartupDataCount())) {
|
|
|
|
for (int i = 0; i < V8::GetCompressedStartupDataCount(); ++i) {
|
|
|
|
raw_data[i] = NULL;
|
2011-06-06 20:58:25 +00:00
|
|
|
}
|
2011-06-06 20:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
StartupDataDecompressor::~StartupDataDecompressor() {
|
|
|
|
for (int i = 0; i < V8::GetCompressedStartupDataCount(); ++i) {
|
|
|
|
i::DeleteArray(raw_data[i]);
|
|
|
|
}
|
|
|
|
i::DeleteArray(raw_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int StartupDataDecompressor::Decompress() {
|
|
|
|
int compressed_data_count = V8::GetCompressedStartupDataCount();
|
|
|
|
StartupData* compressed_data =
|
|
|
|
i::NewArray<StartupData>(compressed_data_count);
|
|
|
|
V8::GetCompressedStartupData(compressed_data);
|
|
|
|
for (int i = 0; i < compressed_data_count; ++i) {
|
|
|
|
char* decompressed = raw_data[i] =
|
|
|
|
i::NewArray<char>(compressed_data[i].raw_size);
|
|
|
|
if (compressed_data[i].compressed_size != 0) {
|
|
|
|
int result = DecompressData(decompressed,
|
|
|
|
&compressed_data[i].raw_size,
|
|
|
|
compressed_data[i].data,
|
|
|
|
compressed_data[i].compressed_size);
|
|
|
|
if (result != 0) return result;
|
|
|
|
} else {
|
|
|
|
ASSERT_EQ(0, compressed_data[i].raw_size);
|
|
|
|
}
|
|
|
|
compressed_data[i].data = decompressed;
|
|
|
|
}
|
|
|
|
V8::SetDecompressedStartupData(compressed_data);
|
2012-02-20 11:01:17 +00:00
|
|
|
i::DeleteArray(compressed_data);
|
2011-06-06 20:47:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-29 12:08:33 +00:00
|
|
|
StartupData::CompressionAlgorithm V8::GetCompressedStartupDataAlgorithm() {
|
|
|
|
#ifdef COMPRESS_STARTUP_DATA_BZ2
|
|
|
|
return StartupData::kBZip2;
|
|
|
|
#else
|
|
|
|
return StartupData::kUncompressed;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enum CompressedStartupDataItems {
|
|
|
|
kSnapshot = 0,
|
|
|
|
kSnapshotContext,
|
2011-06-06 20:47:30 +00:00
|
|
|
kLibraries,
|
|
|
|
kExperimentalLibraries,
|
2011-04-29 12:08:33 +00:00
|
|
|
kCompressedStartupDataCount
|
|
|
|
};
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2011-04-29 12:08:33 +00:00
|
|
|
int V8::GetCompressedStartupDataCount() {
|
|
|
|
#ifdef COMPRESS_STARTUP_DATA_BZ2
|
|
|
|
return kCompressedStartupDataCount;
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void V8::GetCompressedStartupData(StartupData* compressed_data) {
|
|
|
|
#ifdef COMPRESS_STARTUP_DATA_BZ2
|
|
|
|
compressed_data[kSnapshot].data =
|
|
|
|
reinterpret_cast<const char*>(i::Snapshot::data());
|
|
|
|
compressed_data[kSnapshot].compressed_size = i::Snapshot::size();
|
|
|
|
compressed_data[kSnapshot].raw_size = i::Snapshot::raw_size();
|
|
|
|
|
|
|
|
compressed_data[kSnapshotContext].data =
|
|
|
|
reinterpret_cast<const char*>(i::Snapshot::context_data());
|
|
|
|
compressed_data[kSnapshotContext].compressed_size =
|
|
|
|
i::Snapshot::context_size();
|
|
|
|
compressed_data[kSnapshotContext].raw_size = i::Snapshot::context_raw_size();
|
2011-06-06 20:47:30 +00:00
|
|
|
|
|
|
|
i::Vector<const i::byte> libraries_source = i::Natives::GetScriptsSource();
|
|
|
|
compressed_data[kLibraries].data =
|
|
|
|
reinterpret_cast<const char*>(libraries_source.start());
|
|
|
|
compressed_data[kLibraries].compressed_size = libraries_source.length();
|
|
|
|
compressed_data[kLibraries].raw_size = i::Natives::GetRawScriptsSize();
|
|
|
|
|
|
|
|
i::Vector<const i::byte> exp_libraries_source =
|
|
|
|
i::ExperimentalNatives::GetScriptsSource();
|
|
|
|
compressed_data[kExperimentalLibraries].data =
|
|
|
|
reinterpret_cast<const char*>(exp_libraries_source.start());
|
|
|
|
compressed_data[kExperimentalLibraries].compressed_size =
|
|
|
|
exp_libraries_source.length();
|
|
|
|
compressed_data[kExperimentalLibraries].raw_size =
|
|
|
|
i::ExperimentalNatives::GetRawScriptsSize();
|
2011-04-29 12:08:33 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void V8::SetDecompressedStartupData(StartupData* decompressed_data) {
|
|
|
|
#ifdef COMPRESS_STARTUP_DATA_BZ2
|
|
|
|
ASSERT_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(),
|
|
|
|
decompressed_data[kSnapshotContext].raw_size);
|
|
|
|
i::Snapshot::set_context_raw_data(
|
|
|
|
reinterpret_cast<const i::byte*>(
|
|
|
|
decompressed_data[kSnapshotContext].data));
|
2011-06-06 20:47:30 +00:00
|
|
|
|
|
|
|
ASSERT_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(),
|
|
|
|
decompressed_data[kExperimentalLibraries].raw_size);
|
|
|
|
i::Vector<const char> exp_libraries_source(
|
|
|
|
decompressed_data[kExperimentalLibraries].data,
|
|
|
|
decompressed_data[kExperimentalLibraries].raw_size);
|
|
|
|
i::ExperimentalNatives::SetRawScriptsSource(exp_libraries_source);
|
2011-04-29 12:08:33 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
void V8::SetFatalErrorHandler(FatalErrorCallback that) {
|
2014-04-15 10:45:34 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::UncheckedCurrent();
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->set_exception_behavior(that);
|
2009-01-23 17:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-03 05:40:47 +00:00
|
|
|
void V8::SetAllowCodeGenerationFromStringsCallback(
|
|
|
|
AllowCodeGenerationFromStringsCallback callback) {
|
2014-04-15 10:45:34 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::UncheckedCurrent();
|
2011-05-03 05:40:47 +00:00
|
|
|
isolate->set_allow_code_gen_callback(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void V8::SetFlagsFromString(const char* str, int length) {
|
|
|
|
i::FlagList::SetFlagsFromString(str, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-27 10:11:39 +00:00
|
|
|
void V8::SetFlagsFromCommandLine(int* argc, char** argv, bool remove_flags) {
|
|
|
|
i::FlagList::SetFlagsFromCommandLine(argc, argv, remove_flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
RegisteredExtension* RegisteredExtension::first_extension_ = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
RegisteredExtension::RegisteredExtension(Extension* extension)
|
2011-11-15 22:48:55 +00:00
|
|
|
: extension_(extension) { }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
void RegisteredExtension::Register(RegisteredExtension* that) {
|
2011-03-18 20:35:07 +00:00
|
|
|
that->next_ = first_extension_;
|
|
|
|
first_extension_ = that;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-29 09:45:46 +00:00
|
|
|
void RegisteredExtension::UnregisterAll() {
|
|
|
|
RegisteredExtension* re = first_extension_;
|
|
|
|
while (re != NULL) {
|
|
|
|
RegisteredExtension* next = re->next();
|
|
|
|
delete re;
|
|
|
|
re = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void RegisterExtension(Extension* that) {
|
|
|
|
RegisteredExtension* extension = new RegisteredExtension(that);
|
|
|
|
RegisteredExtension::Register(extension);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Extension::Extension(const char* name,
|
|
|
|
const char* source,
|
|
|
|
int dep_count,
|
2011-09-21 13:28:09 +00:00
|
|
|
const char** deps,
|
|
|
|
int source_length)
|
2008-07-03 15:10:15 +00:00
|
|
|
: name_(name),
|
2011-09-21 13:28:09 +00:00
|
|
|
source_length_(source_length >= 0 ?
|
2012-03-08 18:27:39 +00:00
|
|
|
source_length :
|
2012-08-29 15:23:48 +00:00
|
|
|
(source ? static_cast<int>(strlen(source)) : 0)),
|
2011-09-21 13:28:09 +00:00
|
|
|
source_(source, source_length_),
|
2008-07-03 15:10:15 +00:00
|
|
|
dep_count_(dep_count),
|
|
|
|
deps_(deps),
|
2012-09-11 14:16:56 +00:00
|
|
|
auto_enable_(false) {
|
|
|
|
CHECK(source != NULL || source_length_ == 0);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
ResourceConstraints::ResourceConstraints()
|
2014-05-09 08:38:27 +00:00
|
|
|
: max_semi_space_size_(0),
|
2014-01-13 09:42:23 +00:00
|
|
|
max_old_space_size_(0),
|
|
|
|
max_executable_size_(0),
|
|
|
|
stack_limit_(NULL),
|
2014-04-09 12:45:56 +00:00
|
|
|
max_available_threads_(0),
|
|
|
|
code_range_size_(0) { }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-11-19 13:08:37 +00:00
|
|
|
void ResourceConstraints::ConfigureDefaults(uint64_t physical_memory,
|
2014-04-09 12:45:56 +00:00
|
|
|
uint64_t virtual_memory_limit,
|
2013-11-19 13:08:37 +00:00
|
|
|
uint32_t number_of_processors) {
|
2013-11-13 14:05:06 +00:00
|
|
|
#if V8_OS_ANDROID
|
|
|
|
// Android has higher physical memory requirements before raising the maximum
|
|
|
|
// heap size limits since it has no swap space.
|
|
|
|
const uint64_t low_limit = 512ul * i::MB;
|
|
|
|
const uint64_t medium_limit = 1ul * i::GB;
|
|
|
|
const uint64_t high_limit = 2ul * i::GB;
|
|
|
|
#else
|
|
|
|
const uint64_t low_limit = 512ul * i::MB;
|
|
|
|
const uint64_t medium_limit = 768ul * i::MB;
|
|
|
|
const uint64_t high_limit = 1ul * i::GB;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (physical_memory <= low_limit) {
|
2014-05-09 08:38:27 +00:00
|
|
|
set_max_semi_space_size(i::Heap::kMaxSemiSpaceSizeLowMemoryDevice);
|
2014-04-17 11:27:45 +00:00
|
|
|
set_max_old_space_size(i::Heap::kMaxOldSpaceSizeLowMemoryDevice);
|
|
|
|
set_max_executable_size(i::Heap::kMaxExecutableSizeLowMemoryDevice);
|
2013-11-13 14:05:06 +00:00
|
|
|
} else if (physical_memory <= medium_limit) {
|
2014-05-09 08:38:27 +00:00
|
|
|
set_max_semi_space_size(i::Heap::kMaxSemiSpaceSizeMediumMemoryDevice);
|
2014-04-17 11:27:45 +00:00
|
|
|
set_max_old_space_size(i::Heap::kMaxOldSpaceSizeMediumMemoryDevice);
|
|
|
|
set_max_executable_size(i::Heap::kMaxExecutableSizeMediumMemoryDevice);
|
2013-11-13 14:05:06 +00:00
|
|
|
} else if (physical_memory <= high_limit) {
|
2014-05-09 08:38:27 +00:00
|
|
|
set_max_semi_space_size(i::Heap::kMaxSemiSpaceSizeHighMemoryDevice);
|
2014-04-17 11:27:45 +00:00
|
|
|
set_max_old_space_size(i::Heap::kMaxOldSpaceSizeHighMemoryDevice);
|
|
|
|
set_max_executable_size(i::Heap::kMaxExecutableSizeHighMemoryDevice);
|
2013-11-13 14:05:06 +00:00
|
|
|
} else {
|
2014-05-09 08:38:27 +00:00
|
|
|
set_max_semi_space_size(i::Heap::kMaxSemiSpaceSizeHugeMemoryDevice);
|
2014-04-17 11:27:45 +00:00
|
|
|
set_max_old_space_size(i::Heap::kMaxOldSpaceSizeHugeMemoryDevice);
|
|
|
|
set_max_executable_size(i::Heap::kMaxExecutableSizeHugeMemoryDevice);
|
2013-11-13 14:05:06 +00:00
|
|
|
}
|
2013-11-19 11:52:47 +00:00
|
|
|
|
2013-11-19 13:08:37 +00:00
|
|
|
set_max_available_threads(i::Max(i::Min(number_of_processors, 4u), 1u));
|
2014-04-09 12:45:56 +00:00
|
|
|
|
|
|
|
if (virtual_memory_limit > 0 && i::kIs64BitArch) {
|
|
|
|
// Reserve no more than 1/8 of the memory for the code range, but at most
|
|
|
|
// 512 MB.
|
|
|
|
set_code_range_size(
|
2014-05-09 08:38:27 +00:00
|
|
|
i::Min(512, static_cast<int>((virtual_memory_limit >> 3) / i::MB)));
|
2014-04-09 12:45:56 +00:00
|
|
|
}
|
2013-11-19 13:08:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-06 06:59:32 +00:00
|
|
|
bool SetResourceConstraints(Isolate* v8_isolate,
|
|
|
|
ResourceConstraints* constraints) {
|
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
|
2014-05-09 08:38:27 +00:00
|
|
|
int semi_space_size = constraints->max_semi_space_size();
|
2014-05-05 16:33:23 +00:00
|
|
|
int old_space_size = constraints->max_old_space_size();
|
2010-11-10 08:38:42 +00:00
|
|
|
int max_executable_size = constraints->max_executable_size();
|
2014-04-09 12:45:56 +00:00
|
|
|
int code_range_size = constraints->code_range_size();
|
2014-05-09 08:38:27 +00:00
|
|
|
if (semi_space_size != 0 || old_space_size != 0 ||
|
|
|
|
max_executable_size != 0 || code_range_size != 0) {
|
2011-03-18 20:35:07 +00:00
|
|
|
// After initialization it's too late to change Heap constraints.
|
2013-11-05 14:24:57 +00:00
|
|
|
ASSERT(!isolate->IsInitialized());
|
2014-05-09 08:38:27 +00:00
|
|
|
bool result = isolate->heap()->ConfigureHeap(semi_space_size,
|
2014-05-05 16:33:23 +00:00
|
|
|
old_space_size,
|
2014-04-09 12:45:56 +00:00
|
|
|
max_executable_size,
|
|
|
|
code_range_size);
|
2009-10-01 10:33:05 +00:00
|
|
|
if (!result) return false;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
if (constraints->stack_limit() != NULL) {
|
|
|
|
uintptr_t limit = reinterpret_cast<uintptr_t>(constraints->stack_limit());
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->stack_guard()->SetStackLimit(limit);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2013-11-19 11:52:47 +00:00
|
|
|
|
|
|
|
isolate->set_max_available_threads(constraints->max_available_threads());
|
2008-07-03 15:10:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-25 08:31:46 +00:00
|
|
|
i::Object** V8::GlobalizeReference(i::Isolate* isolate, i::Object** obj) {
|
2011-03-18 20:35:07 +00:00
|
|
|
LOG_API(isolate, "Persistent::New");
|
2013-01-25 08:31:46 +00:00
|
|
|
i::Handle<i::Object> result = isolate->global_handles()->Create(*obj);
|
2013-04-18 12:46:38 +00:00
|
|
|
#ifdef DEBUG
|
2014-04-01 08:57:48 +00:00
|
|
|
(*obj)->ObjectVerify();
|
2013-04-18 12:46:38 +00:00
|
|
|
#endif // DEBUG
|
2009-08-26 10:33:11 +00:00
|
|
|
return result.location();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-09 09:25:23 +00:00
|
|
|
i::Object** V8::CopyPersistent(i::Object** obj) {
|
|
|
|
i::Handle<i::Object> result = i::GlobalHandles::CopyGlobal(obj);
|
|
|
|
#ifdef DEBUG
|
2014-04-01 08:57:48 +00:00
|
|
|
(*obj)->ObjectVerify();
|
2013-09-09 09:25:23 +00:00
|
|
|
#endif // DEBUG
|
|
|
|
return result.location();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-29 08:32:45 +00:00
|
|
|
void V8::MakeWeak(i::Object** object,
|
2013-01-25 08:31:46 +00:00
|
|
|
void* parameters,
|
2013-12-18 08:09:37 +00:00
|
|
|
WeakCallback weak_callback) {
|
|
|
|
i::GlobalHandles::MakeWeak(object, parameters, weak_callback);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-13 07:10:59 +00:00
|
|
|
void* V8::ClearWeak(i::Object** obj) {
|
|
|
|
return i::GlobalHandles::ClearWeakness(obj);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-23 08:19:27 +00:00
|
|
|
void V8::DisposeGlobal(i::Object** obj) {
|
|
|
|
i::GlobalHandles::Destroy(obj);
|
2012-11-05 12:35:51 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2013-08-26 09:41:22 +00:00
|
|
|
void V8::Eternalize(Isolate* v8_isolate, Value* value, int* index) {
|
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
|
|
|
|
i::Object* object = *Utils::OpenHandle(value);
|
|
|
|
isolate->eternal_handles()->Create(isolate, object, index);
|
2013-08-07 08:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-26 09:41:22 +00:00
|
|
|
Local<Value> V8::GetEternal(Isolate* v8_isolate, int index) {
|
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
|
|
|
|
return Utils::ToLocal(isolate->eternal_handles()->Get(index));
|
2013-08-07 08:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// --- H a n d l e s ---
|
|
|
|
|
|
|
|
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope::HandleScope(Isolate* isolate) {
|
|
|
|
Initialize(isolate);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HandleScope::Initialize(Isolate* isolate) {
|
|
|
|
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
2014-01-14 09:37:45 +00:00
|
|
|
// We do not want to check the correct usage of the Locker class all over the
|
|
|
|
// place, so we do it only here: Without a HandleScope, an embedder can do
|
|
|
|
// almost nothing, so it is enough to check in this central place.
|
|
|
|
Utils::ApiCheck(!v8::Locker::IsActive() ||
|
|
|
|
internal_isolate->thread_manager()->IsLockedByCurrentThread(),
|
|
|
|
"HandleScope::HandleScope",
|
|
|
|
"Entering the V8 API without proper locking in place");
|
2014-01-16 08:17:40 +00:00
|
|
|
i::HandleScopeData* current = internal_isolate->handle_scope_data();
|
2013-03-15 12:06:53 +00:00
|
|
|
isolate_ = internal_isolate;
|
2011-03-18 20:35:07 +00:00
|
|
|
prev_next_ = current->next;
|
|
|
|
prev_limit_ = current->limit;
|
|
|
|
current->level++;
|
2009-01-23 17:22:23 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2009-01-23 17:22:23 +00:00
|
|
|
HandleScope::~HandleScope() {
|
2013-12-18 08:09:37 +00:00
|
|
|
i::HandleScope::CloseScope(isolate_, prev_next_, prev_limit_);
|
2010-10-21 14:21:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-09 10:37:15 +00:00
|
|
|
int HandleScope::NumberOfHandles(Isolate* isolate) {
|
|
|
|
return i::HandleScope::NumberOfHandles(
|
|
|
|
reinterpret_cast<i::Isolate*>(isolate));
|
2009-01-23 17:22:23 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2012-12-05 09:13:53 +00:00
|
|
|
i::Object** HandleScope::CreateHandle(i::Isolate* isolate, i::Object* value) {
|
2013-02-25 14:46:09 +00:00
|
|
|
return i::HandleScope::CreateHandle(isolate, value);
|
2012-12-05 09:13:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-27 07:04:02 +00:00
|
|
|
i::Object** HandleScope::CreateHandle(i::HeapObject* heap_object,
|
|
|
|
i::Object* value) {
|
|
|
|
ASSERT(heap_object->IsHeapObject());
|
|
|
|
return i::HandleScope::CreateHandle(heap_object->GetIsolate(), value);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-26 13:46:37 +00:00
|
|
|
EscapableHandleScope::EscapableHandleScope(Isolate* v8_isolate) {
|
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
|
|
|
|
escape_slot_ = CreateHandle(isolate, isolate->heap()->the_hole_value());
|
|
|
|
Initialize(v8_isolate);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
i::Object** EscapableHandleScope::Escape(i::Object** escape_value) {
|
2014-01-16 08:17:40 +00:00
|
|
|
i::Heap* heap = reinterpret_cast<i::Isolate*>(GetIsolate())->heap();
|
|
|
|
Utils::ApiCheck(*escape_slot_ == heap->the_hole_value(),
|
2014-01-13 09:42:23 +00:00
|
|
|
"EscapeableHandleScope::Escape",
|
|
|
|
"Escape value set twice");
|
2013-09-26 13:46:37 +00:00
|
|
|
if (escape_value == NULL) {
|
2014-01-16 08:17:40 +00:00
|
|
|
*escape_slot_ = heap->undefined_value();
|
2013-09-26 13:46:37 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
*escape_slot_ = *escape_value;
|
|
|
|
return escape_slot_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void Context::Enter() {
|
2011-06-07 13:09:01 +00:00
|
|
|
i::Handle<i::Context> env = Utils::OpenHandle(this);
|
|
|
|
i::Isolate* isolate = env->GetIsolate();
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2014-01-14 09:37:45 +00:00
|
|
|
i::HandleScopeImplementer* impl = isolate->handle_scope_implementer();
|
|
|
|
impl->EnterContext(env);
|
|
|
|
impl->SaveContext(isolate->context());
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->set_context(*env);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Context::Exit() {
|
2014-01-14 09:37:45 +00:00
|
|
|
i::Handle<i::Context> env = Utils::OpenHandle(this);
|
|
|
|
i::Isolate* isolate = env->GetIsolate();
|
2013-09-23 11:25:52 +00:00
|
|
|
ENTER_V8(isolate);
|
2014-01-13 09:42:23 +00:00
|
|
|
i::HandleScopeImplementer* impl = isolate->handle_scope_implementer();
|
2014-01-14 09:37:45 +00:00
|
|
|
if (!Utils::ApiCheck(impl->LastEnteredContextWas(env),
|
2014-01-13 09:42:23 +00:00
|
|
|
"v8::Context::Exit()",
|
|
|
|
"Cannot exit non-entered context")) {
|
2008-07-25 07:37:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-01-14 09:37:45 +00:00
|
|
|
impl->LeaveContext();
|
2014-01-13 09:42:23 +00:00
|
|
|
isolate->set_context(impl->RestoreContext());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-13 12:27:03 +00:00
|
|
|
static void* DecodeSmiToAligned(i::Object* value, const char* location) {
|
2014-01-13 09:42:23 +00:00
|
|
|
Utils::ApiCheck(value->IsSmi(), location, "Not a Smi");
|
2012-11-13 12:27:03 +00:00
|
|
|
return reinterpret_cast<void*>(value);
|
2012-11-05 10:25:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-26 10:40:00 +00:00
|
|
|
static i::Smi* EncodeAlignedAsSmi(void* value, const char* location) {
|
|
|
|
i::Smi* smi = reinterpret_cast<i::Smi*>(value);
|
2014-01-13 09:42:23 +00:00
|
|
|
Utils::ApiCheck(smi->IsSmi(), location, "Pointer is not aligned");
|
2012-11-13 12:27:03 +00:00
|
|
|
return smi;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static i::Handle<i::FixedArray> EmbedderDataFor(Context* context,
|
|
|
|
int index,
|
|
|
|
bool can_grow,
|
|
|
|
const char* location) {
|
|
|
|
i::Handle<i::Context> env = Utils::OpenHandle(context);
|
2013-09-23 14:15:21 +00:00
|
|
|
bool ok =
|
2014-01-13 09:42:23 +00:00
|
|
|
Utils::ApiCheck(env->IsNativeContext(),
|
|
|
|
location,
|
|
|
|
"Not a native context") &&
|
|
|
|
Utils::ApiCheck(index >= 0, location, "Negative index");
|
2012-11-13 12:27:03 +00:00
|
|
|
if (!ok) return i::Handle<i::FixedArray>();
|
|
|
|
i::Handle<i::FixedArray> data(env->embedder_data());
|
|
|
|
if (index < data->length()) return data;
|
2014-01-13 09:42:23 +00:00
|
|
|
if (!Utils::ApiCheck(can_grow, location, "Index too large")) {
|
2012-11-13 12:27:03 +00:00
|
|
|
return i::Handle<i::FixedArray>();
|
2012-11-09 10:07:54 +00:00
|
|
|
}
|
2012-11-13 12:27:03 +00:00
|
|
|
int new_size = i::Max(index, data->length() << 1) + 1;
|
2014-04-28 15:33:16 +00:00
|
|
|
data = i::FixedArray::CopySize(data, new_size);
|
2012-11-13 12:27:03 +00:00
|
|
|
env->set_embedder_data(*data);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
v8::Local<v8::Value> Context::SlowGetEmbedderData(int index) {
|
|
|
|
const char* location = "v8::Context::GetEmbedderData()";
|
|
|
|
i::Handle<i::FixedArray> data = EmbedderDataFor(this, index, false, location);
|
|
|
|
if (data.is_null()) return Local<Value>();
|
|
|
|
i::Handle<i::Object> result(data->get(index), data->GetIsolate());
|
2009-05-05 09:38:45 +00:00
|
|
|
return Utils::ToLocal(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-13 12:27:03 +00:00
|
|
|
void Context::SetEmbedderData(int index, v8::Handle<Value> value) {
|
|
|
|
const char* location = "v8::Context::SetEmbedderData()";
|
|
|
|
i::Handle<i::FixedArray> data = EmbedderDataFor(this, index, true, location);
|
|
|
|
if (data.is_null()) return;
|
|
|
|
i::Handle<i::Object> val = Utils::OpenHandle(*value);
|
|
|
|
data->set(index, *val);
|
|
|
|
ASSERT_EQ(*Utils::OpenHandle(*value),
|
|
|
|
*Utils::OpenHandle(*GetEmbedderData(index)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void* Context::SlowGetAlignedPointerFromEmbedderData(int index) {
|
|
|
|
const char* location = "v8::Context::GetAlignedPointerFromEmbedderData()";
|
|
|
|
i::Handle<i::FixedArray> data = EmbedderDataFor(this, index, false, location);
|
|
|
|
if (data.is_null()) return NULL;
|
|
|
|
return DecodeSmiToAligned(data->get(index), location);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Context::SetAlignedPointerInEmbedderData(int index, void* value) {
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// --- N e a n d e r ---
|
|
|
|
|
|
|
|
|
|
|
|
// A constructor cannot easily return an error value, therefore it is necessary
|
|
|
|
// to check for a dead VM with ON_BAILOUT before constructing any Neander
|
|
|
|
// objects. To remind you about this there is no HandleScope in the
|
|
|
|
// NeanderObject constructor. When you add one to the site calling the
|
|
|
|
// constructor you should check that you ensured the VM was not dead first.
|
2014-01-08 14:44:30 +00:00
|
|
|
NeanderObject::NeanderObject(v8::internal::Isolate* isolate, int size) {
|
2011-03-24 18:49:45 +00:00
|
|
|
EnsureInitializedForIsolate(isolate, "v8::Nowhere");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
value_ = isolate->factory()->NewNeanderObject();
|
|
|
|
i::Handle<i::FixedArray> elements = isolate->factory()->NewFixedArray(size);
|
2008-07-03 15:10:15 +00:00
|
|
|
value_->set_elements(*elements);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int NeanderObject::size() {
|
|
|
|
return i::FixedArray::cast(value_->elements())->length();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-08 14:44:30 +00:00
|
|
|
NeanderArray::NeanderArray(v8::internal::Isolate* isolate) : obj_(isolate, 2) {
|
2008-07-03 15:10:15 +00:00
|
|
|
obj_.set(0, i::Smi::FromInt(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int NeanderArray::length() {
|
|
|
|
return i::Smi::cast(obj_.get(0))->value();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
i::Object* NeanderArray::get(int offset) {
|
|
|
|
ASSERT(0 <= offset);
|
|
|
|
ASSERT(offset < length());
|
|
|
|
return obj_.get(offset + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// This method cannot easily return an error value, therefore it is necessary
|
|
|
|
// to check for a dead VM with ON_BAILOUT before calling it. To remind you
|
|
|
|
// about this there is no HandleScope in this method. When you add one to the
|
|
|
|
// site calling this method you should check that you ensured the VM was not
|
|
|
|
// dead first.
|
|
|
|
void NeanderArray::add(i::Handle<i::Object> value) {
|
|
|
|
int length = this->length();
|
|
|
|
int size = obj_.size();
|
|
|
|
if (length == size - 1) {
|
2013-06-04 10:30:05 +00:00
|
|
|
i::Factory* factory = i::Isolate::Current()->factory();
|
|
|
|
i::Handle<i::FixedArray> new_elms = factory->NewFixedArray(2 * size);
|
2008-07-03 15:10:15 +00:00
|
|
|
for (int i = 0; i < length; i++)
|
|
|
|
new_elms->set(i + 1, get(i));
|
|
|
|
obj_.value()->set_elements(*new_elms);
|
|
|
|
}
|
|
|
|
obj_.set(length + 1, *value);
|
|
|
|
obj_.set(0, i::Smi::FromInt(length + 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NeanderArray::set(int index, i::Object* value) {
|
|
|
|
if (index < 0 || index >= this->length()) return;
|
|
|
|
obj_.set(index + 1, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// --- T e m p l a t e ---
|
|
|
|
|
|
|
|
|
|
|
|
static void InitializeTemplate(i::Handle<i::TemplateInfo> that, int type) {
|
|
|
|
that->set_tag(i::Smi::FromInt(type));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-26 11:59:14 +00:00
|
|
|
static void TemplateSet(i::Isolate* isolate,
|
|
|
|
v8::Template* templ,
|
|
|
|
int length,
|
|
|
|
v8::Handle<v8::Data>* data) {
|
|
|
|
i::Handle<i::Object> list(Utils::OpenHandle(templ)->property_list(), isolate);
|
|
|
|
if (list->IsUndefined()) {
|
2014-01-08 14:44:30 +00:00
|
|
|
list = NeanderArray(isolate).value();
|
2013-08-26 11:59:14 +00:00
|
|
|
Utils::OpenHandle(templ)->set_property_list(*list);
|
|
|
|
}
|
|
|
|
NeanderArray array(list);
|
2014-01-03 14:31:17 +00:00
|
|
|
array.add(isolate->factory()->NewNumberFromInt(length));
|
2013-08-26 11:59:14 +00:00
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
i::Handle<i::Object> value = data[i].IsEmpty() ?
|
|
|
|
i::Handle<i::Object>(isolate->factory()->undefined_value()) :
|
|
|
|
Utils::OpenHandle(*data[i]);
|
|
|
|
array.add(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Template::Set(v8::Handle<String> name,
|
|
|
|
v8::Handle<Data> value,
|
2008-07-03 15:10:15 +00:00
|
|
|
v8::PropertyAttribute attribute) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2013-08-26 11:59:14 +00:00
|
|
|
const int kSize = 3;
|
2014-01-03 14:31:17 +00:00
|
|
|
v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
|
2013-08-26 11:59:14 +00:00
|
|
|
v8::Handle<v8::Data> data[kSize] = {
|
2014-01-13 09:42:23 +00:00
|
|
|
name,
|
|
|
|
value,
|
|
|
|
v8::Integer::New(v8_isolate, attribute)};
|
2013-08-26 11:59:14 +00:00
|
|
|
TemplateSet(isolate, this, kSize, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Template::SetAccessorProperty(
|
|
|
|
v8::Local<v8::String> name,
|
|
|
|
v8::Local<FunctionTemplate> getter,
|
|
|
|
v8::Local<FunctionTemplate> setter,
|
|
|
|
v8::PropertyAttribute attribute,
|
|
|
|
v8::AccessControl access_control) {
|
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
ASSERT(!name.IsEmpty());
|
|
|
|
ASSERT(!getter.IsEmpty() || !setter.IsEmpty());
|
|
|
|
i::HandleScope scope(isolate);
|
|
|
|
const int kSize = 5;
|
2014-01-03 14:31:17 +00:00
|
|
|
v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
|
2013-08-26 11:59:14 +00:00
|
|
|
v8::Handle<v8::Data> data[kSize] = {
|
2014-01-13 09:42:23 +00:00
|
|
|
name,
|
|
|
|
getter,
|
|
|
|
setter,
|
|
|
|
v8::Integer::New(v8_isolate, attribute),
|
|
|
|
v8::Integer::New(v8_isolate, access_control)};
|
2013-08-26 11:59:14 +00:00
|
|
|
TemplateSet(isolate, this, kSize, data);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// --- F u n c t i o n T e m p l a t e ---
|
|
|
|
static void InitializeFunctionTemplate(
|
2014-01-13 09:42:23 +00:00
|
|
|
i::Handle<i::FunctionTemplateInfo> info) {
|
2008-07-03 15:10:15 +00:00
|
|
|
info->set_tag(i::Smi::FromInt(Consts::FUNCTION_TEMPLATE));
|
|
|
|
info->set_flag(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<ObjectTemplate> FunctionTemplate::PrototypeTemplate() {
|
2014-01-08 06:53:31 +00:00
|
|
|
i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ENTER_V8(i_isolate);
|
2013-02-25 14:46:09 +00:00
|
|
|
i::Handle<i::Object> result(Utils::OpenHandle(this)->prototype_template(),
|
2014-01-08 06:53:31 +00:00
|
|
|
i_isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
if (result->IsUndefined()) {
|
2014-01-08 06:53:31 +00:00
|
|
|
v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(i_isolate);
|
|
|
|
result = Utils::OpenHandle(*ObjectTemplate::New(isolate));
|
2008-07-03 15:10:15 +00:00
|
|
|
Utils::OpenHandle(this)->set_prototype_template(*result);
|
|
|
|
}
|
2013-06-13 09:27:09 +00:00
|
|
|
return ToApiHandle<ObjectTemplate>(result);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FunctionTemplate::Inherit(v8::Handle<FunctionTemplate> value) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ENTER_V8(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
Utils::OpenHandle(this)->set_parent_template(*Utils::OpenHandle(*value));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-09 07:52:52 +00:00
|
|
|
static Local<FunctionTemplate> FunctionTemplateNew(
|
|
|
|
i::Isolate* isolate,
|
2013-08-27 11:47:52 +00:00
|
|
|
FunctionCallback callback,
|
2013-05-21 06:36:24 +00:00
|
|
|
v8::Handle<Value> data,
|
|
|
|
v8::Handle<Signature> signature,
|
2013-09-09 07:52:52 +00:00
|
|
|
int length,
|
|
|
|
bool do_not_cache) {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Struct> struct_obj =
|
2011-03-23 09:02:15 +00:00
|
|
|
isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::FunctionTemplateInfo> obj =
|
|
|
|
i::Handle<i::FunctionTemplateInfo>::cast(struct_obj);
|
|
|
|
InitializeFunctionTemplate(obj);
|
2013-09-09 07:52:52 +00:00
|
|
|
obj->set_do_not_cache(do_not_cache);
|
|
|
|
int next_serial_number = 0;
|
|
|
|
if (!do_not_cache) {
|
|
|
|
next_serial_number = isolate->next_serial_number() + 1;
|
|
|
|
isolate->set_next_serial_number(next_serial_number);
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
obj->set_serial_number(i::Smi::FromInt(next_serial_number));
|
2013-05-24 07:59:33 +00:00
|
|
|
if (callback != 0) {
|
2013-09-26 08:21:48 +00:00
|
|
|
if (data.IsEmpty()) {
|
|
|
|
data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
|
|
|
|
}
|
2013-08-27 11:47:52 +00:00
|
|
|
Utils::ToLocal(obj)->SetCallHandler(callback, data);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2012-12-19 10:28:36 +00:00
|
|
|
obj->set_length(length);
|
2008-07-03 15:10:15 +00:00
|
|
|
obj->set_undetectable(false);
|
|
|
|
obj->set_needs_access_check(false);
|
|
|
|
if (!signature.IsEmpty())
|
|
|
|
obj->set_signature(*Utils::OpenHandle(*signature));
|
|
|
|
return Utils::ToLocal(obj);
|
|
|
|
}
|
|
|
|
|
2013-09-09 07:52:52 +00:00
|
|
|
Local<FunctionTemplate> FunctionTemplate::New(
|
2013-11-26 09:45:17 +00:00
|
|
|
Isolate* isolate,
|
2013-09-09 07:52:52 +00:00
|
|
|
FunctionCallback callback,
|
|
|
|
v8::Handle<Value> data,
|
|
|
|
v8::Handle<Signature> signature,
|
|
|
|
int length) {
|
2013-11-26 09:45:17 +00:00
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
EnsureInitializedForIsolate(i_isolate, "v8::FunctionTemplate::New()");
|
|
|
|
LOG_API(i_isolate, "FunctionTemplate::New");
|
|
|
|
ENTER_V8(i_isolate);
|
2013-09-09 07:52:52 +00:00
|
|
|
return FunctionTemplateNew(
|
2013-11-26 09:45:17 +00:00
|
|
|
i_isolate, callback, data, signature, length, false);
|
2013-09-09 07:52:52 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-11-26 09:45:17 +00:00
|
|
|
Local<Signature> Signature::New(Isolate* isolate,
|
|
|
|
Handle<FunctionTemplate> receiver, int argc,
|
|
|
|
Handle<FunctionTemplate> argv[]) {
|
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
EnsureInitializedForIsolate(i_isolate, "v8::Signature::New()");
|
|
|
|
LOG_API(i_isolate, "Signature::New");
|
|
|
|
ENTER_V8(i_isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Struct> struct_obj =
|
2013-11-26 09:45:17 +00:00
|
|
|
i_isolate->factory()->NewStruct(i::SIGNATURE_INFO_TYPE);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::SignatureInfo> obj =
|
|
|
|
i::Handle<i::SignatureInfo>::cast(struct_obj);
|
|
|
|
if (!receiver.IsEmpty()) obj->set_receiver(*Utils::OpenHandle(*receiver));
|
|
|
|
if (argc > 0) {
|
2013-11-26 09:45:17 +00:00
|
|
|
i::Handle<i::FixedArray> args = i_isolate->factory()->NewFixedArray(argc);
|
2008-07-03 15:10:15 +00:00
|
|
|
for (int i = 0; i < argc; i++) {
|
|
|
|
if (!argv[i].IsEmpty())
|
|
|
|
args->set(i, *Utils::OpenHandle(*argv[i]));
|
|
|
|
}
|
|
|
|
obj->set_args(*args);
|
|
|
|
}
|
|
|
|
return Utils::ToLocal(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-26 09:45:17 +00:00
|
|
|
Local<AccessorSignature> AccessorSignature::New(
|
2014-01-13 09:42:23 +00:00
|
|
|
Isolate* isolate,
|
|
|
|
Handle<FunctionTemplate> receiver) {
|
2013-11-26 09:45:17 +00:00
|
|
|
return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-07 11:42:58 +00:00
|
|
|
template<typename Operation>
|
|
|
|
static Local<Operation> NewDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
const i::DeclaredAccessorDescriptorData& data,
|
2013-06-13 09:27:09 +00:00
|
|
|
Data* previous_descriptor) {
|
2013-03-07 11:42:58 +00:00
|
|
|
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
i::Handle<i::DeclaredAccessorDescriptor> previous =
|
|
|
|
i::Handle<i::DeclaredAccessorDescriptor>();
|
|
|
|
if (previous_descriptor != NULL) {
|
|
|
|
previous = Utils::OpenHandle(
|
2014-01-13 09:42:23 +00:00
|
|
|
static_cast<DeclaredAccessorDescriptor*>(previous_descriptor));
|
2013-03-07 11:42:58 +00:00
|
|
|
}
|
|
|
|
i::Handle<i::DeclaredAccessorDescriptor> descriptor =
|
|
|
|
i::DeclaredAccessorDescriptor::Create(internal_isolate, data, previous);
|
2013-06-13 09:27:09 +00:00
|
|
|
return Utils::Convert<i::DeclaredAccessorDescriptor, Operation>(descriptor);
|
2013-03-07 11:42:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<RawOperationDescriptor>
|
2014-01-13 09:42:23 +00:00
|
|
|
ObjectOperationDescriptor::NewInternalFieldDereference(
|
2013-03-07 11:42:58 +00:00
|
|
|
Isolate* isolate,
|
|
|
|
int internal_field) {
|
|
|
|
i::DeclaredAccessorDescriptorData data;
|
|
|
|
data.type = i::kDescriptorObjectDereference;
|
|
|
|
data.object_dereference_descriptor.internal_field = internal_field;
|
|
|
|
return NewDescriptor<RawOperationDescriptor>(isolate, data, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<RawOperationDescriptor> RawOperationDescriptor::NewRawShift(
|
|
|
|
Isolate* isolate,
|
|
|
|
int16_t byte_offset) {
|
|
|
|
i::DeclaredAccessorDescriptorData data;
|
|
|
|
data.type = i::kDescriptorPointerShift;
|
|
|
|
data.pointer_shift_descriptor.byte_offset = byte_offset;
|
|
|
|
return NewDescriptor<RawOperationDescriptor>(isolate, data, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<DeclaredAccessorDescriptor> RawOperationDescriptor::NewHandleDereference(
|
|
|
|
Isolate* isolate) {
|
|
|
|
i::DeclaredAccessorDescriptorData data;
|
|
|
|
data.type = i::kDescriptorReturnObject;
|
|
|
|
return NewDescriptor<DeclaredAccessorDescriptor>(isolate, data, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<RawOperationDescriptor> RawOperationDescriptor::NewRawDereference(
|
|
|
|
Isolate* isolate) {
|
|
|
|
i::DeclaredAccessorDescriptorData data;
|
|
|
|
data.type = i::kDescriptorPointerDereference;
|
|
|
|
return NewDescriptor<RawOperationDescriptor>(isolate, data, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<DeclaredAccessorDescriptor> RawOperationDescriptor::NewPointerCompare(
|
|
|
|
Isolate* isolate,
|
|
|
|
void* compare_value) {
|
|
|
|
i::DeclaredAccessorDescriptorData data;
|
|
|
|
data.type = i::kDescriptorPointerCompare;
|
|
|
|
data.pointer_compare_descriptor.compare_value = compare_value;
|
|
|
|
return NewDescriptor<DeclaredAccessorDescriptor>(isolate, data, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<DeclaredAccessorDescriptor> RawOperationDescriptor::NewPrimitiveValue(
|
|
|
|
Isolate* isolate,
|
|
|
|
DeclaredAccessorDescriptorDataType data_type,
|
|
|
|
uint8_t bool_offset) {
|
|
|
|
i::DeclaredAccessorDescriptorData data;
|
|
|
|
data.type = i::kDescriptorPrimitiveValue;
|
|
|
|
data.primitive_value_descriptor.data_type = data_type;
|
|
|
|
data.primitive_value_descriptor.bool_offset = bool_offset;
|
|
|
|
return NewDescriptor<DeclaredAccessorDescriptor>(isolate, data, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
static Local<DeclaredAccessorDescriptor> NewBitmaskCompare(
|
|
|
|
Isolate* isolate,
|
|
|
|
T bitmask,
|
|
|
|
T compare_value,
|
|
|
|
RawOperationDescriptor* operation) {
|
|
|
|
i::DeclaredAccessorDescriptorData data;
|
|
|
|
data.type = i::kDescriptorBitmaskCompare;
|
|
|
|
data.bitmask_compare_descriptor.bitmask = bitmask;
|
|
|
|
data.bitmask_compare_descriptor.compare_value = compare_value;
|
|
|
|
data.bitmask_compare_descriptor.size = sizeof(T);
|
|
|
|
return NewDescriptor<DeclaredAccessorDescriptor>(isolate, data, operation);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<DeclaredAccessorDescriptor> RawOperationDescriptor::NewBitmaskCompare8(
|
|
|
|
Isolate* isolate,
|
|
|
|
uint8_t bitmask,
|
|
|
|
uint8_t compare_value) {
|
|
|
|
return NewBitmaskCompare(isolate, bitmask, compare_value, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<DeclaredAccessorDescriptor> RawOperationDescriptor::NewBitmaskCompare16(
|
|
|
|
Isolate* isolate,
|
|
|
|
uint16_t bitmask,
|
|
|
|
uint16_t compare_value) {
|
|
|
|
return NewBitmaskCompare(isolate, bitmask, compare_value, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<DeclaredAccessorDescriptor> RawOperationDescriptor::NewBitmaskCompare32(
|
|
|
|
Isolate* isolate,
|
|
|
|
uint32_t bitmask,
|
|
|
|
uint32_t compare_value) {
|
|
|
|
return NewBitmaskCompare(isolate, bitmask, compare_value, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Local<TypeSwitch> TypeSwitch::New(Handle<FunctionTemplate> type) {
|
|
|
|
Handle<FunctionTemplate> types[1] = { type };
|
|
|
|
return TypeSwitch::New(1, types);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<TypeSwitch> TypeSwitch::New(int argc, Handle<FunctionTemplate> types[]) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
EnsureInitializedForIsolate(isolate, "v8::TypeSwitch::New()");
|
|
|
|
LOG_API(isolate, "TypeSwitch::New");
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Handle<i::FixedArray> vector = isolate->factory()->NewFixedArray(argc);
|
2008-07-03 15:10:15 +00:00
|
|
|
for (int i = 0; i < argc; i++)
|
|
|
|
vector->set(i, *Utils::OpenHandle(*types[i]));
|
|
|
|
i::Handle<i::Struct> struct_obj =
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->factory()->NewStruct(i::TYPE_SWITCH_INFO_TYPE);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::TypeSwitchInfo> obj =
|
|
|
|
i::Handle<i::TypeSwitchInfo>::cast(struct_obj);
|
|
|
|
obj->set_types(*vector);
|
|
|
|
return Utils::ToLocal(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TypeSwitch::match(v8::Handle<Value> value) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
LOG_API(isolate, "TypeSwitch::match");
|
2011-05-30 14:33:23 +00:00
|
|
|
USE(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(*value);
|
|
|
|
i::Handle<i::TypeSwitchInfo> info = Utils::OpenHandle(this);
|
|
|
|
i::FixedArray* types = i::FixedArray::cast(info->types());
|
|
|
|
for (int i = 0; i < types->length(); i++) {
|
2013-11-19 13:38:15 +00:00
|
|
|
if (i::FunctionTemplateInfo::cast(types->get(i))->IsTemplateFor(*obj))
|
2008-07-03 15:10:15 +00:00
|
|
|
return i + 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-13 09:42:23 +00:00
|
|
|
#define SET_FIELD_WRAPPED(obj, setter, cdata) do { \
|
|
|
|
i::Handle<i::Object> foreign = FromCData(obj->GetIsolate(), cdata); \
|
|
|
|
(obj)->setter(*foreign); \
|
2010-09-23 08:27:51 +00:00
|
|
|
} while (false)
|
|
|
|
|
|
|
|
|
2013-08-27 11:47:52 +00:00
|
|
|
void FunctionTemplate::SetCallHandler(FunctionCallback callback,
|
|
|
|
v8::Handle<Value> data) {
|
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Struct> struct_obj =
|
2011-03-23 09:02:15 +00:00
|
|
|
isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::CallHandlerInfo> obj =
|
|
|
|
i::Handle<i::CallHandlerInfo>::cast(struct_obj);
|
2010-09-23 08:27:51 +00:00
|
|
|
SET_FIELD_WRAPPED(obj, set_callback, callback);
|
2013-09-26 08:21:48 +00:00
|
|
|
if (data.IsEmpty()) {
|
|
|
|
data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
obj->set_data(*Utils::OpenHandle(*data));
|
2013-08-27 11:47:52 +00:00
|
|
|
Utils::OpenHandle(this)->set_call_code(*obj);
|
2013-06-20 12:53:19 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-03-07 11:42:58 +00:00
|
|
|
static i::Handle<i::AccessorInfo> SetAccessorInfoProperties(
|
|
|
|
i::Handle<i::AccessorInfo> obj,
|
|
|
|
v8::Handle<String> name,
|
|
|
|
v8::AccessControl settings,
|
|
|
|
v8::PropertyAttribute attributes,
|
|
|
|
v8::Handle<AccessorSignature> signature) {
|
2008-07-03 15:10:15 +00:00
|
|
|
obj->set_name(*Utils::OpenHandle(*name));
|
|
|
|
if (settings & ALL_CAN_READ) obj->set_all_can_read(true);
|
|
|
|
if (settings & ALL_CAN_WRITE) obj->set_all_can_write(true);
|
|
|
|
obj->set_property_attributes(static_cast<PropertyAttributes>(attributes));
|
2012-06-08 07:45:11 +00:00
|
|
|
if (!signature.IsEmpty()) {
|
|
|
|
obj->set_expected_receiver_type(*Utils::OpenHandle(*signature));
|
|
|
|
}
|
2010-05-25 12:14:49 +00:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-21 06:36:24 +00:00
|
|
|
template<typename Getter, typename Setter>
|
2013-03-07 11:42:58 +00:00
|
|
|
static i::Handle<i::AccessorInfo> MakeAccessorInfo(
|
2014-01-13 09:42:23 +00:00
|
|
|
v8::Handle<String> name,
|
|
|
|
Getter getter,
|
|
|
|
Setter setter,
|
|
|
|
v8::Handle<Value> data,
|
|
|
|
v8::AccessControl settings,
|
|
|
|
v8::PropertyAttribute attributes,
|
|
|
|
v8::Handle<AccessorSignature> signature) {
|
2013-03-07 11:42:58 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(*name)->GetIsolate();
|
|
|
|
i::Handle<i::ExecutableAccessorInfo> obj =
|
|
|
|
isolate->factory()->NewExecutableAccessorInfo();
|
|
|
|
SET_FIELD_WRAPPED(obj, set_getter, getter);
|
|
|
|
SET_FIELD_WRAPPED(obj, set_setter, setter);
|
2013-09-26 08:21:48 +00:00
|
|
|
if (data.IsEmpty()) {
|
|
|
|
data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
|
|
|
|
}
|
2013-03-07 11:42:58 +00:00
|
|
|
obj->set_data(*Utils::OpenHandle(*data));
|
|
|
|
return SetAccessorInfoProperties(obj, name, settings, attributes, signature);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-03-07 11:42:58 +00:00
|
|
|
|
|
|
|
static i::Handle<i::AccessorInfo> MakeAccessorInfo(
|
2014-01-13 09:42:23 +00:00
|
|
|
v8::Handle<String> name,
|
|
|
|
v8::Handle<v8::DeclaredAccessorDescriptor> descriptor,
|
|
|
|
void* setter_ignored,
|
|
|
|
void* data_ignored,
|
|
|
|
v8::AccessControl settings,
|
|
|
|
v8::PropertyAttribute attributes,
|
|
|
|
v8::Handle<AccessorSignature> signature) {
|
2013-03-07 11:42:58 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(*name)->GetIsolate();
|
|
|
|
if (descriptor.IsEmpty()) return i::Handle<i::DeclaredAccessorInfo>();
|
|
|
|
i::Handle<i::DeclaredAccessorInfo> obj =
|
|
|
|
isolate->factory()->NewDeclaredAccessorInfo();
|
|
|
|
obj->set_descriptor(*Utils::OpenHandle(*descriptor));
|
|
|
|
return SetAccessorInfoProperties(obj, name, settings, attributes, signature);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<ObjectTemplate> FunctionTemplate::InstanceTemplate() {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2014-01-13 09:42:23 +00:00
|
|
|
if (!Utils::ApiCheck(this != NULL,
|
|
|
|
"v8::FunctionTemplate::InstanceTemplate()",
|
|
|
|
"Reading from empty handle")) {
|
2008-07-03 15:10:15 +00:00
|
|
|
return Local<ObjectTemplate>();
|
2014-01-13 09:42:23 +00:00
|
|
|
}
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2013-06-13 09:27:09 +00:00
|
|
|
i::Handle<i::FunctionTemplateInfo> handle = Utils::OpenHandle(this);
|
|
|
|
if (handle->instance_template()->IsUndefined()) {
|
2008-07-03 15:10:15 +00:00
|
|
|
Local<ObjectTemplate> templ =
|
2013-11-26 09:45:17 +00:00
|
|
|
ObjectTemplate::New(isolate, ToApiHandle<FunctionTemplate>(handle));
|
2013-06-13 09:27:09 +00:00
|
|
|
handle->set_instance_template(*Utils::OpenHandle(*templ));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2013-06-13 09:27:09 +00:00
|
|
|
i::Handle<i::ObjectTemplateInfo> result(
|
|
|
|
i::ObjectTemplateInfo::cast(handle->instance_template()));
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::ToLocal(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-19 10:28:36 +00:00
|
|
|
void FunctionTemplate::SetLength(int length) {
|
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
Utils::OpenHandle(this)->set_length(length);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-16 07:07:30 +00:00
|
|
|
void FunctionTemplate::SetClassName(Handle<String> name) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ENTER_V8(isolate);
|
2008-07-16 07:07:30 +00:00
|
|
|
Utils::OpenHandle(this)->set_class_name(*Utils::OpenHandle(*name));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FunctionTemplate::SetHiddenPrototype(bool value) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ENTER_V8(isolate);
|
2008-07-16 07:07:30 +00:00
|
|
|
Utils::OpenHandle(this)->set_hidden_prototype(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-25 15:01:45 +00:00
|
|
|
void FunctionTemplate::ReadOnlyPrototype() {
|
2011-06-22 12:39:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ENTER_V8(isolate);
|
2011-07-25 15:01:45 +00:00
|
|
|
Utils::OpenHandle(this)->set_read_only_prototype(true);
|
2011-06-22 12:39:45 +00:00
|
|
|
}
|
|
|
|
|
2013-08-26 17:40:03 +00:00
|
|
|
|
|
|
|
void FunctionTemplate::RemovePrototype() {
|
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
Utils::OpenHandle(this)->set_remove_prototype(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// --- O b j e c t T e m p l a t e ---
|
|
|
|
|
|
|
|
|
2013-11-26 09:45:17 +00:00
|
|
|
Local<ObjectTemplate> ObjectTemplate::New(Isolate* isolate) {
|
|
|
|
return New(reinterpret_cast<i::Isolate*>(isolate), Local<FunctionTemplate>());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Local<ObjectTemplate> ObjectTemplate::New() {
|
2013-11-26 09:45:17 +00:00
|
|
|
return New(i::Isolate::Current(), Local<FunctionTemplate>());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<ObjectTemplate> ObjectTemplate::New(
|
2014-01-13 09:42:23 +00:00
|
|
|
i::Isolate* isolate,
|
|
|
|
v8::Handle<FunctionTemplate> constructor) {
|
2011-03-18 20:35:07 +00:00
|
|
|
EnsureInitializedForIsolate(isolate, "v8::ObjectTemplate::New()");
|
|
|
|
LOG_API(isolate, "ObjectTemplate::New");
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Struct> struct_obj =
|
2011-03-24 18:49:45 +00:00
|
|
|
isolate->factory()->NewStruct(i::OBJECT_TEMPLATE_INFO_TYPE);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::ObjectTemplateInfo> obj =
|
|
|
|
i::Handle<i::ObjectTemplateInfo>::cast(struct_obj);
|
|
|
|
InitializeTemplate(obj, Consts::OBJECT_TEMPLATE);
|
|
|
|
if (!constructor.IsEmpty())
|
|
|
|
obj->set_constructor(*Utils::OpenHandle(*constructor));
|
2008-07-16 07:07:30 +00:00
|
|
|
obj->set_internal_field_count(i::Smi::FromInt(0));
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::ToLocal(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Ensure that the object template has a constructor. If no
|
|
|
|
// constructor is available we create one.
|
2013-09-04 07:45:36 +00:00
|
|
|
static i::Handle<i::FunctionTemplateInfo> EnsureConstructor(
|
2013-12-18 10:31:42 +00:00
|
|
|
i::Isolate* isolate,
|
2013-09-04 07:45:36 +00:00
|
|
|
ObjectTemplate* object_template) {
|
|
|
|
i::Object* obj = Utils::OpenHandle(object_template)->constructor();
|
|
|
|
if (!obj ->IsUndefined()) {
|
|
|
|
i::FunctionTemplateInfo* info = i::FunctionTemplateInfo::cast(obj);
|
2013-12-18 10:31:42 +00:00
|
|
|
return i::Handle<i::FunctionTemplateInfo>(info, isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2013-12-18 10:31:42 +00:00
|
|
|
Local<FunctionTemplate> templ =
|
|
|
|
FunctionTemplate::New(reinterpret_cast<Isolate*>(isolate));
|
2013-09-04 07:45:36 +00:00
|
|
|
i::Handle<i::FunctionTemplateInfo> constructor = Utils::OpenHandle(*templ);
|
|
|
|
constructor->set_instance_template(*Utils::OpenHandle(object_template));
|
|
|
|
Utils::OpenHandle(object_template)->set_constructor(*constructor);
|
|
|
|
return constructor;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-04 07:45:36 +00:00
|
|
|
static inline void AddPropertyToTemplate(
|
|
|
|
i::Handle<i::TemplateInfo> info,
|
2013-03-07 11:42:58 +00:00
|
|
|
i::Handle<i::AccessorInfo> obj) {
|
2014-01-08 14:44:30 +00:00
|
|
|
i::Isolate* isolate = info->GetIsolate();
|
|
|
|
i::Handle<i::Object> list(info->property_accessors(), isolate);
|
2013-03-07 11:42:58 +00:00
|
|
|
if (list->IsUndefined()) {
|
2014-01-08 14:44:30 +00:00
|
|
|
list = NeanderArray(isolate).value();
|
2013-09-04 07:45:36 +00:00
|
|
|
info->set_property_accessors(*list);
|
2013-03-07 11:42:58 +00:00
|
|
|
}
|
|
|
|
NeanderArray array(list);
|
|
|
|
array.add(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-04 07:45:36 +00:00
|
|
|
static inline i::Handle<i::TemplateInfo> GetTemplateInfo(
|
2013-12-18 10:31:42 +00:00
|
|
|
i::Isolate* isolate,
|
2013-09-04 07:45:36 +00:00
|
|
|
Template* template_obj) {
|
|
|
|
return Utils::OpenHandle(template_obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO(dcarney): remove this with ObjectTemplate::SetAccessor
|
|
|
|
static inline i::Handle<i::TemplateInfo> GetTemplateInfo(
|
2013-12-18 10:31:42 +00:00
|
|
|
i::Isolate* isolate,
|
2013-09-04 07:45:36 +00:00
|
|
|
ObjectTemplate* object_template) {
|
2013-12-18 10:31:42 +00:00
|
|
|
EnsureConstructor(isolate, object_template);
|
2013-09-04 07:45:36 +00:00
|
|
|
return Utils::OpenHandle(object_template);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename Setter, typename Getter, typename Data, typename Template>
|
|
|
|
static bool TemplateSetAccessor(
|
|
|
|
Template* template_obj,
|
|
|
|
v8::Local<String> name,
|
2013-05-21 06:36:24 +00:00
|
|
|
Getter getter,
|
|
|
|
Setter setter,
|
|
|
|
Data data,
|
|
|
|
AccessControl settings,
|
|
|
|
PropertyAttribute attribute,
|
2013-09-04 07:45:36 +00:00
|
|
|
v8::Local<AccessorSignature> signature) {
|
|
|
|
i::Isolate* isolate = Utils::OpenHandle(template_obj)->GetIsolate();
|
2013-05-21 06:36:24 +00:00
|
|
|
ENTER_V8(isolate);
|
|
|
|
i::HandleScope scope(isolate);
|
|
|
|
i::Handle<i::AccessorInfo> obj = MakeAccessorInfo(
|
|
|
|
name, getter, setter, data, settings, attribute, signature);
|
|
|
|
if (obj.is_null()) return false;
|
2013-12-18 10:31:42 +00:00
|
|
|
i::Handle<i::TemplateInfo> info = GetTemplateInfo(isolate, template_obj);
|
2013-09-04 07:45:36 +00:00
|
|
|
AddPropertyToTemplate(info, obj);
|
2013-05-21 06:36:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-04 07:45:36 +00:00
|
|
|
bool Template::SetDeclaredAccessor(
|
|
|
|
Local<String> name,
|
|
|
|
Local<DeclaredAccessorDescriptor> descriptor,
|
|
|
|
PropertyAttribute attribute,
|
|
|
|
Local<AccessorSignature> signature,
|
|
|
|
AccessControl settings) {
|
|
|
|
void* null = NULL;
|
|
|
|
return TemplateSetAccessor(
|
|
|
|
this, name, descriptor, null, null, settings, attribute, signature);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Template::SetNativeDataProperty(v8::Local<String> name,
|
|
|
|
AccessorGetterCallback getter,
|
|
|
|
AccessorSetterCallback setter,
|
|
|
|
v8::Handle<Value> data,
|
|
|
|
PropertyAttribute attribute,
|
|
|
|
v8::Local<AccessorSignature> signature,
|
|
|
|
AccessControl settings) {
|
|
|
|
TemplateSetAccessor(
|
|
|
|
this, name, getter, setter, data, settings, attribute, signature);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-21 06:36:24 +00:00
|
|
|
void ObjectTemplate::SetAccessor(v8::Handle<String> name,
|
|
|
|
AccessorGetterCallback getter,
|
|
|
|
AccessorSetterCallback setter,
|
|
|
|
v8::Handle<Value> data,
|
2013-03-07 11:42:58 +00:00
|
|
|
AccessControl settings,
|
|
|
|
PropertyAttribute attribute,
|
2013-05-21 06:36:24 +00:00
|
|
|
v8::Handle<AccessorSignature> signature) {
|
2013-09-04 07:45:36 +00:00
|
|
|
TemplateSetAccessor(
|
2013-05-21 06:36:24 +00:00
|
|
|
this, name, getter, setter, data, settings, attribute, signature);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-27 11:47:52 +00:00
|
|
|
void ObjectTemplate::SetNamedPropertyHandler(
|
|
|
|
NamedPropertyGetterCallback getter,
|
|
|
|
NamedPropertySetterCallback setter,
|
|
|
|
NamedPropertyQueryCallback query,
|
|
|
|
NamedPropertyDeleterCallback remover,
|
|
|
|
NamedPropertyEnumeratorCallback enumerator,
|
2013-05-21 06:36:24 +00:00
|
|
|
Handle<Value> data) {
|
2013-08-27 11:47:52 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
|
|
|
i::HandleScope scope(isolate);
|
2013-12-18 10:31:42 +00:00
|
|
|
EnsureConstructor(isolate, this);
|
2013-05-21 06:36:24 +00:00
|
|
|
i::FunctionTemplateInfo* constructor = i::FunctionTemplateInfo::cast(
|
2013-08-27 11:47:52 +00:00
|
|
|
Utils::OpenHandle(this)->constructor());
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::FunctionTemplateInfo> cons(constructor);
|
2013-08-27 11:47:52 +00:00
|
|
|
i::Handle<i::Struct> struct_obj =
|
|
|
|
isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE);
|
|
|
|
i::Handle<i::InterceptorInfo> obj =
|
|
|
|
i::Handle<i::InterceptorInfo>::cast(struct_obj);
|
2013-05-21 06:36:24 +00:00
|
|
|
|
2013-08-27 11:47:52 +00:00
|
|
|
if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter);
|
|
|
|
if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter);
|
|
|
|
if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query);
|
|
|
|
if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover);
|
|
|
|
if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator);
|
2013-05-21 06:36:24 +00:00
|
|
|
|
2013-09-26 08:21:48 +00:00
|
|
|
if (data.IsEmpty()) {
|
|
|
|
data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
|
|
|
|
}
|
2013-08-27 11:47:52 +00:00
|
|
|
obj->set_data(*Utils::OpenHandle(*data));
|
|
|
|
cons->set_named_property_handler(*obj);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ObjectTemplate::MarkAsUndetectable() {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2013-12-18 10:31:42 +00:00
|
|
|
EnsureConstructor(isolate, this);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::FunctionTemplateInfo* constructor =
|
|
|
|
i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor());
|
|
|
|
i::Handle<i::FunctionTemplateInfo> cons(constructor);
|
|
|
|
cons->set_undetectable(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ObjectTemplate::SetAccessCheckCallbacks(
|
2014-01-13 09:42:23 +00:00
|
|
|
NamedSecurityCallback named_callback,
|
|
|
|
IndexedSecurityCallback indexed_callback,
|
|
|
|
Handle<Value> data,
|
|
|
|
bool turned_on_by_default) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2013-12-18 10:31:42 +00:00
|
|
|
EnsureConstructor(isolate, this);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
i::Handle<i::Struct> struct_info =
|
2011-03-23 09:02:15 +00:00
|
|
|
isolate->factory()->NewStruct(i::ACCESS_CHECK_INFO_TYPE);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::AccessCheckInfo> info =
|
|
|
|
i::Handle<i::AccessCheckInfo>::cast(struct_info);
|
2010-09-23 08:27:51 +00:00
|
|
|
|
|
|
|
SET_FIELD_WRAPPED(info, set_named_callback, named_callback);
|
|
|
|
SET_FIELD_WRAPPED(info, set_indexed_callback, indexed_callback);
|
|
|
|
|
2013-09-26 08:21:48 +00:00
|
|
|
if (data.IsEmpty()) {
|
|
|
|
data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
info->set_data(*Utils::OpenHandle(*data));
|
|
|
|
|
|
|
|
i::FunctionTemplateInfo* constructor =
|
|
|
|
i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor());
|
|
|
|
i::Handle<i::FunctionTemplateInfo> cons(constructor);
|
|
|
|
cons->set_access_check_info(*info);
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
cons->set_needs_access_check(turned_on_by_default);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-27 11:47:52 +00:00
|
|
|
void ObjectTemplate::SetIndexedPropertyHandler(
|
2014-01-13 09:42:23 +00:00
|
|
|
IndexedPropertyGetterCallback getter,
|
|
|
|
IndexedPropertySetterCallback setter,
|
|
|
|
IndexedPropertyQueryCallback query,
|
|
|
|
IndexedPropertyDeleterCallback remover,
|
|
|
|
IndexedPropertyEnumeratorCallback enumerator,
|
|
|
|
Handle<Value> data) {
|
2013-08-27 11:47:52 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2013-12-18 10:31:42 +00:00
|
|
|
EnsureConstructor(isolate, this);
|
2013-05-21 06:36:24 +00:00
|
|
|
i::FunctionTemplateInfo* constructor = i::FunctionTemplateInfo::cast(
|
2013-08-27 11:47:52 +00:00
|
|
|
Utils::OpenHandle(this)->constructor());
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::FunctionTemplateInfo> cons(constructor);
|
2013-08-27 11:47:52 +00:00
|
|
|
i::Handle<i::Struct> struct_obj =
|
|
|
|
isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE);
|
|
|
|
i::Handle<i::InterceptorInfo> obj =
|
|
|
|
i::Handle<i::InterceptorInfo>::cast(struct_obj);
|
2013-05-21 06:36:24 +00:00
|
|
|
|
2013-08-27 11:47:52 +00:00
|
|
|
if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter);
|
|
|
|
if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter);
|
|
|
|
if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query);
|
|
|
|
if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover);
|
|
|
|
if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator);
|
2013-05-21 06:36:24 +00:00
|
|
|
|
2013-09-26 08:21:48 +00:00
|
|
|
if (data.IsEmpty()) {
|
|
|
|
data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
|
|
|
|
}
|
2013-08-27 11:47:52 +00:00
|
|
|
obj->set_data(*Utils::OpenHandle(*data));
|
|
|
|
cons->set_indexed_property_handler(*obj);
|
2013-05-21 06:36:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-27 11:47:52 +00:00
|
|
|
void ObjectTemplate::SetCallAsFunctionHandler(FunctionCallback callback,
|
|
|
|
Handle<Value> data) {
|
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2013-12-18 10:31:42 +00:00
|
|
|
EnsureConstructor(isolate, this);
|
2013-05-21 06:36:24 +00:00
|
|
|
i::FunctionTemplateInfo* constructor = i::FunctionTemplateInfo::cast(
|
2013-08-27 11:47:52 +00:00
|
|
|
Utils::OpenHandle(this)->constructor());
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::FunctionTemplateInfo> cons(constructor);
|
2013-08-27 11:47:52 +00:00
|
|
|
i::Handle<i::Struct> struct_obj =
|
|
|
|
isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE);
|
|
|
|
i::Handle<i::CallHandlerInfo> obj =
|
|
|
|
i::Handle<i::CallHandlerInfo>::cast(struct_obj);
|
|
|
|
SET_FIELD_WRAPPED(obj, set_callback, callback);
|
2013-09-26 08:21:48 +00:00
|
|
|
if (data.IsEmpty()) {
|
|
|
|
data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
|
|
|
|
}
|
2013-08-27 11:47:52 +00:00
|
|
|
obj->set_data(*Utils::OpenHandle(*data));
|
|
|
|
cons->set_instance_call_handler(*obj);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-16 07:07:30 +00:00
|
|
|
int ObjectTemplate::InternalFieldCount() {
|
|
|
|
return i::Smi::cast(Utils::OpenHandle(this)->internal_field_count())->value();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-16 07:07:30 +00:00
|
|
|
void ObjectTemplate::SetInternalFieldCount(int value) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2014-01-13 09:42:23 +00:00
|
|
|
if (!Utils::ApiCheck(i::Smi::IsValid(value),
|
|
|
|
"v8::ObjectTemplate::SetInternalFieldCount()",
|
|
|
|
"Invalid internal field count")) {
|
2008-07-03 15:10:15 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2008-09-09 07:57:43 +00:00
|
|
|
if (value > 0) {
|
|
|
|
// The internal field count is set by the constructor function's
|
|
|
|
// construct code, so we ensure that there is a constructor
|
|
|
|
// function to do the setting.
|
2013-12-18 10:31:42 +00:00
|
|
|
EnsureConstructor(isolate, this);
|
2008-09-09 07:57:43 +00:00
|
|
|
}
|
2008-07-16 07:07:30 +00:00
|
|
|
Utils::OpenHandle(this)->set_internal_field_count(i::Smi::FromInt(value));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-14 10:20:33 +00:00
|
|
|
// --- S c r i p t s ---
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2014-03-14 10:20:33 +00:00
|
|
|
// Internally, UnboundScript is a SharedFunctionInfo, and Script is a
|
|
|
|
// JSFunction.
|
|
|
|
|
2014-03-19 13:24:13 +00:00
|
|
|
ScriptCompiler::CachedData::CachedData(const uint8_t* data_, int length_,
|
|
|
|
BufferPolicy buffer_policy_)
|
|
|
|
: data(data_), length(length_), buffer_policy(buffer_policy_) {}
|
|
|
|
|
|
|
|
|
|
|
|
ScriptCompiler::CachedData::~CachedData() {
|
|
|
|
if (buffer_policy == BufferOwned) {
|
|
|
|
delete[] data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-14 10:20:33 +00:00
|
|
|
Local<Script> UnboundScript::BindToCurrentContext() {
|
|
|
|
i::Handle<i::HeapObject> obj =
|
|
|
|
i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this));
|
|
|
|
i::Handle<i::SharedFunctionInfo>
|
|
|
|
function_info(i::SharedFunctionInfo::cast(*obj), obj->GetIsolate());
|
|
|
|
i::Handle<i::JSFunction> function =
|
|
|
|
obj->GetIsolate()->factory()->NewFunctionFromSharedFunctionInfo(
|
|
|
|
function_info, obj->GetIsolate()->global_context());
|
|
|
|
return ToApiHandle<Script>(function);
|
2009-08-17 11:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-14 10:20:33 +00:00
|
|
|
int UnboundScript::GetId() {
|
|
|
|
i::Handle<i::HeapObject> obj =
|
|
|
|
i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this));
|
|
|
|
i::Isolate* isolate = obj->GetIsolate();
|
|
|
|
ON_BAILOUT(isolate, "v8::UnboundScript::GetId()", return -1);
|
|
|
|
LOG_API(isolate, "v8::UnboundScript::GetId");
|
|
|
|
{
|
|
|
|
i::HandleScope scope(isolate);
|
|
|
|
i::Handle<i::SharedFunctionInfo> function_info(
|
|
|
|
i::SharedFunctionInfo::cast(*obj));
|
|
|
|
i::Handle<i::Script> script(i::Script::cast(function_info->script()));
|
|
|
|
return script->id()->value();
|
|
|
|
}
|
2009-08-17 11:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-14 10:20:33 +00:00
|
|
|
int UnboundScript::GetLineNumber(int code_pos) {
|
2014-05-21 07:32:32 +00:00
|
|
|
i::Handle<i::SharedFunctionInfo> obj =
|
|
|
|
i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this));
|
2014-03-14 10:20:33 +00:00
|
|
|
i::Isolate* isolate = obj->GetIsolate();
|
|
|
|
ON_BAILOUT(isolate, "v8::UnboundScript::GetLineNumber()", return -1);
|
|
|
|
LOG_API(isolate, "UnboundScript::GetLineNumber");
|
2014-05-21 07:32:32 +00:00
|
|
|
if (obj->script()->IsScript()) {
|
|
|
|
i::Handle<i::Script> script(i::Script::cast(obj->script()));
|
2014-04-16 13:28:11 +00:00
|
|
|
return i::Script::GetLineNumber(script, code_pos);
|
2014-03-14 10:20:33 +00:00
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-14 10:20:33 +00:00
|
|
|
Handle<Value> UnboundScript::GetScriptName() {
|
2014-05-21 07:32:32 +00:00
|
|
|
i::Handle<i::SharedFunctionInfo> obj =
|
|
|
|
i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this));
|
2014-03-14 10:20:33 +00:00
|
|
|
i::Isolate* isolate = obj->GetIsolate();
|
|
|
|
ON_BAILOUT(isolate, "v8::UnboundScript::GetName()",
|
|
|
|
return Handle<String>());
|
|
|
|
LOG_API(isolate, "UnboundScript::GetName");
|
2014-05-21 07:32:32 +00:00
|
|
|
if (obj->script()->IsScript()) {
|
|
|
|
i::Object* name = i::Script::cast(obj->script())->name();
|
2014-03-14 10:20:33 +00:00
|
|
|
return Utils::ToLocal(i::Handle<i::Object>(name, isolate));
|
|
|
|
} else {
|
|
|
|
return Handle<String>();
|
|
|
|
}
|
2008-08-14 13:41:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Local<Value> Script::Run() {
|
2014-03-14 10:20:33 +00:00
|
|
|
// If execution is terminating, Compile(..)->Run() requires this
|
|
|
|
// check.
|
2013-10-01 09:56:04 +00:00
|
|
|
if (this == NULL) return Local<Value>();
|
|
|
|
i::Handle<i::HeapObject> obj =
|
|
|
|
i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this));
|
|
|
|
i::Isolate* isolate = obj->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
ON_BAILOUT(isolate, "v8::Script::Run()", return Local<Value>());
|
|
|
|
LOG_API(isolate, "Script::Run");
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2012-11-22 13:04:11 +00:00
|
|
|
i::Logger::TimerEventScope timer_scope(
|
2012-11-26 08:56:59 +00:00
|
|
|
isolate, i::Logger::TimerEventScope::v8_execute);
|
2014-04-11 10:41:09 +00:00
|
|
|
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> result;
|
|
|
|
has_pending_exception = !i::Execution::Call(
|
|
|
|
isolate, fun, receiver, 0, NULL).ToHandle(&result);
|
|
|
|
EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Value>());
|
|
|
|
return Utils::ToLocal(scope.CloseAndEscape(result));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-14 10:20:33 +00:00
|
|
|
Local<UnboundScript> Script::GetUnboundScript() {
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
return ToApiHandle<UnboundScript>(
|
|
|
|
i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared()));
|
2013-06-25 14:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-14 10:20:33 +00:00
|
|
|
Local<UnboundScript> ScriptCompiler::CompileUnbound(
|
|
|
|
Isolate* v8_isolate,
|
2014-03-19 13:24:13 +00:00
|
|
|
Source* source,
|
2014-03-14 10:20:33 +00:00
|
|
|
CompileOptions options) {
|
2014-04-11 11:44:49 +00:00
|
|
|
i::ScriptData* script_data_impl = NULL;
|
2014-03-19 13:24:13 +00:00
|
|
|
i::CachedDataMode cached_data_mode = i::NO_CACHED_DATA;
|
2014-04-14 07:35:46 +00:00
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
|
|
|
|
ON_BAILOUT(isolate, "v8::ScriptCompiler::CompileUnbound()",
|
|
|
|
return Local<UnboundScript>());
|
2014-03-19 13:24:13 +00:00
|
|
|
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
|
2014-04-14 07:35:46 +00:00
|
|
|
// 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>());
|
2014-03-19 13:24:13 +00:00
|
|
|
}
|
|
|
|
} else if (source->cached_data) {
|
2014-04-14 07:35:46 +00:00
|
|
|
cached_data_mode = i::CONSUME_CACHED_DATA;
|
2014-04-11 11:44:49 +00:00
|
|
|
// ScriptData takes care of aligning, in case the data is not aligned
|
|
|
|
// correctly.
|
|
|
|
script_data_impl = i::ScriptData::New(
|
2014-03-19 13:24:13 +00:00
|
|
|
reinterpret_cast<const char*>(source->cached_data->data),
|
2014-04-11 11:44:49 +00:00
|
|
|
source->cached_data->length);
|
2014-04-14 07:35:46 +00:00
|
|
|
// 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();
|
2014-03-19 13:24:13 +00:00
|
|
|
delete script_data_impl;
|
2014-04-14 07:35:46 +00:00
|
|
|
has_pending_exception = true;
|
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<UnboundScript>());
|
2014-03-19 13:24:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
i::Handle<i::String> str = Utils::OpenHandle(*(source->source_string));
|
2014-03-14 10:20:33 +00:00
|
|
|
LOG_API(isolate, "ScriptCompiler::CompileUnbound");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
i::SharedFunctionInfo* raw_result = NULL;
|
|
|
|
{ i::HandleScope scope(isolate);
|
|
|
|
i::Handle<i::Object> name_obj;
|
|
|
|
int line_offset = 0;
|
|
|
|
int column_offset = 0;
|
|
|
|
bool is_shared_cross_origin = false;
|
2014-03-19 13:24:13 +00:00
|
|
|
if (!source->resource_name.IsEmpty()) {
|
|
|
|
name_obj = Utils::OpenHandle(*(source->resource_name));
|
2014-03-14 10:20:33 +00:00
|
|
|
}
|
2014-03-19 13:24:13 +00:00
|
|
|
if (!source->resource_line_offset.IsEmpty()) {
|
|
|
|
line_offset = static_cast<int>(source->resource_line_offset->Value());
|
2014-03-14 10:20:33 +00:00
|
|
|
}
|
2014-03-19 13:24:13 +00:00
|
|
|
if (!source->resource_column_offset.IsEmpty()) {
|
2014-03-14 10:20:33 +00:00
|
|
|
column_offset =
|
2014-03-19 13:24:13 +00:00
|
|
|
static_cast<int>(source->resource_column_offset->Value());
|
2014-03-14 10:20:33 +00:00
|
|
|
}
|
2014-03-19 13:24:13 +00:00
|
|
|
if (!source->resource_is_shared_cross_origin.IsEmpty()) {
|
2014-03-14 10:20:33 +00:00
|
|
|
v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
|
|
|
|
is_shared_cross_origin =
|
2014-03-19 13:24:13 +00:00
|
|
|
source->resource_is_shared_cross_origin == v8::True(v8_isolate);
|
2014-03-14 10:20:33 +00:00
|
|
|
}
|
|
|
|
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,
|
2014-03-19 13:24:13 +00:00
|
|
|
&script_data_impl,
|
|
|
|
cached_data_mode,
|
2014-03-14 10:20:33 +00:00
|
|
|
i::NOT_NATIVES_CODE);
|
|
|
|
has_pending_exception = result.is_null();
|
2014-05-26 11:04:32 +00:00
|
|
|
if (has_pending_exception && cached_data_mode == i::CONSUME_CACHED_DATA) {
|
|
|
|
// 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;
|
|
|
|
}
|
2014-03-14 10:20:33 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<UnboundScript>());
|
|
|
|
raw_result = *result;
|
2014-03-19 13:24:13 +00:00
|
|
|
if ((options & kProduceDataToCache) && script_data_impl != NULL) {
|
|
|
|
// script_data_impl 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;
|
|
|
|
}
|
|
|
|
delete script_data_impl;
|
2014-03-13 09:14:16 +00:00
|
|
|
}
|
2014-03-14 10:20:33 +00:00
|
|
|
i::Handle<i::SharedFunctionInfo> result(raw_result, isolate);
|
|
|
|
return ToApiHandle<UnboundScript>(result);
|
2013-04-12 12:48:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-14 10:20:33 +00:00
|
|
|
Local<Script> ScriptCompiler::Compile(
|
|
|
|
Isolate* v8_isolate,
|
2014-03-19 13:24:13 +00:00
|
|
|
Source* source,
|
2014-03-14 10:20:33 +00:00
|
|
|
CompileOptions options) {
|
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
|
2014-05-22 15:27:57 +00:00
|
|
|
ON_BAILOUT(isolate, "v8::ScriptCompiler::Compile()", return Local<Script>());
|
2014-03-14 10:20:33 +00:00
|
|
|
LOG_API(isolate, "ScriptCompiler::CompiletBound()");
|
|
|
|
ENTER_V8(isolate);
|
2014-05-22 15:27:57 +00:00
|
|
|
Local<UnboundScript> generic = CompileUnbound(v8_isolate, source, options);
|
2014-03-14 10:20:33 +00:00
|
|
|
if (generic.IsEmpty()) return Local<Script>();
|
|
|
|
return generic->BindToCurrentContext();
|
2014-03-13 08:54:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-14 10:20:33 +00:00
|
|
|
Local<Script> Script::Compile(v8::Handle<String> source,
|
2014-04-11 11:44:49 +00:00
|
|
|
v8::ScriptOrigin* origin) {
|
2014-03-14 10:20:33 +00:00
|
|
|
i::Handle<i::String> str = Utils::OpenHandle(*source);
|
|
|
|
if (origin) {
|
2014-04-11 11:44:49 +00:00
|
|
|
ScriptCompiler::Source script_source(source, *origin);
|
2014-03-14 10:20:33 +00:00
|
|
|
return ScriptCompiler::Compile(
|
|
|
|
reinterpret_cast<v8::Isolate*>(str->GetIsolate()),
|
2014-03-19 13:24:13 +00:00
|
|
|
&script_source);
|
2014-03-13 09:14:16 +00:00
|
|
|
}
|
2014-04-11 11:44:49 +00:00
|
|
|
ScriptCompiler::Source script_source(source);
|
2014-03-14 10:20:33 +00:00
|
|
|
return ScriptCompiler::Compile(
|
|
|
|
reinterpret_cast<v8::Isolate*>(str->GetIsolate()),
|
2014-03-19 13:24:13 +00:00
|
|
|
&script_source);
|
2014-03-14 10:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<Script> Script::Compile(v8::Handle<String> source,
|
|
|
|
v8::Handle<String> file_name) {
|
|
|
|
ScriptOrigin origin(file_name);
|
|
|
|
return Compile(source, &origin);
|
2013-04-12 12:48:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// --- E x c e p t i o n s ---
|
|
|
|
|
|
|
|
|
|
|
|
v8::TryCatch::TryCatch()
|
2011-06-07 15:01:52 +00:00
|
|
|
: isolate_(i::Isolate::Current()),
|
2014-05-20 10:13:46 +00:00
|
|
|
next_(isolate_->try_catch_handler()),
|
2008-09-10 14:54:15 +00:00
|
|
|
is_verbose_(false),
|
2009-09-23 07:55:48 +00:00
|
|
|
can_continue_(true),
|
2008-11-12 23:21:54 +00:00
|
|
|
capture_message_(true),
|
2013-04-22 15:01:45 +00:00
|
|
|
rethrow_(false),
|
|
|
|
has_terminated_(false) {
|
2013-07-01 10:54:39 +00:00
|
|
|
Reset();
|
2014-05-20 10:13:46 +00:00
|
|
|
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
|
|
|
|
// 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_)));
|
2011-06-07 15:01:52 +00:00
|
|
|
isolate_->RegisterTryCatchHandler(this);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
v8::TryCatch::~TryCatch() {
|
2011-06-07 15:01:52 +00:00
|
|
|
ASSERT(isolate_ == i::Isolate::Current());
|
2009-11-03 08:53:34 +00:00
|
|
|
if (rethrow_) {
|
2013-09-27 07:04:02 +00:00
|
|
|
v8::Isolate* isolate = reinterpret_cast<Isolate*>(isolate_);
|
|
|
|
v8::HandleScope scope(isolate);
|
|
|
|
v8::Local<v8::Value> exc = v8::Local<v8::Value>::New(isolate, Exception());
|
2013-07-01 10:54:39 +00:00
|
|
|
if (HasCaught() && capture_message_) {
|
|
|
|
// If an exception was caught and rethrow_ is indicated, the saved
|
|
|
|
// message, script, and location need to be restored to Isolate TLS
|
|
|
|
// for reuse. capture_message_ needs to be disabled so that DoThrow()
|
|
|
|
// does not create a new message.
|
|
|
|
isolate_->thread_local_top()->rethrowing_message_ = true;
|
|
|
|
isolate_->RestorePendingMessageFromTryCatch(this);
|
|
|
|
}
|
2011-06-07 15:01:52 +00:00
|
|
|
isolate_->UnregisterTryCatchHandler(this);
|
2014-05-20 10:13:46 +00:00
|
|
|
v8::internal::SimulatorStack::UnregisterCTryCatch();
|
2013-09-26 07:37:59 +00:00
|
|
|
reinterpret_cast<Isolate*>(isolate_)->ThrowException(exc);
|
2013-07-01 10:54:39 +00:00
|
|
|
ASSERT(!isolate_->thread_local_top()->rethrowing_message_);
|
2009-11-03 08:53:34 +00:00
|
|
|
} else {
|
2011-06-07 15:01:52 +00:00
|
|
|
isolate_->UnregisterTryCatchHandler(this);
|
2014-05-20 10:13:46 +00:00
|
|
|
v8::internal::SimulatorStack::UnregisterCTryCatch();
|
2009-11-03 08:53:34 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-23 08:25:23 +00:00
|
|
|
bool v8::TryCatch::HasCaught() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
return !reinterpret_cast<i::Object*>(exception_)->IsTheHole();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-19 15:14:11 +00:00
|
|
|
bool v8::TryCatch::CanContinue() const {
|
|
|
|
return can_continue_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-22 15:01:45 +00:00
|
|
|
bool v8::TryCatch::HasTerminated() const {
|
|
|
|
return has_terminated_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-03 08:53:34 +00:00
|
|
|
v8::Handle<v8::Value> v8::TryCatch::ReThrow() {
|
|
|
|
if (!HasCaught()) return v8::Local<v8::Value>();
|
|
|
|
rethrow_ = true;
|
2013-09-26 08:21:48 +00:00
|
|
|
return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate_));
|
2009-11-03 08:53:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-23 08:25:23 +00:00
|
|
|
v8::Local<Value> v8::TryCatch::Exception() const {
|
2011-06-07 15:01:52 +00:00
|
|
|
ASSERT(isolate_ == i::Isolate::Current());
|
2008-07-03 15:10:15 +00:00
|
|
|
if (HasCaught()) {
|
|
|
|
// Check for out of memory exception.
|
|
|
|
i::Object* exception = reinterpret_cast<i::Object*>(exception_);
|
2011-06-07 15:01:52 +00:00
|
|
|
return v8::Utils::ToLocal(i::Handle<i::Object>(exception, isolate_));
|
2008-07-03 15:10:15 +00:00
|
|
|
} else {
|
|
|
|
return v8::Local<Value>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-17 13:34:41 +00:00
|
|
|
v8::Local<Value> v8::TryCatch::StackTrace() const {
|
2011-06-07 15:01:52 +00:00
|
|
|
ASSERT(isolate_ == i::Isolate::Current());
|
2009-08-17 13:34:41 +00:00
|
|
|
if (HasCaught()) {
|
|
|
|
i::Object* raw_obj = reinterpret_cast<i::Object*>(exception_);
|
|
|
|
if (!raw_obj->IsJSObject()) return v8::Local<Value>();
|
2011-06-07 15:01:52 +00:00
|
|
|
i::HandleScope scope(isolate_);
|
|
|
|
i::Handle<i::JSObject> obj(i::JSObject::cast(raw_obj), isolate_);
|
2013-02-28 17:03:34 +00:00
|
|
|
i::Handle<i::String> name = isolate_->factory()->stack_string();
|
2013-09-17 11:34:20 +00:00
|
|
|
if (!i::JSReceiver::HasProperty(obj, name)) return v8::Local<Value>();
|
2014-04-11 12:47:34 +00:00
|
|
|
i::Handle<i::Object> value;
|
|
|
|
if (!i::Object::GetProperty(obj, name).ToHandle(&value)) {
|
|
|
|
return v8::Local<Value>();
|
|
|
|
}
|
2011-07-04 13:29:56 +00:00
|
|
|
return v8::Utils::ToLocal(scope.CloseAndEscape(value));
|
2009-08-17 13:34:41 +00:00
|
|
|
} else {
|
|
|
|
return v8::Local<Value>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-23 08:25:23 +00:00
|
|
|
v8::Local<v8::Message> v8::TryCatch::Message() const {
|
2011-06-07 15:01:52 +00:00
|
|
|
ASSERT(isolate_ == i::Isolate::Current());
|
2013-07-01 10:54:39 +00:00
|
|
|
i::Object* message = reinterpret_cast<i::Object*>(message_obj_);
|
|
|
|
ASSERT(message->IsJSMessageObject() || message->IsTheHole());
|
|
|
|
if (HasCaught() && !message->IsTheHole()) {
|
2011-06-07 15:01:52 +00:00
|
|
|
return v8::Utils::MessageToLocal(i::Handle<i::Object>(message, isolate_));
|
2008-09-09 18:55:41 +00:00
|
|
|
} else {
|
|
|
|
return v8::Local<v8::Message>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void v8::TryCatch::Reset() {
|
2011-06-07 15:01:52 +00:00
|
|
|
ASSERT(isolate_ == i::Isolate::Current());
|
2013-07-01 10:54:39 +00:00
|
|
|
i::Object* the_hole = isolate_->heap()->the_hole_value();
|
|
|
|
exception_ = the_hole;
|
|
|
|
message_obj_ = the_hole;
|
|
|
|
message_script_ = the_hole;
|
|
|
|
message_start_pos_ = 0;
|
|
|
|
message_end_pos_ = 0;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void v8::TryCatch::SetVerbose(bool value) {
|
|
|
|
is_verbose_ = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-10 14:54:15 +00:00
|
|
|
void v8::TryCatch::SetCaptureMessage(bool value) {
|
|
|
|
capture_message_ = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// --- M e s s a g e ---
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
Local<String> Message::Get() const {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
ON_BAILOUT(isolate, "v8::Message::Get()", return Local<String>());
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2013-12-02 18:12:01 +00:00
|
|
|
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
2013-02-25 14:46:09 +00:00
|
|
|
i::Handle<i::String> raw_result = i::MessageHandler::GetMessage(isolate, obj);
|
2008-07-03 15:10:15 +00:00
|
|
|
Local<String> result = Utils::ToLocal(raw_result);
|
2013-12-02 18:12:01 +00:00
|
|
|
return scope.Escape(result);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
v8::Handle<Value> Message::GetScriptResourceName() const {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ENTER_V8(isolate);
|
2013-12-02 18:12:01 +00:00
|
|
|
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
|
2011-02-02 13:31:52 +00:00
|
|
|
i::Handle<i::JSMessageObject> message =
|
|
|
|
i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
|
2008-07-03 15:10:15 +00:00
|
|
|
// Return this.script.name.
|
|
|
|
i::Handle<i::JSValue> script =
|
2013-02-25 14:46:09 +00:00
|
|
|
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);
|
2013-12-02 18:12:01 +00:00
|
|
|
return scope.Escape(Utils::ToLocal(resource_name));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-12 13:17:27 +00:00
|
|
|
v8::Handle<v8::StackTrace> Message::GetStackTrace() const {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ENTER_V8(isolate);
|
2013-12-02 18:12:01 +00:00
|
|
|
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
|
2011-02-02 13:31:52 +00:00
|
|
|
i::Handle<i::JSMessageObject> message =
|
|
|
|
i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
|
2013-02-25 14:46:09 +00:00
|
|
|
i::Handle<i::Object> stackFramesObj(message->stack_frames(), isolate);
|
2010-07-12 13:17:27 +00:00
|
|
|
if (!stackFramesObj->IsJSArray()) return v8::Handle<v8::StackTrace>();
|
|
|
|
i::Handle<i::JSArray> stackTrace =
|
|
|
|
i::Handle<i::JSArray>::cast(stackFramesObj);
|
2013-12-02 18:12:01 +00:00
|
|
|
return scope.Escape(Utils::StackTraceToLocal(stackTrace));
|
2010-07-12 13:17:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-11 10:41:09 +00:00
|
|
|
MUST_USE_RESULT static i::MaybeHandle<i::Object> CallV8HeapFunction(
|
|
|
|
const char* name,
|
|
|
|
i::Handle<i::Object> recv,
|
|
|
|
int argc,
|
|
|
|
i::Handle<i::Object> argv[]) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2014-04-09 12:21:47 +00:00
|
|
|
i::Handle<i::Object> object_fun =
|
2014-04-11 12:47:34 +00:00
|
|
|
i::Object::GetProperty(
|
2014-04-16 13:28:11 +00:00
|
|
|
isolate, isolate->js_builtins_object(), name).ToHandleChecked();
|
2014-04-09 12:21:47 +00:00
|
|
|
i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(object_fun);
|
2014-04-11 10:41:09 +00:00
|
|
|
return i::Execution::Call(isolate, fun, recv, argc, argv);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-11 10:41:09 +00:00
|
|
|
MUST_USE_RESULT static i::MaybeHandle<i::Object> CallV8HeapFunction(
|
|
|
|
const char* name,
|
|
|
|
i::Handle<i::Object> data) {
|
2011-10-06 09:31:38 +00:00
|
|
|
i::Handle<i::Object> argv[] = { data };
|
2008-07-03 15:10:15 +00:00
|
|
|
return CallV8HeapFunction(name,
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate::Current()->js_builtins_object(),
|
2011-10-06 09:31:38 +00:00
|
|
|
ARRAY_SIZE(argv),
|
2014-04-11 10:41:09 +00:00
|
|
|
argv);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
int Message::GetLineNumber() const {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
ON_BAILOUT(isolate, "v8::Message::GetLineNumber()", return kNoLineNumberInfo);
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2011-02-02 13:31:52 +00:00
|
|
|
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
i::Handle<i::Object> result;
|
|
|
|
has_pending_exception = !CallV8HeapFunction(
|
|
|
|
"GetLineNumber", Utils::OpenHandle(this)).ToHandle(&result);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, 0);
|
2008-07-03 15:10:15 +00:00
|
|
|
return static_cast<int>(result->Number());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
int Message::GetStartPosition() const {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2011-02-02 13:31:52 +00:00
|
|
|
i::Handle<i::JSMessageObject> message =
|
|
|
|
i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
|
|
|
|
return message->start_position();
|
2008-09-09 18:55:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
int Message::GetEndPosition() const {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2011-02-02 13:31:52 +00:00
|
|
|
i::Handle<i::JSMessageObject> message =
|
|
|
|
i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
|
|
|
|
return message->end_position();
|
2008-09-09 18:55:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
int Message::GetStartColumn() const {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2008-09-09 18:55:41 +00:00
|
|
|
i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
i::Handle<i::Object> start_col_obj;
|
|
|
|
has_pending_exception = !CallV8HeapFunction(
|
|
|
|
"GetPositionInLine", data_obj).ToHandle(&start_col_obj);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, 0);
|
2008-09-09 18:55:41 +00:00
|
|
|
return static_cast<int>(start_col_obj->Number());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
int Message::GetEndColumn() const {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2008-09-09 18:55:41 +00:00
|
|
|
i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
i::Handle<i::Object> start_col_obj;
|
|
|
|
has_pending_exception = !CallV8HeapFunction(
|
|
|
|
"GetPositionInLine", data_obj).ToHandle(&start_col_obj);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, 0);
|
2011-02-02 13:31:52 +00:00
|
|
|
i::Handle<i::JSMessageObject> message =
|
|
|
|
i::Handle<i::JSMessageObject>::cast(data_obj);
|
|
|
|
int start = message->start_position();
|
|
|
|
int end = message->end_position();
|
2008-09-09 18:55:41 +00:00
|
|
|
return static_cast<int>(start_col_obj->Number()) + (end - start);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-30 17:05:50 +00:00
|
|
|
bool Message::IsSharedCrossOrigin() const {
|
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
i::HandleScope scope(isolate);
|
|
|
|
i::Handle<i::JSMessageObject> message =
|
|
|
|
i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
|
|
|
|
i::Handle<i::JSValue> script =
|
|
|
|
i::Handle<i::JSValue>::cast(i::Handle<i::Object>(message->script(),
|
|
|
|
isolate));
|
|
|
|
return i::Script::cast(script->value())->is_shared_cross_origin();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
Local<String> Message::GetSourceLine() const {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
ON_BAILOUT(isolate, "v8::Message::GetSourceLine()", return Local<String>());
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2013-12-02 18:12:01 +00:00
|
|
|
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
i::Handle<i::Object> result;
|
|
|
|
has_pending_exception = !CallV8HeapFunction(
|
|
|
|
"GetSourceLine", Utils::OpenHandle(this)).ToHandle(&result);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::String>());
|
2008-09-09 18:55:41 +00:00
|
|
|
if (result->IsString()) {
|
2013-12-02 18:12:01 +00:00
|
|
|
return scope.Escape(Utils::ToLocal(i::Handle<i::String>::cast(result)));
|
2008-09-09 18:55:41 +00:00
|
|
|
} else {
|
|
|
|
return Local<String>();
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-26 09:45:17 +00:00
|
|
|
void Message::PrintCurrentStackTrace(Isolate* isolate, FILE* out) {
|
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
ENTER_V8(i_isolate);
|
|
|
|
i_isolate->PrintCurrentStackTrace(out);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-06 07:32:44 +00:00
|
|
|
// --- S t a c k T r a c e ---
|
|
|
|
|
|
|
|
Local<StackFrame> StackTrace::GetFrame(uint32_t index) const {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ENTER_V8(isolate);
|
2013-12-02 18:12:01 +00:00
|
|
|
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
|
2010-05-06 07:32:44 +00:00
|
|
|
i::Handle<i::JSArray> self = Utils::OpenHandle(this);
|
2014-03-20 12:22:13 +00:00
|
|
|
i::Handle<i::Object> obj =
|
2014-04-11 12:47:34 +00:00
|
|
|
i::Object::GetElement(isolate, self, index).ToHandleChecked();
|
2014-03-20 12:22:13 +00:00
|
|
|
i::Handle<i::JSObject> jsobj = i::Handle<i::JSObject>::cast(obj);
|
|
|
|
return scope.Escape(Utils::StackFrameToLocal(jsobj));
|
2010-05-06 07:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int StackTrace::GetFrameCount() const {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ENTER_V8(isolate);
|
2010-05-06 07:32:44 +00:00
|
|
|
return i::Smi::cast(Utils::OpenHandle(this)->length())->value();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<Array> StackTrace::AsArray() {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ENTER_V8(isolate);
|
2010-05-06 07:32:44 +00:00
|
|
|
return Utils::ToLocal(Utils::OpenHandle(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-26 09:45:17 +00:00
|
|
|
Local<StackTrace> StackTrace::CurrentStackTrace(
|
|
|
|
Isolate* isolate,
|
|
|
|
int frame_limit,
|
2010-05-06 07:32:44 +00:00
|
|
|
StackTraceOptions options) {
|
2013-11-26 09:45:17 +00:00
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
ENTER_V8(i_isolate);
|
2014-05-19 13:45:45 +00:00
|
|
|
// TODO(dcarney): remove when ScriptDebugServer is fixed.
|
|
|
|
options = static_cast<StackTraceOptions>(
|
|
|
|
static_cast<int>(options) | kExposeFramesAcrossSecurityOrigins);
|
2010-07-12 13:17:27 +00:00
|
|
|
i::Handle<i::JSArray> stackTrace =
|
2013-11-26 09:45:17 +00:00
|
|
|
i_isolate->CaptureCurrentStackTrace(frame_limit, options);
|
2010-07-12 13:17:27 +00:00
|
|
|
return Utils::StackTraceToLocal(stackTrace);
|
2010-05-06 07:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// --- S t a c k F r a m e ---
|
|
|
|
|
|
|
|
int StackFrame::GetLineNumber() const {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2010-05-06 07:32:44 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
2014-04-16 13:28:11 +00:00
|
|
|
i::Handle<i::Object> line = i::Object::GetProperty(
|
|
|
|
isolate, self, "lineNumber").ToHandleChecked();
|
2010-05-06 07:32:44 +00:00
|
|
|
if (!line->IsSmi()) {
|
|
|
|
return Message::kNoLineNumberInfo;
|
|
|
|
}
|
|
|
|
return i::Smi::cast(*line)->value();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int StackFrame::GetColumn() const {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2010-05-06 07:32:44 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
2014-04-16 13:28:11 +00:00
|
|
|
i::Handle<i::Object> column = i::Object::GetProperty(
|
|
|
|
isolate, self, "column").ToHandleChecked();
|
2010-05-06 07:32:44 +00:00
|
|
|
if (!column->IsSmi()) {
|
|
|
|
return Message::kNoColumnInfo;
|
|
|
|
}
|
|
|
|
return i::Smi::cast(*column)->value();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-30 14:54:59 +00:00
|
|
|
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);
|
2014-04-16 13:28:11 +00:00
|
|
|
i::Handle<i::Object> scriptId = i::Object::GetProperty(
|
|
|
|
isolate, self, "scriptId").ToHandleChecked();
|
2013-08-30 14:54:59 +00:00
|
|
|
if (!scriptId->IsSmi()) {
|
|
|
|
return Message::kNoScriptIdInfo;
|
|
|
|
}
|
|
|
|
return i::Smi::cast(*scriptId)->value();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-06 07:32:44 +00:00
|
|
|
Local<String> StackFrame::GetScriptName() const {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ENTER_V8(isolate);
|
2013-12-02 18:12:01 +00:00
|
|
|
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
|
2010-05-06 07:32:44 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
2014-04-16 13:28:11 +00:00
|
|
|
i::Handle<i::Object> name = i::Object::GetProperty(
|
|
|
|
isolate, self, "scriptName").ToHandleChecked();
|
2010-05-06 07:32:44 +00:00
|
|
|
if (!name->IsString()) {
|
|
|
|
return Local<String>();
|
|
|
|
}
|
2013-12-02 18:12:01 +00:00
|
|
|
return scope.Escape(Local<String>::Cast(Utils::ToLocal(name)));
|
2010-05-06 07:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-05 08:53:51 +00:00
|
|
|
Local<String> StackFrame::GetScriptNameOrSourceURL() const {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ENTER_V8(isolate);
|
2013-12-02 18:12:01 +00:00
|
|
|
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
|
2010-10-05 08:53:51 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
2014-04-16 13:28:11 +00:00
|
|
|
i::Handle<i::Object> name = i::Object::GetProperty(
|
|
|
|
isolate, self, "scriptNameOrSourceURL").ToHandleChecked();
|
2010-10-05 08:53:51 +00:00
|
|
|
if (!name->IsString()) {
|
|
|
|
return Local<String>();
|
|
|
|
}
|
2013-12-02 18:12:01 +00:00
|
|
|
return scope.Escape(Local<String>::Cast(Utils::ToLocal(name)));
|
2010-10-05 08:53:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-06 07:32:44 +00:00
|
|
|
Local<String> StackFrame::GetFunctionName() const {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ENTER_V8(isolate);
|
2013-12-02 18:12:01 +00:00
|
|
|
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
|
2010-05-06 07:32:44 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
2014-04-16 13:28:11 +00:00
|
|
|
i::Handle<i::Object> name = i::Object::GetProperty(
|
|
|
|
isolate, self, "functionName").ToHandleChecked();
|
2010-05-06 07:32:44 +00:00
|
|
|
if (!name->IsString()) {
|
|
|
|
return Local<String>();
|
|
|
|
}
|
2013-12-02 18:12:01 +00:00
|
|
|
return scope.Escape(Local<String>::Cast(Utils::ToLocal(name)));
|
2010-05-06 07:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool StackFrame::IsEval() const {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2010-05-06 07:32:44 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
2014-04-16 13:28:11 +00:00
|
|
|
i::Handle<i::Object> is_eval = i::Object::GetProperty(
|
|
|
|
isolate, self, "isEval").ToHandleChecked();
|
2010-05-06 07:32:44 +00:00
|
|
|
return is_eval->IsTrue();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool StackFrame::IsConstructor() const {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2010-05-06 07:32:44 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
2014-04-16 13:28:11 +00:00
|
|
|
i::Handle<i::Object> is_constructor = i::Object::GetProperty(
|
|
|
|
isolate, self, "isConstructor").ToHandleChecked();
|
2010-05-06 07:32:44 +00:00
|
|
|
return is_constructor->IsTrue();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-05 11:14:46 +00:00
|
|
|
// --- J S O N ---
|
|
|
|
|
2013-08-07 09:11:39 +00:00
|
|
|
Local<Value> JSON::Parse(Local<String> json_string) {
|
2014-04-15 08:30:42 +00:00
|
|
|
i::Handle<i::String> string = Utils::OpenHandle(*json_string);
|
|
|
|
i::Isolate* isolate = string->GetIsolate();
|
2013-08-05 11:14:46 +00:00
|
|
|
EnsureInitializedForIsolate(isolate, "v8::JSON::Parse");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
i::HandleScope scope(isolate);
|
2014-04-15 08:30:42 +00:00
|
|
|
i::Handle<i::String> source = i::String::Flatten(string);
|
2013-08-05 11:14:46 +00:00
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-03 14:25:59 +00:00
|
|
|
i::MaybeHandle<i::Object> maybe_result =
|
|
|
|
source->IsSeqOneByteString() ? i::JsonParser<true>::Parse(source)
|
|
|
|
: i::JsonParser<false>::Parse(source);
|
2013-08-05 11:14:46 +00:00
|
|
|
i::Handle<i::Object> result;
|
2014-04-03 14:25:59 +00:00
|
|
|
has_pending_exception = !maybe_result.ToHandle(&result);
|
2013-08-05 11:14:46 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>());
|
|
|
|
return Utils::ToLocal(
|
2013-08-07 09:11:39 +00:00
|
|
|
i::Handle<i::Object>::cast(scope.CloseAndEscape(result)));
|
2013-08-05 11:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// --- D a t a ---
|
|
|
|
|
2012-04-18 15:51:34 +00:00
|
|
|
bool Value::FullIsUndefined() const {
|
|
|
|
bool result = Utils::OpenHandle(this)->IsUndefined();
|
|
|
|
ASSERT_EQ(result, QuickIsUndefined());
|
|
|
|
return result;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-18 15:51:34 +00:00
|
|
|
bool Value::FullIsNull() const {
|
|
|
|
bool result = Utils::OpenHandle(this)->IsNull();
|
|
|
|
ASSERT_EQ(result, QuickIsNull());
|
|
|
|
return result;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
bool Value::IsTrue() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::OpenHandle(this)->IsTrue();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
bool Value::IsFalse() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::OpenHandle(this)->IsFalse();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
bool Value::IsFunction() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::OpenHandle(this)->IsJSFunction();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-26 10:33:11 +00:00
|
|
|
bool Value::FullIsString() const {
|
|
|
|
bool result = Utils::OpenHandle(this)->IsString();
|
|
|
|
ASSERT_EQ(result, QuickIsString());
|
|
|
|
return result;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-10 12:16:29 +00:00
|
|
|
bool Value::IsSymbol() const {
|
|
|
|
return Utils::OpenHandle(this)->IsSymbol();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
bool Value::IsArray() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::OpenHandle(this)->IsJSArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-30 18:53:27 +00:00
|
|
|
bool Value::IsArrayBuffer() const {
|
|
|
|
return Utils::OpenHandle(this)->IsJSArrayBuffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-24 11:23:50 +00:00
|
|
|
bool Value::IsArrayBufferView() const {
|
|
|
|
return Utils::OpenHandle(this)->IsJSArrayBufferView();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-30 18:53:27 +00:00
|
|
|
bool Value::IsTypedArray() const {
|
|
|
|
return Utils::OpenHandle(this)->IsJSTypedArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-24 16:01:15 +00:00
|
|
|
#define VALUE_IS_TYPED_ARRAY(Type, typeName, TYPE, ctype, size) \
|
|
|
|
bool Value::Is##Type##Array() const { \
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this); \
|
|
|
|
return obj->IsJSTypedArray() && \
|
|
|
|
i::JSTypedArray::cast(*obj)->type() == kExternal##Type##Array; \
|
2013-04-30 18:53:27 +00:00
|
|
|
}
|
|
|
|
|
2014-01-24 16:01:15 +00:00
|
|
|
TYPED_ARRAYS(VALUE_IS_TYPED_ARRAY)
|
2013-04-30 18:53:27 +00:00
|
|
|
|
|
|
|
#undef VALUE_IS_TYPED_ARRAY
|
|
|
|
|
|
|
|
|
2013-06-24 11:23:50 +00:00
|
|
|
bool Value::IsDataView() const {
|
|
|
|
return Utils::OpenHandle(this)->IsJSDataView();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
bool Value::IsObject() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::OpenHandle(this)->IsJSObject();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
bool Value::IsNumber() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::OpenHandle(this)->IsNumber();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
bool Value::IsBoolean() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::OpenHandle(this)->IsBoolean();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
bool Value::IsExternal() const {
|
2012-11-13 12:27:03 +00:00
|
|
|
return Utils::OpenHandle(this)->IsExternal();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
bool Value::IsInt32() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
if (obj->IsSmi()) return true;
|
|
|
|
if (obj->IsNumber()) {
|
2013-12-20 13:33:20 +00:00
|
|
|
return i::IsInt32Double(obj->Number());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-03 13:44:20 +00:00
|
|
|
bool Value::IsUint32() const {
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
if (obj->IsSmi()) return i::Smi::cast(*obj)->value() >= 0;
|
|
|
|
if (obj->IsNumber()) {
|
|
|
|
double value = obj->Number();
|
2013-12-20 13:33:20 +00:00
|
|
|
return !i::IsMinusZero(value) &&
|
2014-01-13 09:42:23 +00:00
|
|
|
value >= 0 &&
|
|
|
|
value <= i::kMaxUInt32 &&
|
|
|
|
value == i::FastUI2D(i::FastD2UI(value));
|
2010-03-03 13:44:20 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
bool Value::IsDate() const {
|
2008-10-23 08:25:23 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
2014-04-15 08:30:42 +00:00
|
|
|
if (!obj->IsHeapObject()) return false;
|
|
|
|
i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
|
2013-02-28 17:03:34 +00:00
|
|
|
return obj->HasSpecificClassOf(isolate->heap()->Date_string());
|
2008-10-23 08:25:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-14 11:00:04 +00:00
|
|
|
bool Value::IsStringObject() const {
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
2014-04-15 08:30:42 +00:00
|
|
|
if (!obj->IsHeapObject()) return false;
|
|
|
|
i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
|
2013-02-28 17:03:34 +00:00
|
|
|
return obj->HasSpecificClassOf(isolate->heap()->String_string());
|
2011-07-14 11:00:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-10 12:16:29 +00:00
|
|
|
bool Value::IsSymbolObject() const {
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
2014-04-15 08:30:42 +00:00
|
|
|
if (!obj->IsHeapObject()) return false;
|
|
|
|
i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
|
2013-04-10 12:16:29 +00:00
|
|
|
return obj->HasSpecificClassOf(isolate->heap()->Symbol_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-14 11:00:04 +00:00
|
|
|
bool Value::IsNumberObject() const {
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
2014-04-15 08:30:42 +00:00
|
|
|
if (!obj->IsHeapObject()) return false;
|
|
|
|
i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
|
2013-02-28 17:03:34 +00:00
|
|
|
return obj->HasSpecificClassOf(isolate->heap()->Number_string());
|
2011-07-14 11:00:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool CheckConstructor(i::Isolate* isolate,
|
|
|
|
i::Handle<i::JSObject> obj,
|
|
|
|
const char* class_name) {
|
2014-04-16 13:28:11 +00:00
|
|
|
i::Handle<i::Object> constr(obj->map()->constructor(), isolate);
|
2012-11-12 15:33:31 +00:00
|
|
|
if (!constr->IsJSFunction()) return false;
|
2014-04-16 13:28:11 +00:00
|
|
|
i::Handle<i::JSFunction> func = i::Handle<i::JSFunction>::cast(constr);
|
|
|
|
return func->shared()->native() && constr.is_identical_to(
|
|
|
|
i::Object::GetProperty(isolate,
|
|
|
|
isolate->js_builtins_object(),
|
|
|
|
class_name).ToHandleChecked());
|
2011-07-14 11:00:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Value::IsNativeError() const {
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
if (obj->IsJSObject()) {
|
|
|
|
i::Handle<i::JSObject> js_obj(i::JSObject::cast(*obj));
|
2014-04-15 08:30:42 +00:00
|
|
|
i::Isolate* isolate = js_obj->GetIsolate();
|
2011-07-14 11:00:04 +00:00
|
|
|
return CheckConstructor(isolate, js_obj, "$Error") ||
|
|
|
|
CheckConstructor(isolate, js_obj, "$EvalError") ||
|
|
|
|
CheckConstructor(isolate, js_obj, "$RangeError") ||
|
|
|
|
CheckConstructor(isolate, js_obj, "$ReferenceError") ||
|
|
|
|
CheckConstructor(isolate, js_obj, "$SyntaxError") ||
|
|
|
|
CheckConstructor(isolate, js_obj, "$TypeError") ||
|
|
|
|
CheckConstructor(isolate, js_obj, "$URIError");
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Value::IsBooleanObject() const {
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
2014-04-15 08:30:42 +00:00
|
|
|
if (!obj->IsHeapObject()) return false;
|
|
|
|
i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
|
2013-02-28 17:03:34 +00:00
|
|
|
return obj->HasSpecificClassOf(isolate->heap()->Boolean_string());
|
2011-07-14 11:00:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-10 09:53:56 +00:00
|
|
|
bool Value::IsRegExp() const {
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
return obj->IsJSRegExp();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
Local<String> Value::ToString() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> str;
|
|
|
|
if (obj->IsString()) {
|
|
|
|
str = obj;
|
|
|
|
} else {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
LOG_API(isolate, "ToString");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
has_pending_exception = !i::Execution::ToString(
|
|
|
|
isolate, obj).ToHandle(&str);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<String>());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2013-06-13 09:27:09 +00:00
|
|
|
return ToApiHandle<String>(str);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
Local<String> Value::ToDetailString() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> str;
|
|
|
|
if (obj->IsString()) {
|
|
|
|
str = obj;
|
|
|
|
} else {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
LOG_API(isolate, "ToDetailString");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
has_pending_exception = !i::Execution::ToDetailString(
|
|
|
|
isolate, obj).ToHandle(&str);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<String>());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2013-06-13 09:27:09 +00:00
|
|
|
return ToApiHandle<String>(str);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
Local<v8::Object> Value::ToObject() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> val;
|
|
|
|
if (obj->IsJSObject()) {
|
|
|
|
val = obj;
|
|
|
|
} else {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
LOG_API(isolate, "ToObject");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
has_pending_exception = !i::Execution::ToObject(
|
|
|
|
isolate, obj).ToHandle(&val);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2013-06-13 09:27:09 +00:00
|
|
|
return ToApiHandle<Object>(val);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
Local<Boolean> Value::ToBoolean() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
2009-04-03 08:18:24 +00:00
|
|
|
if (obj->IsBoolean()) {
|
2013-06-13 09:27:09 +00:00
|
|
|
return ToApiHandle<Boolean>(obj);
|
2009-04-03 08:18:24 +00:00
|
|
|
} else {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
LOG_API(isolate, "ToBoolean");
|
|
|
|
ENTER_V8(isolate);
|
2013-03-07 16:22:19 +00:00
|
|
|
i::Handle<i::Object> val =
|
|
|
|
isolate->factory()->ToBoolean(obj->BooleanValue());
|
2013-06-13 09:27:09 +00:00
|
|
|
return ToApiHandle<Boolean>(val);
|
2009-04-03 08:18:24 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
Local<Number> Value::ToNumber() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> num;
|
|
|
|
if (obj->IsNumber()) {
|
|
|
|
num = obj;
|
|
|
|
} else {
|
2014-04-15 08:30:42 +00:00
|
|
|
i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
|
2011-03-24 18:49:45 +00:00
|
|
|
LOG_API(isolate, "ToNumber");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
has_pending_exception = !i::Execution::ToNumber(
|
|
|
|
isolate, obj).ToHandle(&num);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<Number>());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2013-06-13 09:27:09 +00:00
|
|
|
return ToApiHandle<Number>(num);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
Local<Integer> Value::ToInteger() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> num;
|
|
|
|
if (obj->IsSmi()) {
|
|
|
|
num = obj;
|
|
|
|
} else {
|
2014-04-15 08:30:42 +00:00
|
|
|
i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
|
2011-03-24 18:49:45 +00:00
|
|
|
LOG_API(isolate, "ToInteger");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
has_pending_exception = !i::Execution::ToInteger(
|
|
|
|
isolate, obj).ToHandle(&num);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<Integer>());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2013-06-13 09:27:09 +00:00
|
|
|
return ToApiHandle<Integer>(num);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-01 12:57:15 +00:00
|
|
|
void i::Internals::CheckInitializedImpl(v8::Isolate* external_isolate) {
|
2013-06-25 08:11:50 +00:00
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
|
2014-01-13 09:42:23 +00:00
|
|
|
Utils::ApiCheck(isolate != NULL &&
|
|
|
|
isolate->IsInitialized() &&
|
|
|
|
!isolate->IsDead(),
|
|
|
|
"v8::internal::Internals::CheckInitialized()",
|
|
|
|
"Isolate is not initialized or V8 has died");
|
2013-06-25 08:11:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-26 10:33:11 +00:00
|
|
|
void External::CheckCast(v8::Value* that) {
|
2014-01-13 09:42:23 +00:00
|
|
|
Utils::ApiCheck(Utils::OpenHandle(that)->IsExternal(),
|
|
|
|
"v8::External::Cast()",
|
|
|
|
"Could not convert to external");
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-26 10:33:11 +00:00
|
|
|
void v8::Object::CheckCast(Value* that) {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
2014-01-13 09:42:23 +00:00
|
|
|
Utils::ApiCheck(obj->IsJSObject(),
|
|
|
|
"v8::Object::Cast()",
|
|
|
|
"Could not convert to object");
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-26 10:33:11 +00:00
|
|
|
void v8::Function::CheckCast(Value* that) {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
2014-01-13 09:42:23 +00:00
|
|
|
Utils::ApiCheck(obj->IsJSFunction(),
|
|
|
|
"v8::Function::Cast()",
|
|
|
|
"Could not convert to function");
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-26 10:33:11 +00:00
|
|
|
void v8::String::CheckCast(v8::Value* that) {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
2014-01-13 09:42:23 +00:00
|
|
|
Utils::ApiCheck(obj->IsString(),
|
|
|
|
"v8::String::Cast()",
|
|
|
|
"Could not convert to string");
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-10 12:16:29 +00:00
|
|
|
void v8::Symbol::CheckCast(v8::Value* that) {
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
2014-01-13 09:42:23 +00:00
|
|
|
Utils::ApiCheck(obj->IsSymbol(),
|
|
|
|
"v8::Symbol::Cast()",
|
|
|
|
"Could not convert to symbol");
|
2013-04-10 12:16:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-26 10:33:11 +00:00
|
|
|
void v8::Number::CheckCast(v8::Value* that) {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
2014-01-13 09:42:23 +00:00
|
|
|
Utils::ApiCheck(obj->IsNumber(),
|
|
|
|
"v8::Number::Cast()",
|
|
|
|
"Could not convert to number");
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-26 10:33:11 +00:00
|
|
|
void v8::Integer::CheckCast(v8::Value* that) {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
2014-01-13 09:42:23 +00:00
|
|
|
Utils::ApiCheck(obj->IsNumber(),
|
|
|
|
"v8::Integer::Cast()",
|
|
|
|
"Could not convert to number");
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-26 10:33:11 +00:00
|
|
|
void v8::Array::CheckCast(Value* that) {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
2014-01-13 09:42:23 +00:00
|
|
|
Utils::ApiCheck(obj->IsJSArray(),
|
|
|
|
"v8::Array::Cast()",
|
|
|
|
"Could not convert to array");
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-11 16:17:20 +00:00
|
|
|
void v8::Promise::CheckCast(Value* that) {
|
|
|
|
Utils::ApiCheck(that->IsPromise(),
|
|
|
|
"v8::Promise::Cast()",
|
|
|
|
"Could not convert to promise");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-17 09:57:25 +00:00
|
|
|
void v8::Promise::Resolver::CheckCast(Value* that) {
|
|
|
|
Utils::ApiCheck(that->IsPromise(),
|
|
|
|
"v8::Promise::Resolver::Cast()",
|
|
|
|
"Could not convert to promise resolver");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-25 12:02:23 +00:00
|
|
|
void v8::ArrayBuffer::CheckCast(Value* that) {
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
2014-01-13 09:42:23 +00:00
|
|
|
Utils::ApiCheck(obj->IsJSArrayBuffer(),
|
|
|
|
"v8::ArrayBuffer::Cast()",
|
|
|
|
"Could not convert to ArrayBuffer");
|
2013-04-25 12:02:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-24 11:23:50 +00:00
|
|
|
void v8::ArrayBufferView::CheckCast(Value* that) {
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
2014-01-13 09:42:23 +00:00
|
|
|
Utils::ApiCheck(obj->IsJSArrayBufferView(),
|
|
|
|
"v8::ArrayBufferView::Cast()",
|
|
|
|
"Could not convert to ArrayBufferView");
|
2013-06-24 11:23:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-29 11:09:03 +00:00
|
|
|
void v8::TypedArray::CheckCast(Value* that) {
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
2014-01-13 09:42:23 +00:00
|
|
|
Utils::ApiCheck(obj->IsJSTypedArray(),
|
|
|
|
"v8::TypedArray::Cast()",
|
|
|
|
"Could not convert to TypedArray");
|
2013-04-29 11:09:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-24 16:01:15 +00:00
|
|
|
#define CHECK_TYPED_ARRAY_CAST(Type, typeName, TYPE, ctype, size) \
|
|
|
|
void v8::Type##Array::CheckCast(Value* that) { \
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that); \
|
|
|
|
Utils::ApiCheck(obj->IsJSTypedArray() && \
|
|
|
|
i::JSTypedArray::cast(*obj)->type() == \
|
|
|
|
kExternal##Type##Array, \
|
|
|
|
"v8::" #Type "Array::Cast()", \
|
|
|
|
"Could not convert to " #Type "Array"); \
|
2013-04-29 11:09:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-24 16:01:15 +00:00
|
|
|
TYPED_ARRAYS(CHECK_TYPED_ARRAY_CAST)
|
2013-04-29 11:09:03 +00:00
|
|
|
|
|
|
|
#undef CHECK_TYPED_ARRAY_CAST
|
|
|
|
|
|
|
|
|
2013-06-24 11:23:50 +00:00
|
|
|
void v8::DataView::CheckCast(Value* that) {
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
2014-01-13 09:42:23 +00:00
|
|
|
Utils::ApiCheck(obj->IsJSDataView(),
|
|
|
|
"v8::DataView::Cast()",
|
|
|
|
"Could not convert to DataView");
|
2013-06-24 11:23:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-26 10:33:11 +00:00
|
|
|
void v8::Date::CheckCast(v8::Value* that) {
|
2008-10-23 08:25:23 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
2014-04-15 08:30:42 +00:00
|
|
|
i::Isolate* isolate = NULL;
|
|
|
|
if (obj->IsHeapObject()) isolate = i::HeapObject::cast(*obj)->GetIsolate();
|
|
|
|
Utils::ApiCheck(isolate != NULL &&
|
|
|
|
obj->HasSpecificClassOf(isolate->heap()->Date_string()),
|
2014-01-13 09:42:23 +00:00
|
|
|
"v8::Date::Cast()",
|
|
|
|
"Could not convert to date");
|
2008-10-23 08:25:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-14 11:00:04 +00:00
|
|
|
void v8::StringObject::CheckCast(v8::Value* that) {
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
2014-04-15 08:30:42 +00:00
|
|
|
i::Isolate* isolate = NULL;
|
|
|
|
if (obj->IsHeapObject()) isolate = i::HeapObject::cast(*obj)->GetIsolate();
|
|
|
|
Utils::ApiCheck(isolate != NULL &&
|
|
|
|
obj->HasSpecificClassOf(isolate->heap()->String_string()),
|
2014-01-13 09:42:23 +00:00
|
|
|
"v8::StringObject::Cast()",
|
|
|
|
"Could not convert to StringObject");
|
2011-07-14 11:00:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-10 12:16:29 +00:00
|
|
|
void v8::SymbolObject::CheckCast(v8::Value* that) {
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
2014-04-15 08:30:42 +00:00
|
|
|
i::Isolate* isolate = NULL;
|
|
|
|
if (obj->IsHeapObject()) isolate = i::HeapObject::cast(*obj)->GetIsolate();
|
|
|
|
Utils::ApiCheck(isolate != NULL &&
|
|
|
|
obj->HasSpecificClassOf(isolate->heap()->Symbol_string()),
|
2014-01-13 09:42:23 +00:00
|
|
|
"v8::SymbolObject::Cast()",
|
|
|
|
"Could not convert to SymbolObject");
|
2013-04-10 12:16:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-14 11:00:04 +00:00
|
|
|
void v8::NumberObject::CheckCast(v8::Value* that) {
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
2014-04-15 08:30:42 +00:00
|
|
|
i::Isolate* isolate = NULL;
|
|
|
|
if (obj->IsHeapObject()) isolate = i::HeapObject::cast(*obj)->GetIsolate();
|
|
|
|
Utils::ApiCheck(isolate != NULL &&
|
|
|
|
obj->HasSpecificClassOf(isolate->heap()->Number_string()),
|
2014-01-13 09:42:23 +00:00
|
|
|
"v8::NumberObject::Cast()",
|
|
|
|
"Could not convert to NumberObject");
|
2011-07-14 11:00:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void v8::BooleanObject::CheckCast(v8::Value* that) {
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
2014-04-15 08:30:42 +00:00
|
|
|
i::Isolate* isolate = NULL;
|
|
|
|
if (obj->IsHeapObject()) isolate = i::HeapObject::cast(*obj)->GetIsolate();
|
|
|
|
Utils::ApiCheck(isolate != NULL &&
|
|
|
|
obj->HasSpecificClassOf(isolate->heap()->Boolean_string()),
|
2014-01-13 09:42:23 +00:00
|
|
|
"v8::BooleanObject::Cast()",
|
|
|
|
"Could not convert to BooleanObject");
|
2011-07-14 11:00:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-04 15:04:16 +00:00
|
|
|
void v8::RegExp::CheckCast(v8::Value* that) {
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
2014-01-13 09:42:23 +00:00
|
|
|
Utils::ApiCheck(obj->IsJSRegExp(),
|
|
|
|
"v8::RegExp::Cast()",
|
|
|
|
"Could not convert to regular expression");
|
2010-10-04 15:04:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
bool Value::BooleanValue() const {
|
2013-03-07 16:22:19 +00:00
|
|
|
return Utils::OpenHandle(this)->BooleanValue();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
double Value::NumberValue() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> num;
|
|
|
|
if (obj->IsNumber()) {
|
|
|
|
num = obj;
|
|
|
|
} else {
|
2014-04-15 08:30:42 +00:00
|
|
|
i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
|
2011-03-24 18:49:45 +00:00
|
|
|
LOG_API(isolate, "NumberValue");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
has_pending_exception = !i::Execution::ToNumber(
|
|
|
|
isolate, obj).ToHandle(&num);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, i::OS::nan_value());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
return num->Number();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
int64_t Value::IntegerValue() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> num;
|
|
|
|
if (obj->IsNumber()) {
|
|
|
|
num = obj;
|
|
|
|
} else {
|
2014-04-15 08:30:42 +00:00
|
|
|
i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
|
2011-03-24 18:49:45 +00:00
|
|
|
LOG_API(isolate, "IntegerValue");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
has_pending_exception = !i::Execution::ToInteger(
|
|
|
|
isolate, obj).ToHandle(&num);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, 0);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
if (num->IsSmi()) {
|
|
|
|
return i::Smi::cast(*num)->value();
|
|
|
|
} else {
|
|
|
|
return static_cast<int64_t>(num->Number());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
Local<Int32> Value::ToInt32() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> num;
|
|
|
|
if (obj->IsSmi()) {
|
|
|
|
num = obj;
|
|
|
|
} else {
|
2014-04-15 08:30:42 +00:00
|
|
|
i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
|
2011-03-24 18:49:45 +00:00
|
|
|
LOG_API(isolate, "ToInt32");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
has_pending_exception = !i::Execution::ToInt32(isolate, obj).ToHandle(&num);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<Int32>());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2013-06-13 09:27:09 +00:00
|
|
|
return ToApiHandle<Int32>(num);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
Local<Uint32> Value::ToUint32() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> num;
|
|
|
|
if (obj->IsSmi()) {
|
|
|
|
num = obj;
|
|
|
|
} else {
|
2014-04-15 08:30:42 +00:00
|
|
|
i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
|
2011-03-24 18:49:45 +00:00
|
|
|
LOG_API(isolate, "ToUInt32");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
has_pending_exception = !i::Execution::ToUint32(
|
|
|
|
isolate, obj).ToHandle(&num);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<Uint32>());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2013-06-13 09:27:09 +00:00
|
|
|
return ToApiHandle<Uint32>(num);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
Local<Uint32> Value::ToArrayIndex() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
if (obj->IsSmi()) {
|
|
|
|
if (i::Smi::cast(*obj)->value() >= 0) return Utils::Uint32ToLocal(obj);
|
|
|
|
return Local<Uint32>();
|
|
|
|
}
|
2014-04-15 08:30:42 +00:00
|
|
|
i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
|
2011-03-24 18:49:45 +00:00
|
|
|
LOG_API(isolate, "ToArrayIndex");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
i::Handle<i::Object> string_obj;
|
|
|
|
has_pending_exception = !i::Execution::ToString(
|
|
|
|
isolate, obj).ToHandle(&string_obj);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<Uint32>());
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::String> str = i::Handle<i::String>::cast(string_obj);
|
|
|
|
uint32_t index;
|
|
|
|
if (str->AsArrayIndex(&index)) {
|
|
|
|
i::Handle<i::Object> value;
|
|
|
|
if (index <= static_cast<uint32_t>(i::Smi::kMaxValue)) {
|
2013-02-25 14:46:09 +00:00
|
|
|
value = i::Handle<i::Object>(i::Smi::FromInt(index), isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
} else {
|
2011-03-23 09:02:15 +00:00
|
|
|
value = isolate->factory()->NewNumber(index);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
return Utils::Uint32ToLocal(value);
|
|
|
|
}
|
|
|
|
return Local<Uint32>();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
int32_t Value::Int32Value() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
if (obj->IsSmi()) {
|
|
|
|
return i::Smi::cast(*obj)->value();
|
|
|
|
} else {
|
2014-04-15 08:30:42 +00:00
|
|
|
i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
LOG_API(isolate, "Int32Value (slow)");
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
i::Handle<i::Object> num;
|
|
|
|
has_pending_exception = !i::Execution::ToInt32(isolate, obj).ToHandle(&num);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, 0);
|
2008-07-03 15:10:15 +00:00
|
|
|
if (num->IsSmi()) {
|
|
|
|
return i::Smi::cast(*num)->value();
|
|
|
|
} else {
|
|
|
|
return static_cast<int32_t>(num->Number());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
bool Value::Equals(Handle<Value> that) const {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2014-01-13 09:42:23 +00:00
|
|
|
if (!Utils::ApiCheck(this != NULL && !that.IsEmpty(),
|
|
|
|
"v8::Value::Equals()",
|
|
|
|
"Reading from empty handle")) {
|
2008-07-03 15:10:15 +00:00
|
|
|
return false;
|
2009-04-03 07:49:20 +00:00
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
LOG_API(isolate, "Equals");
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> other = Utils::OpenHandle(*that);
|
2011-02-09 19:09:26 +00:00
|
|
|
// If both obj and other are JSObjects, we'd better compare by identity
|
|
|
|
// immediately when going into JS builtin. The reason is Invoke
|
|
|
|
// would overwrite global object receiver with global proxy.
|
|
|
|
if (obj->IsJSObject() && other->IsJSObject()) {
|
|
|
|
return *obj == *other;
|
|
|
|
}
|
2011-10-06 09:31:38 +00:00
|
|
|
i::Handle<i::Object> args[] = { other };
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
i::Handle<i::Object> result;
|
|
|
|
has_pending_exception = !CallV8HeapFunction(
|
|
|
|
"EQUALS", obj, ARRAY_SIZE(args), args).ToHandle(&result);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, false);
|
2008-07-03 15:10:15 +00:00
|
|
|
return *result == i::Smi::FromInt(i::EQUAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
bool Value::StrictEquals(Handle<Value> that) const {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2014-01-13 09:42:23 +00:00
|
|
|
if (!Utils::ApiCheck(this != NULL && !that.IsEmpty(),
|
|
|
|
"v8::Value::StrictEquals()",
|
|
|
|
"Reading from empty handle")) {
|
2008-07-03 15:10:15 +00:00
|
|
|
return false;
|
2009-04-03 07:49:20 +00:00
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
LOG_API(isolate, "StrictEquals");
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> other = Utils::OpenHandle(*that);
|
|
|
|
// Must check HeapNumber first, since NaN !== NaN.
|
|
|
|
if (obj->IsHeapNumber()) {
|
|
|
|
if (!other->IsNumber()) return false;
|
|
|
|
double x = obj->Number();
|
|
|
|
double y = other->Number();
|
|
|
|
// Must check explicitly for NaN:s on Windows, but -0 works fine.
|
2013-04-19 13:26:47 +00:00
|
|
|
return x == y && !std::isnan(x) && !std::isnan(y);
|
2008-07-03 15:10:15 +00:00
|
|
|
} else if (*obj == *other) { // Also covers Booleans.
|
|
|
|
return true;
|
|
|
|
} else if (obj->IsSmi()) {
|
|
|
|
return other->IsNumber() && obj->Number() == other->Number();
|
|
|
|
} else if (obj->IsString()) {
|
|
|
|
return other->IsString() &&
|
2014-04-11 07:27:25 +00:00
|
|
|
i::String::Equals(i::Handle<i::String>::cast(obj),
|
|
|
|
i::Handle<i::String>::cast(other));
|
2008-07-03 15:10:15 +00:00
|
|
|
} else if (obj->IsUndefined() || obj->IsUndetectableObject()) {
|
|
|
|
return other->IsUndefined() || other->IsUndetectableObject();
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-24 16:51:43 +00:00
|
|
|
bool Value::SameValue(Handle<Value> that) const {
|
2014-01-13 09:42:23 +00:00
|
|
|
if (!Utils::ApiCheck(this != NULL && !that.IsEmpty(),
|
|
|
|
"v8::Value::SameValue()",
|
|
|
|
"Reading from empty handle")) {
|
2013-09-24 16:51:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> other = Utils::OpenHandle(*that);
|
|
|
|
return obj->SameValue(*other);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
uint32_t Value::Uint32Value() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
if (obj->IsSmi()) {
|
|
|
|
return i::Smi::cast(*obj)->value();
|
|
|
|
} else {
|
2014-04-15 08:30:42 +00:00
|
|
|
i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
|
2011-03-24 18:49:45 +00:00
|
|
|
LOG_API(isolate, "Uint32Value");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
i::Handle<i::Object> num;
|
|
|
|
has_pending_exception = !i::Execution::ToUint32(
|
|
|
|
isolate, obj).ToHandle(&num);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, 0);
|
2008-07-03 15:10:15 +00:00
|
|
|
if (num->IsSmi()) {
|
|
|
|
return i::Smi::cast(*num)->value();
|
|
|
|
} else {
|
|
|
|
return static_cast<uint32_t>(num->Number());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool v8::Object::Set(v8::Handle<Value> key, v8::Handle<Value> value,
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
v8::PropertyAttribute attribs) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
ON_BAILOUT(isolate, "v8::Object::Set()", return false);
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> self = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
|
|
|
|
i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-04 12:06:11 +00:00
|
|
|
has_pending_exception = i::Runtime::SetObjectProperty(
|
2012-11-22 07:58:59 +00:00
|
|
|
isolate,
|
2008-07-03 15:10:15 +00:00
|
|
|
self,
|
|
|
|
key_obj,
|
2009-04-21 13:28:11 +00:00
|
|
|
value_obj,
|
2011-03-02 04:53:43 +00:00
|
|
|
static_cast<PropertyAttributes>(attribs),
|
2014-04-04 12:06:11 +00:00
|
|
|
i::SLOPPY).is_null();
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, false);
|
2009-04-21 13:28:11 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-02 18:47:03 +00:00
|
|
|
bool v8::Object::Set(uint32_t index, v8::Handle<Value> value) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
ON_BAILOUT(isolate, "v8::Object::Set()", return false);
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2010-03-02 18:47:03 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-08 07:04:13 +00:00
|
|
|
has_pending_exception = i::JSObject::SetElement(
|
|
|
|
self, index, value_obj, NONE, i::SLOPPY).is_null();
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, false);
|
2010-03-02 18:47:03 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-21 13:28:11 +00:00
|
|
|
bool v8::Object::ForceSet(v8::Handle<Value> key,
|
|
|
|
v8::Handle<Value> value,
|
|
|
|
v8::PropertyAttribute attribs) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
ON_BAILOUT(isolate, "v8::Object::ForceSet()", return false);
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2009-04-21 13:28:11 +00:00
|
|
|
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);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-04 12:06:11 +00:00
|
|
|
has_pending_exception = i::Runtime::ForceSetObjectProperty(
|
2009-04-21 13:28:11 +00:00
|
|
|
self,
|
|
|
|
key_obj,
|
2008-07-03 15:10:15 +00:00
|
|
|
value_obj,
|
2014-04-04 12:06:11 +00:00
|
|
|
static_cast<PropertyAttributes>(attribs)).is_null();
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, false);
|
2008-07-03 15:10:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
|
|
|
bool v8::Object::SetPrivate(v8::Handle<Private> key, v8::Handle<Value> value) {
|
2014-05-22 15:27:57 +00:00
|
|
|
return ForceSet(v8::Handle<Value>(reinterpret_cast<Value*>(*key)),
|
|
|
|
value, DontEnum);
|
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-08 09:46:09 +00:00
|
|
|
bool v8::Object::ForceDelete(v8::Handle<Value> key) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
ON_BAILOUT(isolate, "v8::Object::ForceDelete()", return false);
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2009-06-08 09:46:09 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2012-04-20 10:21:08 +00:00
|
|
|
// When deleting a property on the global object using ForceDelete
|
|
|
|
// deoptimize all functions as optimized code does not check for the hole
|
|
|
|
// value with DontDelete properties. We have to deoptimize all contexts
|
|
|
|
// because of possible cross-context inlined functions.
|
|
|
|
if (self->IsJSGlobalProxy() || self->IsGlobalObject()) {
|
2013-03-18 13:57:49 +00:00
|
|
|
i::Deoptimizer::DeoptimizeAll(isolate);
|
2012-04-20 10:21:08 +00:00
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-08 07:04:13 +00:00
|
|
|
i::Handle<i::Object> obj;
|
|
|
|
has_pending_exception = !i::Runtime::DeleteObjectProperty(
|
|
|
|
isolate, self, key_obj, i::JSReceiver::FORCE_DELETION).ToHandle(&obj);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, false);
|
2009-06-08 09:46:09 +00:00
|
|
|
return obj->IsTrue();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Local<Value> v8::Object::Get(v8::Handle<Value> key) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
ON_BAILOUT(isolate, "v8::Object::Get()", return Local<v8::Value>());
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> self = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-10 09:20:11 +00:00
|
|
|
i::Handle<i::Object> result;
|
|
|
|
has_pending_exception =
|
|
|
|
!i::Runtime::GetObjectProperty(isolate, self, key_obj).ToHandle(&result);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>());
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::ToLocal(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-02 18:47:03 +00:00
|
|
|
Local<Value> v8::Object::Get(uint32_t index) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
ON_BAILOUT(isolate, "v8::Object::Get()", return Local<v8::Value>());
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2010-03-02 18:47:03 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-10 09:20:11 +00:00
|
|
|
i::Handle<i::Object> result;
|
|
|
|
has_pending_exception =
|
|
|
|
!i::Object::GetElement(isolate, self, index).ToHandle(&result);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>());
|
2010-03-02 18:47:03 +00:00
|
|
|
return Utils::ToLocal(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
|
|
|
Local<Value> v8::Object::GetPrivate(v8::Handle<Private> key) {
|
2013-11-13 12:18:52 +00:00
|
|
|
return Get(v8::Handle<Value>(reinterpret_cast<Value*>(*key)));
|
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-18 17:44:57 +00:00
|
|
|
PropertyAttribute v8::Object::GetPropertyAttributes(v8::Handle<Value> key) {
|
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ON_BAILOUT(isolate, "v8::Object::GetPropertyAttribute()",
|
|
|
|
return static_cast<PropertyAttribute>(NONE));
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
i::HandleScope scope(isolate);
|
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
|
2013-04-10 12:16:29 +00:00
|
|
|
if (!key_obj->IsName()) {
|
2011-07-18 17:44:57 +00:00
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
has_pending_exception = !i::Execution::ToString(
|
|
|
|
isolate, key_obj).ToHandle(&key_obj);
|
2011-07-18 17:44:57 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, static_cast<PropertyAttribute>(NONE));
|
|
|
|
}
|
2013-04-10 12:16:29 +00:00
|
|
|
i::Handle<i::Name> key_name = i::Handle<i::Name>::cast(key_obj);
|
2014-03-13 11:55:31 +00:00
|
|
|
PropertyAttributes result =
|
|
|
|
i::JSReceiver::GetPropertyAttribute(self, key_name);
|
2011-07-18 17:44:57 +00:00
|
|
|
if (result == ABSENT) return static_cast<PropertyAttribute>(NONE);
|
|
|
|
return static_cast<PropertyAttribute>(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Local<Value> v8::Object::GetPrototype() {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2014-05-22 15:27:57 +00:00
|
|
|
ON_BAILOUT(isolate, "v8::Object::GetPrototype()", return Local<v8::Value>());
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> self = Utils::OpenHandle(this);
|
2013-02-27 13:22:29 +00:00
|
|
|
i::Handle<i::Object> result(self->GetPrototype(isolate), isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::ToLocal(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-10 14:44:15 +00:00
|
|
|
bool v8::Object::SetPrototype(Handle<Value> value) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
ON_BAILOUT(isolate, "v8::Object::SetPrototype()", return false);
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2010-02-10 14:44:15 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
|
2011-04-07 19:52:24 +00:00
|
|
|
// We do not allow exceptions thrown while setting the prototype
|
|
|
|
// to propagate outside.
|
|
|
|
TryCatch try_catch;
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-22 09:32:42 +00:00
|
|
|
i::MaybeHandle<i::Object> result = i::JSObject::SetPrototype(
|
|
|
|
self, value_obj);
|
2010-02-10 14:44:15 +00:00
|
|
|
has_pending_exception = result.is_null();
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, false);
|
2010-02-10 14:44:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-06 13:35:21 +00:00
|
|
|
Local<Object> v8::Object::FindInstanceInPrototypeChain(
|
|
|
|
v8::Handle<FunctionTemplate> tmpl) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ON_BAILOUT(isolate,
|
2011-03-18 20:35:07 +00:00
|
|
|
"v8::Object::FindInstanceInPrototypeChain()",
|
2009-08-06 13:35:21 +00:00
|
|
|
return Local<v8::Object>());
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2009-08-06 13:35:21 +00:00
|
|
|
i::JSObject* object = *Utils::OpenHandle(this);
|
|
|
|
i::FunctionTemplateInfo* tmpl_info = *Utils::OpenHandle(*tmpl);
|
2013-11-19 13:38:15 +00:00
|
|
|
while (!tmpl_info->IsTemplateFor(object)) {
|
2009-08-06 13:35:21 +00:00
|
|
|
i::Object* prototype = object->GetPrototype();
|
|
|
|
if (!prototype->IsJSObject()) return Local<Object>();
|
|
|
|
object = i::JSObject::cast(prototype);
|
|
|
|
}
|
|
|
|
return Utils::ToLocal(i::Handle<i::JSObject>(object));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-23 10:31:49 +00:00
|
|
|
Local<Array> v8::Object::GetPropertyNames() {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-23 09:02:15 +00:00
|
|
|
ON_BAILOUT(isolate, "v8::Object::GetPropertyNames()",
|
2011-03-18 20:35:07 +00:00
|
|
|
return Local<v8::Array>());
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
|
|
|
i::HandleScope scope(isolate);
|
2008-10-23 10:31:49 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
2014-04-10 09:20:11 +00:00
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
|
|
|
i::Handle<i::FixedArray> value;
|
2014-04-16 13:28:11 +00:00
|
|
|
has_pending_exception = !i::JSReceiver::GetKeys(
|
|
|
|
self, i::JSReceiver::INCLUDE_PROTOS).ToHandle(&value);
|
2014-04-10 09:20:11 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Array>());
|
2008-10-23 10:31:49 +00:00
|
|
|
// Because we use caching to speed up enumeration it is important
|
|
|
|
// to never change the result of the basic enumeration function so
|
2011-06-10 12:33:55 +00:00
|
|
|
// we clone the result.
|
|
|
|
i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value);
|
|
|
|
i::Handle<i::JSArray> result =
|
|
|
|
isolate->factory()->NewJSArrayWithElements(elms);
|
|
|
|
return Utils::ToLocal(scope.CloseAndEscape(result));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<Array> v8::Object::GetOwnPropertyNames() {
|
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ON_BAILOUT(isolate, "v8::Object::GetOwnPropertyNames()",
|
|
|
|
return Local<v8::Array>());
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
i::HandleScope scope(isolate);
|
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
2014-04-10 09:20:11 +00:00
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
|
|
|
i::Handle<i::FixedArray> value;
|
2014-04-16 13:28:11 +00:00
|
|
|
has_pending_exception = !i::JSReceiver::GetKeys(
|
2014-05-22 15:27:57 +00:00
|
|
|
self, i::JSReceiver::OWN_ONLY).ToHandle(&value);
|
2014-04-10 09:20:11 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Array>());
|
2011-06-10 12:33:55 +00:00
|
|
|
// Because we use caching to speed up enumeration it is important
|
|
|
|
// to never change the result of the basic enumeration function so
|
2008-10-23 10:31:49 +00:00
|
|
|
// we clone the result.
|
2011-03-23 09:02:15 +00:00
|
|
|
i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value);
|
|
|
|
i::Handle<i::JSArray> result =
|
|
|
|
isolate->factory()->NewJSArrayWithElements(elms);
|
2011-03-24 18:49:45 +00:00
|
|
|
return Utils::ToLocal(scope.CloseAndEscape(result));
|
2008-10-23 10:31:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Local<String> v8::Object::ObjectProtoToString() {
|
2013-11-22 12:28:58 +00:00
|
|
|
i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate);
|
|
|
|
ON_BAILOUT(i_isolate, "v8::Object::ObjectProtoToString()",
|
2011-03-18 20:35:07 +00:00
|
|
|
return Local<v8::String>());
|
2013-11-22 12:28:58 +00:00
|
|
|
ENTER_V8(i_isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
|
|
|
|
2013-11-22 12:28:58 +00:00
|
|
|
i::Handle<i::Object> name(self->class_name(), i_isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Native implementation of Object.prototype.toString (v8natives.js):
|
2013-03-22 16:33:50 +00:00
|
|
|
// var c = %_ClassOf(this);
|
2008-07-03 15:10:15 +00:00
|
|
|
// if (c === 'Arguments') c = 'Object';
|
|
|
|
// return "[object " + c + "]";
|
|
|
|
|
|
|
|
if (!name->IsString()) {
|
2013-11-22 12:28:58 +00:00
|
|
|
return v8::String::NewFromUtf8(isolate, "[object ]");
|
2008-07-03 15:10:15 +00:00
|
|
|
} else {
|
|
|
|
i::Handle<i::String> class_name = i::Handle<i::String>::cast(name);
|
2013-01-09 10:30:54 +00:00
|
|
|
if (class_name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("Arguments"))) {
|
2013-11-22 12:28:58 +00:00
|
|
|
return v8::String::NewFromUtf8(isolate, "[object Object]");
|
2008-07-03 15:10:15 +00:00
|
|
|
} else {
|
|
|
|
const char* prefix = "[object ";
|
|
|
|
Local<String> str = Utils::ToLocal(class_name);
|
|
|
|
const char* postfix = "]";
|
|
|
|
|
2009-11-11 09:50:06 +00:00
|
|
|
int prefix_len = i::StrLength(prefix);
|
2013-05-03 06:47:24 +00:00
|
|
|
int str_len = str->Utf8Length();
|
2009-11-11 09:50:06 +00:00
|
|
|
int postfix_len = i::StrLength(postfix);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-11-11 09:50:06 +00:00
|
|
|
int buf_len = prefix_len + str_len + postfix_len;
|
2010-05-05 12:25:58 +00:00
|
|
|
i::ScopedVector<char> buf(buf_len);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Write prefix.
|
2010-05-05 12:25:58 +00:00
|
|
|
char* ptr = buf.start();
|
2014-05-27 07:57:22 +00:00
|
|
|
i::MemCopy(ptr, prefix, prefix_len * v8::internal::kCharSize);
|
2008-07-03 15:10:15 +00:00
|
|
|
ptr += prefix_len;
|
|
|
|
|
|
|
|
// Write real content.
|
2013-05-03 06:47:24 +00:00
|
|
|
str->WriteUtf8(ptr, str_len);
|
2008-07-03 15:10:15 +00:00
|
|
|
ptr += str_len;
|
|
|
|
|
|
|
|
// Write postfix.
|
2014-05-27 07:57:22 +00:00
|
|
|
i::MemCopy(ptr, postfix, postfix_len * v8::internal::kCharSize);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Copy the buffer into a heap-allocated string and return it.
|
2013-11-22 12:28:58 +00:00
|
|
|
Local<String> result = v8::String::NewFromUtf8(
|
|
|
|
isolate, buf.start(), String::kNormalString, buf_len);
|
2008-07-03 15:10:15 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-28 16:29:53 +00:00
|
|
|
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);
|
2013-02-25 14:46:09 +00:00
|
|
|
i::Handle<i::Object> constructor(self->GetConstructor(), isolate);
|
2012-06-28 16:29:53 +00:00
|
|
|
return Utils::ToLocal(constructor);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-25 08:04:12 +00:00
|
|
|
Local<String> v8::Object::GetConstructorName() {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
ON_BAILOUT(isolate, "v8::Object::GetConstructorName()",
|
|
|
|
return Local<v8::String>());
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2010-11-25 08:04:12 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::String> name(self->constructor_name());
|
|
|
|
return Utils::ToLocal(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-10 12:16:29 +00:00
|
|
|
bool v8::Object::Delete(v8::Handle<Value> key) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
ON_BAILOUT(isolate, "v8::Object::Delete()", return false);
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
2013-04-10 12:16:29 +00:00
|
|
|
i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-08 07:04:13 +00:00
|
|
|
i::Handle<i::Object> obj;
|
|
|
|
has_pending_exception = !i::Runtime::DeleteObjectProperty(
|
|
|
|
isolate, self, key_obj, i::JSReceiver::NORMAL_DELETION).ToHandle(&obj);
|
2013-04-10 12:16:29 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, false);
|
|
|
|
return obj->IsTrue();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
|
|
|
bool v8::Object::DeletePrivate(v8::Handle<Private> key) {
|
2013-11-13 12:18:52 +00:00
|
|
|
return Delete(v8::Handle<Value>(reinterpret_cast<Value*>(*key)));
|
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-10 12:16:29 +00:00
|
|
|
bool v8::Object::Has(v8::Handle<Value> key) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ON_BAILOUT(isolate, "v8::Object::Has()", return false);
|
|
|
|
ENTER_V8(isolate);
|
2013-04-10 12:16:29 +00:00
|
|
|
i::Handle<i::JSReceiver> self = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-08 07:04:13 +00:00
|
|
|
i::Handle<i::Object> obj;
|
|
|
|
has_pending_exception = !i::Runtime::HasObjectProperty(
|
|
|
|
isolate, self, key_obj).ToHandle(&obj);
|
2013-04-10 12:16:29 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, false);
|
|
|
|
return obj->IsTrue();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
|
|
|
bool v8::Object::HasPrivate(v8::Handle<Private> key) {
|
2014-05-22 15:27:57 +00:00
|
|
|
// TODO(rossberg): this should use HasOwnProperty, but we'd need to
|
|
|
|
// generalise that to a (noy yet existant) Name argument first.
|
2013-11-13 12:18:52 +00:00
|
|
|
return Has(v8::Handle<Value>(reinterpret_cast<Value*>(*key)));
|
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
bool v8::Object::Delete(uint32_t index) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ON_BAILOUT(isolate, "v8::Object::DeleteProperty()",
|
2011-03-18 20:35:07 +00:00
|
|
|
return false);
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope scope(reinterpret_cast<Isolate*>(isolate));
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
2014-04-08 07:04:13 +00:00
|
|
|
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
|
|
|
i::Handle<i::Object> obj;
|
|
|
|
has_pending_exception =
|
|
|
|
!i::JSReceiver::DeleteElement(self, index).ToHandle(&obj);
|
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, false);
|
|
|
|
return obj->IsTrue();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool v8::Object::Has(uint32_t index) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ON_BAILOUT(isolate, "v8::Object::HasProperty()", return false);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
2013-09-17 11:34:20 +00:00
|
|
|
return i::JSReceiver::HasElement(self, index);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-21 06:36:24 +00:00
|
|
|
template<typename Setter, typename Getter, typename Data>
|
|
|
|
static inline bool ObjectSetAccessor(Object* obj,
|
|
|
|
Handle<String> name,
|
|
|
|
Setter getter,
|
|
|
|
Getter setter,
|
|
|
|
Data data,
|
|
|
|
AccessControl settings,
|
|
|
|
PropertyAttribute attributes) {
|
|
|
|
i::Isolate* isolate = Utils::OpenHandle(obj)->GetIsolate();
|
|
|
|
ON_BAILOUT(isolate, "v8::Object::SetAccessor()", return false);
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
i::HandleScope scope(isolate);
|
|
|
|
v8::Handle<AccessorSignature> signature;
|
|
|
|
i::Handle<i::AccessorInfo> info = MakeAccessorInfo(
|
|
|
|
name, getter, setter, data, settings, attributes, signature);
|
2013-03-07 11:42:58 +00:00
|
|
|
if (info.is_null()) return false;
|
|
|
|
bool fast = Utils::OpenHandle(obj)->HasFastProperties();
|
2014-04-17 08:33:18 +00:00
|
|
|
i::Handle<i::Object> result;
|
|
|
|
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
|
|
|
|
isolate, result,
|
|
|
|
i::JSObject::SetAccessor(Utils::OpenHandle(obj), info),
|
|
|
|
false);
|
|
|
|
if (result->IsUndefined()) return false;
|
2013-03-07 11:42:58 +00:00
|
|
|
if (fast) i::JSObject::TransformToFastProperties(Utils::OpenHandle(obj), 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-21 06:36:24 +00:00
|
|
|
bool Object::SetAccessor(Handle<String> name,
|
|
|
|
AccessorGetterCallback getter,
|
|
|
|
AccessorSetterCallback setter,
|
|
|
|
v8::Handle<Value> data,
|
|
|
|
AccessControl settings,
|
|
|
|
PropertyAttribute attributes) {
|
|
|
|
return ObjectSetAccessor(
|
|
|
|
this, name, getter, setter, data, settings, attributes);
|
2013-03-07 11:42:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-04 07:45:36 +00:00
|
|
|
bool Object::SetDeclaredAccessor(Local<String> name,
|
|
|
|
Local<DeclaredAccessorDescriptor> descriptor,
|
|
|
|
PropertyAttribute attributes,
|
|
|
|
AccessControl settings) {
|
2013-05-21 06:36:24 +00:00
|
|
|
void* null = NULL;
|
|
|
|
return ObjectSetAccessor(
|
|
|
|
this, name, descriptor, null, null, settings, attributes);
|
2010-05-25 12:14:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-24 08:41:59 +00:00
|
|
|
void Object::SetAccessorProperty(Local<String> name,
|
|
|
|
Local<Function> getter,
|
|
|
|
Handle<Function> setter,
|
|
|
|
PropertyAttribute attribute,
|
|
|
|
AccessControl settings) {
|
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ON_BAILOUT(isolate, "v8::Object::SetAccessorProperty()", return);
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
i::HandleScope scope(isolate);
|
|
|
|
i::Handle<i::Object> getter_i = v8::Utils::OpenHandle(*getter);
|
|
|
|
i::Handle<i::Object> setter_i = v8::Utils::OpenHandle(*setter, true);
|
|
|
|
if (setter_i.is_null()) setter_i = isolate->factory()->null_value();
|
|
|
|
i::JSObject::DefineAccessor(v8::Utils::OpenHandle(this),
|
|
|
|
v8::Utils::OpenHandle(*name),
|
|
|
|
getter_i,
|
|
|
|
setter_i,
|
|
|
|
static_cast<PropertyAttributes>(attribute),
|
|
|
|
settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-28 09:27:40 +00:00
|
|
|
bool v8::Object::HasOwnProperty(Handle<String> key) {
|
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ON_BAILOUT(isolate, "v8::Object::HasOwnProperty()",
|
|
|
|
return false);
|
2014-05-22 15:27:57 +00:00
|
|
|
return i::JSReceiver::HasOwnProperty(
|
2013-09-17 11:34:20 +00:00
|
|
|
Utils::OpenHandle(this), Utils::OpenHandle(*key));
|
2011-04-28 09:27:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
bool v8::Object::HasRealNamedProperty(Handle<String> key) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ON_BAILOUT(isolate, "v8::Object::HasRealNamedProperty()",
|
2011-03-18 20:35:07 +00:00
|
|
|
return false);
|
2013-10-18 12:52:07 +00:00
|
|
|
return i::JSObject::HasRealNamedProperty(Utils::OpenHandle(this),
|
|
|
|
Utils::OpenHandle(*key));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool v8::Object::HasRealIndexedProperty(uint32_t index) {
|
2013-04-04 19:12:59 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ON_BAILOUT(isolate, "v8::Object::HasRealIndexedProperty()",
|
2011-03-18 20:35:07 +00:00
|
|
|
return false);
|
2013-10-18 12:52:07 +00:00
|
|
|
return i::JSObject::HasRealElementProperty(Utils::OpenHandle(this), index);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool v8::Object::HasRealNamedCallbackProperty(Handle<String> key) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ON_BAILOUT(isolate,
|
2011-03-18 20:35:07 +00:00
|
|
|
"v8::Object::HasRealNamedCallbackProperty()",
|
|
|
|
return false);
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2013-10-18 12:52:07 +00:00
|
|
|
return i::JSObject::HasRealNamedCallbackProperty(Utils::OpenHandle(this),
|
|
|
|
Utils::OpenHandle(*key));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool v8::Object::HasNamedLookupInterceptor() {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ON_BAILOUT(isolate, "v8::Object::HasNamedLookupInterceptor()",
|
2011-03-18 20:35:07 +00:00
|
|
|
return false);
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::OpenHandle(this)->HasNamedInterceptor();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool v8::Object::HasIndexedLookupInterceptor() {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ON_BAILOUT(isolate, "v8::Object::HasIndexedLookupInterceptor()",
|
2011-03-18 20:35:07 +00:00
|
|
|
return false);
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::OpenHandle(this)->HasIndexedInterceptor();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-07 19:52:24 +00:00
|
|
|
static Local<Value> GetPropertyByLookup(i::Isolate* isolate,
|
|
|
|
i::Handle<i::JSObject> receiver,
|
|
|
|
i::Handle<i::String> name,
|
|
|
|
i::LookupResult* lookup) {
|
|
|
|
if (!lookup->IsProperty()) {
|
|
|
|
// No real property was found.
|
|
|
|
return Local<Value>();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the property being looked up is a callback, it can throw
|
|
|
|
// an exception.
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2011-10-19 12:04:16 +00:00
|
|
|
PropertyAttributes ignored;
|
2014-04-04 12:25:45 +00:00
|
|
|
i::Handle<i::Object> result;
|
|
|
|
has_pending_exception = !i::Object::GetProperty(
|
|
|
|
receiver, receiver, lookup, name, &ignored).ToHandle(&result);
|
2011-04-07 19:52:24 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>());
|
|
|
|
|
|
|
|
return Utils::ToLocal(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-28 14:32:48 +00:00
|
|
|
Local<Value> v8::Object::GetRealNamedPropertyInPrototypeChain(
|
2014-01-13 09:42:23 +00:00
|
|
|
Handle<String> key) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ON_BAILOUT(isolate,
|
2011-03-18 20:35:07 +00:00
|
|
|
"v8::Object::GetRealNamedPropertyInPrototypeChain()",
|
2008-07-03 15:10:15 +00:00
|
|
|
return Local<Value>());
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::JSObject> self_obj = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::String> key_obj = Utils::OpenHandle(*key);
|
2011-10-18 11:18:55 +00:00
|
|
|
i::LookupResult lookup(isolate);
|
2014-04-29 13:43:17 +00:00
|
|
|
self_obj->LookupRealNamedPropertyInPrototypes(key_obj, &lookup);
|
2011-04-07 19:52:24 +00:00
|
|
|
return GetPropertyByLookup(isolate, self_obj, key_obj, &lookup);
|
2009-09-25 12:29:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-28 14:32:48 +00:00
|
|
|
Local<Value> v8::Object::GetRealNamedProperty(Handle<String> key) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ON_BAILOUT(isolate, "v8::Object::GetRealNamedProperty()",
|
2011-03-18 20:35:07 +00:00
|
|
|
return Local<Value>());
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2009-09-25 12:29:24 +00:00
|
|
|
i::Handle<i::JSObject> self_obj = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::String> key_obj = Utils::OpenHandle(*key);
|
2011-10-18 11:18:55 +00:00
|
|
|
i::LookupResult lookup(isolate);
|
2014-04-29 13:43:17 +00:00
|
|
|
self_obj->LookupRealNamedProperty(key_obj, &lookup);
|
2011-04-07 19:52:24 +00:00
|
|
|
return GetPropertyByLookup(isolate, self_obj, key_obj, &lookup);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
// Turns on access checks by copying the map and setting the check flag.
|
|
|
|
// Because the object gets a new map, existing inline cache caching
|
|
|
|
// the old map of this object will fail.
|
|
|
|
void v8::Object::TurnOnAccessCheck() {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
ON_BAILOUT(isolate, "v8::Object::TurnOnAccessCheck()", return);
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// When turning on access checks for a global object deoptimize all functions
|
|
|
|
// as optimized code does not always handle access checks.
|
|
|
|
i::Deoptimizer::DeoptimizeGlobalObject(*obj);
|
|
|
|
|
2014-04-01 17:43:20 +00:00
|
|
|
i::Handle<i::Map> new_map = i::Map::Copy(i::Handle<i::Map>(obj->map()));
|
2008-10-30 12:51:06 +00:00
|
|
|
new_map->set_is_access_check_needed(true);
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
obj->set_map(*new_map);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-17 08:58:06 +00:00
|
|
|
bool v8::Object::IsDirty() {
|
|
|
|
return Utils::OpenHandle(this)->IsDirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-18 19:24:15 +00:00
|
|
|
Local<v8::Object> v8::Object::Clone() {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
ON_BAILOUT(isolate, "v8::Object::Clone()", return Local<Object>());
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2009-03-18 19:24:15 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-29 07:02:11 +00:00
|
|
|
i::Handle<i::JSObject> result = isolate->factory()->CopyJSObject(self);
|
2009-03-18 19:24:15 +00:00
|
|
|
has_pending_exception = result.is_null();
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>());
|
2009-03-18 19:24:15 +00:00
|
|
|
return Utils::ToLocal(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-01 12:17:20 +00:00
|
|
|
Local<v8::Context> v8::Object::CreationContext() {
|
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ON_BAILOUT(isolate,
|
|
|
|
"v8::Object::CreationContext()", return Local<v8::Context>());
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
2014-05-02 13:55:11 +00:00
|
|
|
i::Context* context = self->GetCreationContext();
|
2011-04-01 12:17:20 +00:00
|
|
|
return Utils::ToLocal(i::Handle<i::Context>(context));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-19 18:50:00 +00:00
|
|
|
int v8::Object::GetIdentityHash() {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
ON_BAILOUT(isolate, "v8::Object::GetIdentityHash()", return 0);
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2009-03-19 18:50:00 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
2014-05-09 18:31:08 +00:00
|
|
|
return i::JSReceiver::GetOrCreateIdentityHash(self)->value();
|
2009-03-19 18:50:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool v8::Object::SetHiddenValue(v8::Handle<v8::String> key,
|
|
|
|
v8::Handle<v8::Value> value) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
ON_BAILOUT(isolate, "v8::Object::SetHiddenValue()", return false);
|
2012-08-06 07:55:05 +00:00
|
|
|
if (value.IsEmpty()) return DeleteHiddenValue(key);
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2009-03-19 18:50:00 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
2011-10-04 07:45:25 +00:00
|
|
|
i::Handle<i::String> key_obj = Utils::OpenHandle(*key);
|
2013-02-28 17:03:34 +00:00
|
|
|
i::Handle<i::String> key_string =
|
|
|
|
isolate->factory()->InternalizeString(key_obj);
|
2009-03-19 18:50:00 +00:00
|
|
|
i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
|
2012-01-05 17:16:19 +00:00
|
|
|
i::Handle<i::Object> result =
|
2013-02-28 17:03:34 +00:00
|
|
|
i::JSObject::SetHiddenProperty(self, key_string, value_obj);
|
2011-10-04 07:45:25 +00:00
|
|
|
return *result == *self;
|
2009-03-19 18:50:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
v8::Local<v8::Value> v8::Object::GetHiddenValue(v8::Handle<v8::String> key) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
ON_BAILOUT(isolate, "v8::Object::GetHiddenValue()",
|
|
|
|
return Local<v8::Value>());
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2009-03-19 18:50:00 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::String> key_obj = Utils::OpenHandle(*key);
|
2013-06-04 10:30:05 +00:00
|
|
|
i::Handle<i::String> key_string =
|
|
|
|
isolate->factory()->InternalizeString(key_obj);
|
2014-04-29 13:51:14 +00:00
|
|
|
i::Handle<i::Object> result(self->GetHiddenProperty(key_string), isolate);
|
2013-06-26 08:00:05 +00:00
|
|
|
if (result->IsTheHole()) return v8::Local<v8::Value>();
|
2009-03-19 18:50:00 +00:00
|
|
|
return Utils::ToLocal(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool v8::Object::DeleteHiddenValue(v8::Handle<v8::String> key) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
ON_BAILOUT(isolate, "v8::DeleteHiddenValue()", return false);
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2009-03-19 18:50:00 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::String> key_obj = Utils::OpenHandle(*key);
|
2013-06-04 10:30:05 +00:00
|
|
|
i::Handle<i::String> key_string =
|
|
|
|
isolate->factory()->InternalizeString(key_obj);
|
2013-08-30 13:28:52 +00:00
|
|
|
i::JSObject::DeleteHiddenProperty(self, key_string);
|
2011-10-04 07:45:25 +00:00
|
|
|
return true;
|
2009-03-19 18:50:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-09 15:01:16 +00:00
|
|
|
namespace {
|
|
|
|
|
2011-09-09 14:47:37 +00:00
|
|
|
static i::ElementsKind GetElementsKindFromExternalArrayType(
|
|
|
|
ExternalArrayType array_type) {
|
|
|
|
switch (array_type) {
|
2014-01-24 16:01:15 +00:00
|
|
|
#define ARRAY_TYPE_TO_ELEMENTS_KIND(Type, type, TYPE, ctype, size) \
|
|
|
|
case kExternal##Type##Array: \
|
|
|
|
return i::EXTERNAL_##TYPE##_ELEMENTS;
|
|
|
|
|
|
|
|
TYPED_ARRAYS(ARRAY_TYPE_TO_ELEMENTS_KIND)
|
|
|
|
#undef ARRAY_TYPE_TO_ELEMENTS_KIND
|
2011-09-09 14:47:37 +00:00
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
return i::DICTIONARY_ELEMENTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-09 15:01:16 +00:00
|
|
|
void PrepareExternalArrayElements(i::Handle<i::JSObject> object,
|
|
|
|
void* data,
|
|
|
|
ExternalArrayType array_type,
|
|
|
|
int length) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = object->GetIsolate();
|
2011-03-09 15:01:16 +00:00
|
|
|
i::Handle<i::ExternalArray> array =
|
2011-03-24 18:49:45 +00:00
|
|
|
isolate->factory()->NewExternalArray(length, array_type, data);
|
2011-03-09 15:01:16 +00:00
|
|
|
|
2011-09-15 16:38:47 +00:00
|
|
|
i::Handle<i::Map> external_array_map =
|
2014-03-25 15:33:22 +00:00
|
|
|
i::JSObject::GetElementsTransitionMap(
|
2011-09-15 16:38:47 +00:00
|
|
|
object,
|
|
|
|
GetElementsKindFromExternalArrayType(array_type));
|
|
|
|
|
2014-03-31 16:21:20 +00:00
|
|
|
i::JSObject::SetMapAndElements(object, external_array_map, array);
|
2011-03-09 15:01:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
2009-07-28 08:43:51 +00:00
|
|
|
void v8::Object::SetIndexedPropertiesToPixelData(uint8_t* data, int length) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
ON_BAILOUT(isolate, "v8::SetElementsToPixelData()", return);
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2014-04-04 16:05:29 +00:00
|
|
|
if (!Utils::ApiCheck(length >= 0 &&
|
|
|
|
length <= i::ExternalUint8ClampedArray::kMaxLength,
|
2014-01-13 09:42:23 +00:00
|
|
|
"v8::Object::SetIndexedPropertiesToPixelData()",
|
|
|
|
"length exceeds max acceptable value")) {
|
2009-07-28 08:43:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
2014-01-13 09:42:23 +00:00
|
|
|
if (!Utils::ApiCheck(!self->IsJSArray(),
|
|
|
|
"v8::Object::SetIndexedPropertiesToPixelData()",
|
|
|
|
"JSArray is not supported")) {
|
2009-07-28 08:43:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-01-24 16:01:15 +00:00
|
|
|
PrepareExternalArrayElements(self, data, kExternalUint8ClampedArray, length);
|
2009-07-28 08:43:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-14 13:09:27 +00:00
|
|
|
bool v8::Object::HasIndexedPropertiesInPixelData() {
|
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
2011-03-24 18:49:45 +00:00
|
|
|
ON_BAILOUT(self->GetIsolate(), "v8::HasIndexedPropertiesInPixelData()",
|
|
|
|
return false);
|
2014-01-24 16:01:15 +00:00
|
|
|
return self->HasExternalUint8ClampedElements();
|
2010-06-14 13:09:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t* v8::Object::GetIndexedPropertiesPixelData() {
|
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
2011-03-24 18:49:45 +00:00
|
|
|
ON_BAILOUT(self->GetIsolate(), "v8::GetIndexedPropertiesPixelData()",
|
|
|
|
return NULL);
|
2014-01-24 16:01:15 +00:00
|
|
|
if (self->HasExternalUint8ClampedElements()) {
|
|
|
|
return i::ExternalUint8ClampedArray::cast(self->elements())->
|
|
|
|
external_uint8_clamped_pointer();
|
2010-06-14 13:09:27 +00:00
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int v8::Object::GetIndexedPropertiesPixelDataLength() {
|
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
2011-03-24 18:49:45 +00:00
|
|
|
ON_BAILOUT(self->GetIsolate(), "v8::GetIndexedPropertiesPixelDataLength()",
|
|
|
|
return -1);
|
2014-01-24 16:01:15 +00:00
|
|
|
if (self->HasExternalUint8ClampedElements()) {
|
|
|
|
return i::ExternalUint8ClampedArray::cast(self->elements())->length();
|
2010-06-14 13:09:27 +00:00
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-09 14:47:37 +00:00
|
|
|
|
2009-10-20 15:26:17 +00:00
|
|
|
void v8::Object::SetIndexedPropertiesToExternalArrayData(
|
|
|
|
void* data,
|
|
|
|
ExternalArrayType array_type,
|
|
|
|
int length) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
ON_BAILOUT(isolate, "v8::SetIndexedPropertiesToExternalArrayData()", return);
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2014-04-04 16:05:29 +00:00
|
|
|
if (!Utils::ApiCheck(length >= 0 && length <= i::ExternalArray::kMaxLength,
|
2014-01-13 09:42:23 +00:00
|
|
|
"v8::Object::SetIndexedPropertiesToExternalArrayData()",
|
|
|
|
"length exceeds max acceptable value")) {
|
2009-10-20 15:26:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
2014-01-13 09:42:23 +00:00
|
|
|
if (!Utils::ApiCheck(!self->IsJSArray(),
|
|
|
|
"v8::Object::SetIndexedPropertiesToExternalArrayData()",
|
|
|
|
"JSArray is not supported")) {
|
2009-10-20 15:26:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-03-09 15:01:16 +00:00
|
|
|
PrepareExternalArrayElements(self, data, array_type, length);
|
2009-10-20 15:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-14 13:09:27 +00:00
|
|
|
bool v8::Object::HasIndexedPropertiesInExternalArrayData() {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
|
|
|
ON_BAILOUT(self->GetIsolate(),
|
2011-03-18 20:35:07 +00:00
|
|
|
"v8::HasIndexedPropertiesInExternalArrayData()",
|
|
|
|
return false);
|
2010-06-14 13:09:27 +00:00
|
|
|
return self->HasExternalArrayElements();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void* v8::Object::GetIndexedPropertiesExternalArrayData() {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
|
|
|
ON_BAILOUT(self->GetIsolate(),
|
2011-03-18 20:35:07 +00:00
|
|
|
"v8::GetIndexedPropertiesExternalArrayData()",
|
|
|
|
return NULL);
|
2010-06-14 13:09:27 +00:00
|
|
|
if (self->HasExternalArrayElements()) {
|
|
|
|
return i::ExternalArray::cast(self->elements())->external_pointer();
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ExternalArrayType v8::Object::GetIndexedPropertiesExternalArrayDataType() {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
|
|
|
ON_BAILOUT(self->GetIsolate(),
|
2011-03-18 20:35:07 +00:00
|
|
|
"v8::GetIndexedPropertiesExternalArrayDataType()",
|
2010-06-14 13:09:27 +00:00
|
|
|
return static_cast<ExternalArrayType>(-1));
|
|
|
|
switch (self->elements()->map()->instance_type()) {
|
2014-01-24 16:01:15 +00:00
|
|
|
#define INSTANCE_TYPE_TO_ARRAY_TYPE(Type, type, TYPE, ctype, size) \
|
|
|
|
case i::EXTERNAL_##TYPE##_ARRAY_TYPE: \
|
|
|
|
return kExternal##Type##Array;
|
|
|
|
TYPED_ARRAYS(INSTANCE_TYPE_TO_ARRAY_TYPE)
|
|
|
|
#undef INSTANCE_TYPE_TO_ARRAY_TYPE
|
2010-06-14 13:09:27 +00:00
|
|
|
default:
|
|
|
|
return static_cast<ExternalArrayType>(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int v8::Object::GetIndexedPropertiesExternalArrayDataLength() {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
|
|
|
ON_BAILOUT(self->GetIsolate(),
|
2011-03-18 20:35:07 +00:00
|
|
|
"v8::GetIndexedPropertiesExternalArrayDataLength()",
|
|
|
|
return 0);
|
2010-06-14 13:09:27 +00:00
|
|
|
if (self->HasExternalArrayElements()) {
|
|
|
|
return i::ExternalArray::cast(self->elements())->length();
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-09 15:24:48 +00:00
|
|
|
bool v8::Object::IsCallable() {
|
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ON_BAILOUT(isolate, "v8::Object::IsCallable()", return false);
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
i::HandleScope scope(isolate);
|
|
|
|
i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
|
2013-11-27 17:21:40 +00:00
|
|
|
return obj->IsCallable();
|
2011-05-09 15:24:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-30 11:47:36 +00:00
|
|
|
Local<v8::Value> Object::CallAsFunction(v8::Handle<v8::Value> recv,
|
2011-10-06 09:31:38 +00:00
|
|
|
int argc,
|
2011-05-04 13:03:08 +00:00
|
|
|
v8::Handle<v8::Value> argv[]) {
|
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ON_BAILOUT(isolate, "v8::Object::CallAsFunction()",
|
|
|
|
return Local<v8::Value>());
|
|
|
|
LOG_API(isolate, "Object::CallAsFunction");
|
|
|
|
ENTER_V8(isolate);
|
2012-11-26 08:56:59 +00:00
|
|
|
i::Logger::TimerEventScope timer_scope(
|
|
|
|
isolate, i::Logger::TimerEventScope::v8_execute);
|
2011-05-06 11:07:52 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2011-05-04 13:03:08 +00:00
|
|
|
i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv);
|
|
|
|
STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**));
|
2011-10-06 09:31:38 +00:00
|
|
|
i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
|
2011-05-04 13:03:08 +00:00
|
|
|
i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>();
|
|
|
|
if (obj->IsJSFunction()) {
|
|
|
|
fun = i::Handle<i::JSFunction>::cast(obj);
|
|
|
|
} else {
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
i::Handle<i::Object> delegate;
|
|
|
|
has_pending_exception = !i::Execution::TryGetFunctionDelegate(
|
|
|
|
isolate, obj).ToHandle(&delegate);
|
2011-05-04 13:03:08 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>());
|
|
|
|
fun = i::Handle<i::JSFunction>::cast(delegate);
|
|
|
|
recv_obj = obj;
|
|
|
|
}
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
i::Handle<i::Object> returned;
|
|
|
|
has_pending_exception = !i::Execution::Call(
|
|
|
|
isolate, fun, recv_obj, argc, args, true).ToHandle(&returned);
|
2012-01-04 08:48:35 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Value>());
|
2011-05-06 11:07:52 +00:00
|
|
|
return Utils::ToLocal(scope.CloseAndEscape(returned));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<v8::Value> Object::CallAsConstructor(int argc,
|
|
|
|
v8::Handle<v8::Value> argv[]) {
|
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ON_BAILOUT(isolate, "v8::Object::CallAsConstructor()",
|
|
|
|
return Local<v8::Object>());
|
|
|
|
LOG_API(isolate, "Object::CallAsConstructor");
|
|
|
|
ENTER_V8(isolate);
|
2012-11-26 08:56:59 +00:00
|
|
|
i::Logger::TimerEventScope timer_scope(
|
|
|
|
isolate, i::Logger::TimerEventScope::v8_execute);
|
2011-05-06 11:07:52 +00:00
|
|
|
i::HandleScope scope(isolate);
|
|
|
|
i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
|
|
|
|
STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**));
|
2011-10-06 09:31:38 +00:00
|
|
|
i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
|
2011-05-06 11:07:52 +00:00
|
|
|
if (obj->IsJSFunction()) {
|
|
|
|
i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(obj);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
i::Handle<i::Object> returned;
|
|
|
|
has_pending_exception = !i::Execution::New(
|
|
|
|
fun, argc, args).ToHandle(&returned);
|
2012-01-04 08:48:35 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<v8::Object>());
|
2011-05-06 11:07:52 +00:00
|
|
|
return Utils::ToLocal(scope.CloseAndEscape(
|
|
|
|
i::Handle<i::JSObject>::cast(returned)));
|
|
|
|
}
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
i::Handle<i::Object> delegate;
|
|
|
|
has_pending_exception = !i::Execution::TryGetConstructorDelegate(
|
|
|
|
isolate, obj).ToHandle(&delegate);
|
2011-05-06 11:07:52 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>());
|
|
|
|
if (!delegate->IsUndefined()) {
|
|
|
|
i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(delegate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
i::Handle<i::Object> returned;
|
|
|
|
has_pending_exception = !i::Execution::Call(
|
|
|
|
isolate, fun, obj, argc, args).ToHandle(&returned);
|
2012-01-04 08:48:35 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<v8::Object>());
|
2011-05-06 11:07:52 +00:00
|
|
|
ASSERT(!delegate->IsUndefined());
|
|
|
|
return Utils::ToLocal(scope.CloseAndEscape(returned));
|
|
|
|
}
|
|
|
|
return Local<v8::Object>();
|
2011-05-04 13:03:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-09 07:52:52 +00:00
|
|
|
Local<Function> Function::New(Isolate* v8_isolate,
|
|
|
|
FunctionCallback callback,
|
|
|
|
Local<Value> data,
|
|
|
|
int length) {
|
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
|
|
|
|
LOG_API(isolate, "Function::New");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
return FunctionTemplateNew(
|
|
|
|
isolate, callback, data, Local<Signature>(), length, true)->
|
2014-01-13 09:42:23 +00:00
|
|
|
GetFunction();
|
2013-09-09 07:52:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
Local<v8::Object> Function::NewInstance() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
return NewInstance(0, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<v8::Object> Function::NewInstance(int argc,
|
2009-01-08 11:35:34 +00:00
|
|
|
v8::Handle<v8::Value> argv[]) const {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
ON_BAILOUT(isolate, "v8::Function::NewInstance()",
|
|
|
|
return Local<v8::Object>());
|
|
|
|
LOG_API(isolate, "Function::NewInstance");
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2012-11-26 08:56:59 +00:00
|
|
|
i::Logger::TimerEventScope timer_scope(
|
|
|
|
isolate, i::Logger::TimerEventScope::v8_execute);
|
2013-12-02 18:12:01 +00:00
|
|
|
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::JSFunction> function = Utils::OpenHandle(this);
|
|
|
|
STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**));
|
2011-10-06 09:31:38 +00:00
|
|
|
i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
i::Handle<i::Object> returned;
|
|
|
|
has_pending_exception = !i::Execution::New(
|
|
|
|
function, argc, args).ToHandle(&returned);
|
2012-01-04 08:48:35 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<v8::Object>());
|
2013-12-02 18:12:01 +00:00
|
|
|
return scope.Escape(Utils::ToLocal(i::Handle<i::JSObject>::cast(returned)));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-30 11:47:36 +00:00
|
|
|
Local<v8::Value> Function::Call(v8::Handle<v8::Value> recv, int argc,
|
2008-07-03 15:10:15 +00:00
|
|
|
v8::Handle<v8::Value> argv[]) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
ON_BAILOUT(isolate, "v8::Function::Call()", return Local<v8::Value>());
|
|
|
|
LOG_API(isolate, "Function::Call");
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2012-11-26 08:56:59 +00:00
|
|
|
i::Logger::TimerEventScope timer_scope(
|
|
|
|
isolate, i::Logger::TimerEventScope::v8_execute);
|
2014-04-11 10:41:09 +00:00
|
|
|
i::HandleScope scope(isolate);
|
|
|
|
i::Handle<i::JSFunction> fun = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv);
|
|
|
|
STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**));
|
|
|
|
i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
|
|
|
i::Handle<i::Object> returned;
|
|
|
|
has_pending_exception = !i::Execution::Call(
|
|
|
|
isolate, fun, recv_obj, argc, args, true).ToHandle(&returned);
|
|
|
|
EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Object>());
|
|
|
|
return Utils::ToLocal(scope.CloseAndEscape(returned));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Function::SetName(v8::Handle<v8::String> name) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ENTER_V8(isolate);
|
2011-05-30 14:33:23 +00:00
|
|
|
USE(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
|
|
|
|
func->shared()->set_name(*Utils::OpenHandle(*name));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
Handle<Value> Function::GetName() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
|
2013-02-25 14:46:09 +00:00
|
|
|
return Utils::ToLocal(i::Handle<i::Object>(func->shared()->name(),
|
|
|
|
func->GetIsolate()));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-25 12:45:54 +00:00
|
|
|
Handle<Value> Function::GetInferredName() const {
|
|
|
|
i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
|
2013-02-25 14:46:09 +00:00
|
|
|
return Utils::ToLocal(i::Handle<i::Object>(func->shared()->inferred_name(),
|
|
|
|
func->GetIsolate()));
|
2012-01-25 12:45:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-23 12:38:06 +00:00
|
|
|
Handle<Value> Function::GetDisplayName() const {
|
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ON_BAILOUT(isolate, "v8::Function::GetDisplayName()",
|
|
|
|
return ToApiHandle<Primitive>(
|
2014-01-13 09:42:23 +00:00
|
|
|
isolate->factory()->undefined_value()));
|
2013-10-23 12:38:06 +00:00
|
|
|
ENTER_V8(isolate);
|
|
|
|
i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::String> property_name =
|
|
|
|
isolate->factory()->InternalizeOneByteString(
|
|
|
|
STATIC_ASCII_VECTOR("displayName"));
|
|
|
|
i::LookupResult lookup(isolate);
|
2014-04-29 13:43:17 +00:00
|
|
|
func->LookupRealNamedProperty(property_name, &lookup);
|
2013-10-23 12:38:06 +00:00
|
|
|
if (lookup.IsFound()) {
|
|
|
|
i::Object* value = lookup.GetLazyValue();
|
|
|
|
if (value && value->IsString()) {
|
|
|
|
i::String* name = i::String::cast(value);
|
|
|
|
if (name->length() > 0) return Utils::ToLocal(i::Handle<i::String>(name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ToApiHandle<Primitive>(isolate->factory()->undefined_value());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-15 14:19:15 +00:00
|
|
|
ScriptOrigin Function::GetScriptOrigin() const {
|
|
|
|
i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
|
|
|
|
if (func->shared()->script()->IsScript()) {
|
|
|
|
i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
|
2014-04-16 13:28:11 +00:00
|
|
|
i::Handle<i::Object> scriptName = i::Script::GetNameOrSourceURL(script);
|
2014-01-03 14:31:17 +00:00
|
|
|
v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(func->GetIsolate());
|
2010-02-15 14:19:15 +00:00
|
|
|
v8::ScriptOrigin origin(
|
2014-01-13 09:42:23 +00:00
|
|
|
Utils::ToLocal(scriptName),
|
|
|
|
v8::Integer::New(isolate, script->line_offset()->value()),
|
|
|
|
v8::Integer::New(isolate, script->column_offset()->value()));
|
2010-02-15 14:19:15 +00:00
|
|
|
return origin;
|
|
|
|
}
|
|
|
|
return v8::ScriptOrigin(Handle<Value>());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const int Function::kLineOffsetNotFound = -1;
|
|
|
|
|
|
|
|
|
|
|
|
int Function::GetScriptLineNumber() const {
|
|
|
|
i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
|
|
|
|
if (func->shared()->script()->IsScript()) {
|
|
|
|
i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
|
2014-04-16 13:28:11 +00:00
|
|
|
return i::Script::GetLineNumber(script, func->shared()->start_position());
|
2010-02-15 14:19:15 +00:00
|
|
|
}
|
|
|
|
return kLineOffsetNotFound;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-09 14:18:30 +00:00
|
|
|
int Function::GetScriptColumnNumber() const {
|
|
|
|
i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
|
|
|
|
if (func->shared()->script()->IsScript()) {
|
|
|
|
i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
|
2014-04-16 13:28:11 +00:00
|
|
|
return i::Script::GetColumnNumber(script, func->shared()->start_position());
|
2011-11-09 14:18:30 +00:00
|
|
|
}
|
|
|
|
return kLineOffsetNotFound;
|
|
|
|
}
|
|
|
|
|
2013-06-25 14:57:47 +00:00
|
|
|
|
2013-10-22 14:50:20 +00:00
|
|
|
bool Function::IsBuiltin() const {
|
|
|
|
i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
|
|
|
|
return func->IsBuiltin();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-25 14:57:47 +00:00
|
|
|
int Function::ScriptId() const {
|
|
|
|
i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
|
2014-03-14 10:20:33 +00:00
|
|
|
if (!func->shared()->script()->IsScript()) {
|
|
|
|
return v8::UnboundScript::kNoScriptId;
|
|
|
|
}
|
2013-06-25 14:57:47 +00:00
|
|
|
i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
|
|
|
|
return script->id()->value();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-23 08:04:54 +00:00
|
|
|
Local<v8::Value> Function::GetBoundFunction() const {
|
|
|
|
i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
|
|
|
|
if (!func->shared()->bound()) {
|
|
|
|
return v8::Undefined(reinterpret_cast<v8::Isolate*>(func->GetIsolate()));
|
|
|
|
}
|
|
|
|
i::Handle<i::FixedArray> bound_args = i::Handle<i::FixedArray>(
|
|
|
|
i::FixedArray::cast(func->function_bindings()));
|
|
|
|
i::Handle<i::Object> original(
|
|
|
|
bound_args->get(i::JSFunction::kBoundFunctionIndex),
|
|
|
|
func->GetIsolate());
|
|
|
|
return Utils::ToLocal(i::Handle<i::JSFunction>::cast(original));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
int String::Length() const {
|
2011-03-28 08:44:30 +00:00
|
|
|
i::Handle<i::String> str = Utils::OpenHandle(this);
|
|
|
|
return str->length();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2013-01-03 12:59:54 +00:00
|
|
|
|
2013-01-14 11:22:05 +00:00
|
|
|
bool String::IsOneByte() const {
|
|
|
|
i::Handle<i::String> str = Utils::OpenHandle(this);
|
2013-04-26 14:08:18 +00:00
|
|
|
return str->HasOnlyOneByteChars();
|
2013-01-14 11:22:05 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2013-06-10 07:56:17 +00:00
|
|
|
// Helpers for ContainsOnlyOneByteHelper
|
|
|
|
template<size_t size> struct OneByteMask;
|
|
|
|
template<> struct OneByteMask<4> {
|
|
|
|
static const uint32_t value = 0xFF00FF00;
|
|
|
|
};
|
|
|
|
template<> struct OneByteMask<8> {
|
2013-06-10 08:19:03 +00:00
|
|
|
static const uint64_t value = V8_2PART_UINT64_C(0xFF00FF00, FF00FF00);
|
2013-06-10 07:56:17 +00:00
|
|
|
};
|
|
|
|
static const uintptr_t kOneByteMask = OneByteMask<sizeof(uintptr_t)>::value;
|
|
|
|
static const uintptr_t kAlignmentMask = sizeof(uintptr_t) - 1;
|
|
|
|
static inline bool Unaligned(const uint16_t* chars) {
|
|
|
|
return reinterpret_cast<const uintptr_t>(chars) & kAlignmentMask;
|
|
|
|
}
|
2013-07-05 09:52:11 +00:00
|
|
|
|
|
|
|
|
2013-06-10 07:56:17 +00:00
|
|
|
static inline const uint16_t* Align(const uint16_t* chars) {
|
|
|
|
return reinterpret_cast<uint16_t*>(
|
2014-01-13 09:42:23 +00:00
|
|
|
reinterpret_cast<uintptr_t>(chars) & ~kAlignmentMask);
|
2013-06-10 07:56:17 +00:00
|
|
|
}
|
2013-01-14 11:22:05 +00:00
|
|
|
|
2013-06-06 13:16:52 +00:00
|
|
|
class ContainsOnlyOneByteHelper {
|
|
|
|
public:
|
|
|
|
ContainsOnlyOneByteHelper() : is_one_byte_(true) {}
|
|
|
|
bool Check(i::String* string) {
|
|
|
|
i::ConsString* cons_string = i::String::VisitFlat(this, string, 0);
|
|
|
|
if (cons_string == NULL) return is_one_byte_;
|
|
|
|
return CheckCons(cons_string);
|
|
|
|
}
|
|
|
|
void VisitOneByteString(const uint8_t* chars, int length) {
|
|
|
|
// Nothing to do.
|
|
|
|
}
|
|
|
|
void VisitTwoByteString(const uint16_t* chars, int length) {
|
2013-06-10 07:34:58 +00:00
|
|
|
// Accumulated bits.
|
|
|
|
uintptr_t acc = 0;
|
|
|
|
// Align to uintptr_t.
|
|
|
|
const uint16_t* end = chars + length;
|
|
|
|
while (Unaligned(chars) && chars != end) {
|
2014-01-13 09:42:23 +00:00
|
|
|
acc |= *chars++;
|
2013-06-06 13:16:52 +00:00
|
|
|
}
|
2013-06-10 07:34:58 +00:00
|
|
|
// Read word aligned in blocks,
|
|
|
|
// checking the return value at the end of each block.
|
|
|
|
const uint16_t* aligned_end = Align(end);
|
|
|
|
const int increment = sizeof(uintptr_t)/sizeof(uint16_t);
|
|
|
|
const int inner_loops = 16;
|
|
|
|
while (chars + inner_loops*increment < aligned_end) {
|
|
|
|
for (int i = 0; i < inner_loops; i++) {
|
|
|
|
acc |= *reinterpret_cast<const uintptr_t*>(chars);
|
|
|
|
chars += increment;
|
|
|
|
}
|
|
|
|
// Check for early return.
|
|
|
|
if ((acc & kOneByteMask) != 0) {
|
|
|
|
is_one_byte_ = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Read the rest.
|
|
|
|
while (chars != end) {
|
|
|
|
acc |= *chars++;
|
|
|
|
}
|
|
|
|
// Check result.
|
|
|
|
if ((acc & kOneByteMask) != 0) is_one_byte_ = false;
|
2013-06-06 13:16:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool CheckCons(i::ConsString* cons_string) {
|
|
|
|
while (true) {
|
|
|
|
// Check left side if flat.
|
|
|
|
i::String* left = cons_string->first();
|
|
|
|
i::ConsString* left_as_cons =
|
|
|
|
i::String::VisitFlat(this, left, 0);
|
|
|
|
if (!is_one_byte_) return false;
|
|
|
|
// Check right side if flat.
|
|
|
|
i::String* right = cons_string->second();
|
|
|
|
i::ConsString* right_as_cons =
|
|
|
|
i::String::VisitFlat(this, right, 0);
|
|
|
|
if (!is_one_byte_) return false;
|
|
|
|
// Standard recurse/iterate trick.
|
|
|
|
if (left_as_cons != NULL && right_as_cons != NULL) {
|
|
|
|
if (left->length() < right->length()) {
|
|
|
|
CheckCons(left_as_cons);
|
|
|
|
cons_string = right_as_cons;
|
|
|
|
} else {
|
|
|
|
CheckCons(right_as_cons);
|
|
|
|
cons_string = left_as_cons;
|
|
|
|
}
|
|
|
|
// Check fast return.
|
|
|
|
if (!is_one_byte_) return false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Descend left in place.
|
|
|
|
if (left_as_cons != NULL) {
|
|
|
|
cons_string = left_as_cons;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Descend right in place.
|
|
|
|
if (right_as_cons != NULL) {
|
|
|
|
cons_string = right_as_cons;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Terminate.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return is_one_byte_;
|
|
|
|
}
|
|
|
|
bool is_one_byte_;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ContainsOnlyOneByteHelper);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
bool String::ContainsOnlyOneByte() const {
|
|
|
|
i::Handle<i::String> str = Utils::OpenHandle(this);
|
|
|
|
if (str->HasOnlyOneByteChars()) return true;
|
|
|
|
ContainsOnlyOneByteHelper helper;
|
|
|
|
return helper.Check(*str);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-06 15:39:57 +00:00
|
|
|
class Utf8LengthHelper : public i::AllStatic {
|
2013-01-03 12:59:54 +00:00
|
|
|
public:
|
2013-03-06 15:39:57 +00:00
|
|
|
enum State {
|
|
|
|
kEndsWithLeadingSurrogate = 1 << 0,
|
|
|
|
kStartsWithTrailingSurrogate = 1 << 1,
|
|
|
|
kLeftmostEdgeIsCalculated = 1 << 2,
|
|
|
|
kRightmostEdgeIsCalculated = 1 << 3,
|
|
|
|
kLeftmostEdgeIsSurrogate = 1 << 4,
|
|
|
|
kRightmostEdgeIsSurrogate = 1 << 5
|
|
|
|
};
|
|
|
|
|
|
|
|
static const uint8_t kInitialState = 0;
|
|
|
|
|
|
|
|
static inline bool EndsWithSurrogate(uint8_t state) {
|
|
|
|
return state & kEndsWithLeadingSurrogate;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool StartsWithSurrogate(uint8_t state) {
|
|
|
|
return state & kStartsWithTrailingSurrogate;
|
|
|
|
}
|
|
|
|
|
|
|
|
class Visitor {
|
|
|
|
public:
|
2013-03-13 19:43:45 +00:00
|
|
|
inline explicit Visitor()
|
2014-01-13 09:42:23 +00:00
|
|
|
: utf8_length_(0),
|
|
|
|
state_(kInitialState) {}
|
2013-03-06 15:39:57 +00:00
|
|
|
|
2013-03-13 19:43:45 +00:00
|
|
|
void VisitOneByteString(const uint8_t* chars, int length) {
|
2013-03-06 15:39:57 +00:00
|
|
|
int utf8_length = 0;
|
2013-03-13 19:43:45 +00:00
|
|
|
// Add in length 1 for each non-ASCII character.
|
2013-03-06 15:39:57 +00:00
|
|
|
for (int i = 0; i < length; i++) {
|
2013-03-13 19:43:45 +00:00
|
|
|
utf8_length += *chars++ >> 7;
|
2013-03-06 15:39:57 +00:00
|
|
|
}
|
2013-03-13 19:43:45 +00:00
|
|
|
// Add in length 1 for each character.
|
|
|
|
utf8_length_ = utf8_length + length;
|
2013-03-06 15:39:57 +00:00
|
|
|
state_ = kInitialState;
|
|
|
|
}
|
2013-01-03 12:59:54 +00:00
|
|
|
|
2013-03-06 15:39:57 +00:00
|
|
|
void VisitTwoByteString(const uint16_t* chars, int length) {
|
2013-03-13 19:43:45 +00:00
|
|
|
int utf8_length = 0;
|
|
|
|
int last_character = unibrow::Utf16::kNoPreviousCharacter;
|
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
uint16_t c = chars[i];
|
|
|
|
utf8_length += unibrow::Utf8::Length(c, last_character);
|
|
|
|
last_character = c;
|
|
|
|
}
|
|
|
|
utf8_length_ = utf8_length;
|
2013-03-06 15:39:57 +00:00
|
|
|
uint8_t state = 0;
|
|
|
|
if (unibrow::Utf16::IsTrailSurrogate(chars[0])) {
|
|
|
|
state |= kStartsWithTrailingSurrogate;
|
|
|
|
}
|
|
|
|
if (unibrow::Utf16::IsLeadSurrogate(chars[length-1])) {
|
|
|
|
state |= kEndsWithLeadingSurrogate;
|
|
|
|
}
|
|
|
|
state_ = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
static i::ConsString* VisitFlat(i::String* string,
|
|
|
|
int* length,
|
|
|
|
uint8_t* state) {
|
|
|
|
Visitor visitor;
|
|
|
|
i::ConsString* cons_string = i::String::VisitFlat(&visitor, string);
|
|
|
|
*length = visitor.utf8_length_;
|
|
|
|
*state = visitor.state_;
|
|
|
|
return cons_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int utf8_length_;
|
|
|
|
uint8_t state_;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(Visitor);
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline void MergeLeafLeft(int* length,
|
|
|
|
uint8_t* state,
|
|
|
|
uint8_t leaf_state) {
|
|
|
|
bool edge_surrogate = StartsWithSurrogate(leaf_state);
|
|
|
|
if (!(*state & kLeftmostEdgeIsCalculated)) {
|
|
|
|
ASSERT(!(*state & kLeftmostEdgeIsSurrogate));
|
|
|
|
*state |= kLeftmostEdgeIsCalculated
|
|
|
|
| (edge_surrogate ? kLeftmostEdgeIsSurrogate : 0);
|
|
|
|
} else if (EndsWithSurrogate(*state) && edge_surrogate) {
|
|
|
|
*length -= unibrow::Utf8::kBytesSavedByCombiningSurrogates;
|
|
|
|
}
|
|
|
|
if (EndsWithSurrogate(leaf_state)) {
|
|
|
|
*state |= kEndsWithLeadingSurrogate;
|
|
|
|
} else {
|
|
|
|
*state &= ~kEndsWithLeadingSurrogate;
|
|
|
|
}
|
2013-01-03 12:59:54 +00:00
|
|
|
}
|
|
|
|
|
2013-03-06 15:39:57 +00:00
|
|
|
static inline void MergeLeafRight(int* length,
|
|
|
|
uint8_t* state,
|
|
|
|
uint8_t leaf_state) {
|
|
|
|
bool edge_surrogate = EndsWithSurrogate(leaf_state);
|
|
|
|
if (!(*state & kRightmostEdgeIsCalculated)) {
|
|
|
|
ASSERT(!(*state & kRightmostEdgeIsSurrogate));
|
|
|
|
*state |= (kRightmostEdgeIsCalculated
|
2014-01-13 09:42:23 +00:00
|
|
|
| (edge_surrogate ? kRightmostEdgeIsSurrogate : 0));
|
2013-03-06 15:39:57 +00:00
|
|
|
} else if (edge_surrogate && StartsWithSurrogate(*state)) {
|
|
|
|
*length -= unibrow::Utf8::kBytesSavedByCombiningSurrogates;
|
|
|
|
}
|
|
|
|
if (StartsWithSurrogate(leaf_state)) {
|
|
|
|
*state |= kStartsWithTrailingSurrogate;
|
|
|
|
} else {
|
|
|
|
*state &= ~kStartsWithTrailingSurrogate;
|
2013-01-03 12:59:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-06 15:39:57 +00:00
|
|
|
static inline void MergeTerminal(int* length,
|
|
|
|
uint8_t state,
|
|
|
|
uint8_t* state_out) {
|
|
|
|
ASSERT((state & kLeftmostEdgeIsCalculated) &&
|
|
|
|
(state & kRightmostEdgeIsCalculated));
|
|
|
|
if (EndsWithSurrogate(state) && StartsWithSurrogate(state)) {
|
|
|
|
*length -= unibrow::Utf8::kBytesSavedByCombiningSurrogates;
|
|
|
|
}
|
|
|
|
*state_out = kInitialState |
|
|
|
|
(state & kLeftmostEdgeIsSurrogate ? kStartsWithTrailingSurrogate : 0) |
|
|
|
|
(state & kRightmostEdgeIsSurrogate ? kEndsWithLeadingSurrogate : 0);
|
2013-01-03 12:59:54 +00:00
|
|
|
}
|
|
|
|
|
2013-03-06 15:39:57 +00:00
|
|
|
static int Calculate(i::ConsString* current, uint8_t* state_out) {
|
|
|
|
using namespace internal;
|
|
|
|
int total_length = 0;
|
|
|
|
uint8_t state = kInitialState;
|
|
|
|
while (true) {
|
|
|
|
i::String* left = current->first();
|
|
|
|
i::String* right = current->second();
|
|
|
|
uint8_t right_leaf_state;
|
|
|
|
uint8_t left_leaf_state;
|
|
|
|
int leaf_length;
|
|
|
|
ConsString* left_as_cons =
|
|
|
|
Visitor::VisitFlat(left, &leaf_length, &left_leaf_state);
|
|
|
|
if (left_as_cons == NULL) {
|
|
|
|
total_length += leaf_length;
|
|
|
|
MergeLeafLeft(&total_length, &state, left_leaf_state);
|
|
|
|
}
|
|
|
|
ConsString* right_as_cons =
|
|
|
|
Visitor::VisitFlat(right, &leaf_length, &right_leaf_state);
|
|
|
|
if (right_as_cons == NULL) {
|
|
|
|
total_length += leaf_length;
|
|
|
|
MergeLeafRight(&total_length, &state, right_leaf_state);
|
2013-03-13 19:43:45 +00:00
|
|
|
if (left_as_cons != NULL) {
|
|
|
|
// 1 Leaf node. Descend in place.
|
2013-03-06 15:39:57 +00:00
|
|
|
current = left_as_cons;
|
|
|
|
continue;
|
2013-03-13 19:43:45 +00:00
|
|
|
} else {
|
|
|
|
// Terminal node.
|
|
|
|
MergeTerminal(&total_length, state, state_out);
|
|
|
|
return total_length;
|
2013-03-06 15:39:57 +00:00
|
|
|
}
|
2013-03-13 19:43:45 +00:00
|
|
|
} else if (left_as_cons == NULL) {
|
|
|
|
// 1 Leaf node. Descend in place.
|
|
|
|
current = right_as_cons;
|
|
|
|
continue;
|
2013-03-06 15:39:57 +00:00
|
|
|
}
|
2013-03-13 19:43:45 +00:00
|
|
|
// Both strings are ConsStrings.
|
|
|
|
// Recurse on smallest.
|
|
|
|
if (left->length() < right->length()) {
|
|
|
|
total_length += Calculate(left_as_cons, &left_leaf_state);
|
|
|
|
MergeLeafLeft(&total_length, &state, left_leaf_state);
|
2013-03-06 15:39:57 +00:00
|
|
|
current = right_as_cons;
|
2013-03-13 19:43:45 +00:00
|
|
|
} else {
|
|
|
|
total_length += Calculate(right_as_cons, &right_leaf_state);
|
|
|
|
MergeLeafRight(&total_length, &state, right_leaf_state);
|
|
|
|
current = left_as_cons;
|
2013-03-06 15:39:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int Calculate(i::ConsString* current) {
|
|
|
|
uint8_t state = kInitialState;
|
|
|
|
return Calculate(current, &state);
|
2013-01-03 12:59:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-03-06 15:39:57 +00:00
|
|
|
DISALLOW_IMPLICIT_CONSTRUCTORS(Utf8LengthHelper);
|
2013-01-03 12:59:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int Utf8Length(i::String* str, i::Isolate* isolate) {
|
2013-03-06 15:39:57 +00:00
|
|
|
int length = str->length();
|
2013-01-03 12:59:54 +00:00
|
|
|
if (length == 0) return 0;
|
2013-03-06 15:39:57 +00:00
|
|
|
uint8_t state;
|
|
|
|
i::ConsString* cons_string =
|
|
|
|
Utf8LengthHelper::Visitor::VisitFlat(str, &length, &state);
|
|
|
|
if (cons_string == NULL) return length;
|
|
|
|
return Utf8LengthHelper::Calculate(cons_string);
|
2013-01-03 12:59:54 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
int String::Utf8Length() const {
|
2011-03-28 08:44:30 +00:00
|
|
|
i::Handle<i::String> str = Utils::OpenHandle(this);
|
2013-01-03 12:59:54 +00:00
|
|
|
i::Isolate* isolate = str->GetIsolate();
|
|
|
|
return v8::Utf8Length(*str, isolate);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class Utf8WriterVisitor {
|
|
|
|
public:
|
2013-03-06 15:39:57 +00:00
|
|
|
Utf8WriterVisitor(
|
2014-01-20 09:52:54 +00:00
|
|
|
char* buffer,
|
|
|
|
int capacity,
|
|
|
|
bool skip_capacity_check,
|
|
|
|
bool replace_invalid_utf8)
|
|
|
|
: early_termination_(false),
|
|
|
|
last_character_(unibrow::Utf16::kNoPreviousCharacter),
|
|
|
|
buffer_(buffer),
|
|
|
|
start_(buffer),
|
|
|
|
capacity_(capacity),
|
|
|
|
skip_capacity_check_(capacity == -1 || skip_capacity_check),
|
|
|
|
replace_invalid_utf8_(replace_invalid_utf8),
|
|
|
|
utf16_chars_read_(0) {
|
2013-01-03 12:59:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int WriteEndCharacter(uint16_t character,
|
|
|
|
int last_character,
|
|
|
|
int remaining,
|
2014-01-20 09:52:54 +00:00
|
|
|
char* const buffer,
|
|
|
|
bool replace_invalid_utf8) {
|
2013-01-03 12:59:54 +00:00
|
|
|
using namespace unibrow;
|
|
|
|
ASSERT(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.
|
2014-01-20 09:52:54 +00:00
|
|
|
if (Utf16::IsSurrogatePair(last_character, character)) {
|
|
|
|
int written = Utf8::Encode(buffer,
|
|
|
|
character,
|
|
|
|
last_character,
|
|
|
|
replace_invalid_utf8);
|
2013-01-03 12:59:54 +00:00
|
|
|
ASSERT(written == 1);
|
|
|
|
return written;
|
2012-03-21 13:48:29 +00:00
|
|
|
}
|
2013-01-03 12:59:54 +00:00
|
|
|
// Use a scratch buffer to check the required characters.
|
|
|
|
char temp_buffer[Utf8::kMaxEncodedSize];
|
|
|
|
// Can't encode using last_character as gcc has array bounds issues.
|
|
|
|
int written = Utf8::Encode(temp_buffer,
|
|
|
|
character,
|
2014-01-20 09:52:54 +00:00
|
|
|
Utf16::kNoPreviousCharacter,
|
|
|
|
replace_invalid_utf8);
|
2013-01-03 12:59:54 +00:00
|
|
|
// Won't fit.
|
|
|
|
if (written > remaining) return 0;
|
|
|
|
// Copy over the character from temp_buffer.
|
|
|
|
for (int j = 0; j < written; j++) {
|
|
|
|
buffer[j] = temp_buffer[j];
|
|
|
|
}
|
|
|
|
return written;
|
|
|
|
}
|
|
|
|
|
2014-01-20 09:52:54 +00:00
|
|
|
// Visit writes out a group of code units (chars) of a v8::String to the
|
|
|
|
// internal buffer_. This is done in two phases. The first phase calculates a
|
|
|
|
// pesimistic estimate (writable_length) on how many code units can be safely
|
|
|
|
// written without exceeding the buffer capacity and without writing the last
|
|
|
|
// code unit (it could be a lead surrogate). The estimated number of code
|
|
|
|
// units is then written out in one go, and the reported byte usage is used
|
|
|
|
// to correct the estimate. This is repeated until the estimate becomes <= 0
|
|
|
|
// or all code units have been written out. The second phase writes out code
|
|
|
|
// units until the buffer capacity is reached, would be exceeded by the next
|
|
|
|
// unit, or all units have been written out.
|
2013-01-03 12:59:54 +00:00
|
|
|
template<typename Char>
|
|
|
|
void Visit(const Char* chars, const int length) {
|
|
|
|
using namespace unibrow;
|
|
|
|
ASSERT(!early_termination_);
|
2013-03-06 15:39:57 +00:00
|
|
|
if (length == 0) return;
|
2013-01-03 12:59:54 +00:00
|
|
|
// Copy state to stack.
|
|
|
|
char* buffer = buffer_;
|
2013-03-06 15:39:57 +00:00
|
|
|
int last_character =
|
|
|
|
sizeof(Char) == 1 ? Utf16::kNoPreviousCharacter : last_character_;
|
2013-01-03 12:59:54 +00:00
|
|
|
int i = 0;
|
|
|
|
// Do a fast loop where there is no exit capacity check.
|
|
|
|
while (true) {
|
|
|
|
int fast_length;
|
2013-03-06 15:39:57 +00:00
|
|
|
if (skip_capacity_check_) {
|
2013-01-03 12:59:54 +00:00
|
|
|
fast_length = length;
|
|
|
|
} else {
|
2013-01-03 13:16:00 +00:00
|
|
|
int remaining_capacity = capacity_ - static_cast<int>(buffer - start_);
|
2013-01-03 12:59:54 +00:00
|
|
|
// Need enough space to write everything but one character.
|
|
|
|
STATIC_ASSERT(Utf16::kMaxExtraUtf8BytesForOneUtf16CodeUnit == 3);
|
2013-03-06 15:39:57 +00:00
|
|
|
int max_size_per_char = sizeof(Char) == 1 ? 2 : 3;
|
|
|
|
int writable_length =
|
|
|
|
(remaining_capacity - max_size_per_char)/max_size_per_char;
|
2013-01-03 12:59:54 +00:00
|
|
|
// Need to drop into slow loop.
|
|
|
|
if (writable_length <= 0) break;
|
|
|
|
fast_length = i + writable_length;
|
|
|
|
if (fast_length > length) fast_length = length;
|
2012-03-21 13:48:29 +00:00
|
|
|
}
|
2013-01-03 12:59:54 +00:00
|
|
|
// Write the characters to the stream.
|
2013-03-06 15:39:57 +00:00
|
|
|
if (sizeof(Char) == 1) {
|
|
|
|
for (; i < fast_length; i++) {
|
|
|
|
buffer +=
|
2013-03-13 19:43:45 +00:00
|
|
|
Utf8::EncodeOneByte(buffer, static_cast<uint8_t>(*chars++));
|
2013-03-06 15:39:57 +00:00
|
|
|
ASSERT(capacity_ == -1 || (buffer - start_) <= capacity_);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (; i < fast_length; i++) {
|
|
|
|
uint16_t character = *chars++;
|
2014-01-20 09:52:54 +00:00
|
|
|
buffer += Utf8::Encode(buffer,
|
|
|
|
character,
|
|
|
|
last_character,
|
|
|
|
replace_invalid_utf8_);
|
2013-03-06 15:39:57 +00:00
|
|
|
last_character = character;
|
|
|
|
ASSERT(capacity_ == -1 || (buffer - start_) <= capacity_);
|
|
|
|
}
|
2012-03-21 13:48:29 +00:00
|
|
|
}
|
2013-01-03 12:59:54 +00:00
|
|
|
// Array is fully written. Exit.
|
|
|
|
if (fast_length == length) {
|
|
|
|
// Write state back out to object.
|
|
|
|
last_character_ = last_character;
|
|
|
|
buffer_ = buffer;
|
2013-03-06 15:39:57 +00:00
|
|
|
utf16_chars_read_ += length;
|
2013-01-03 12:59:54 +00:00
|
|
|
return;
|
2012-03-21 13:48:29 +00:00
|
|
|
}
|
2013-01-03 12:59:54 +00:00
|
|
|
}
|
2013-03-06 15:39:57 +00:00
|
|
|
ASSERT(!skip_capacity_check_);
|
2013-01-03 12:59:54 +00:00
|
|
|
// Slow loop. Must check capacity on each iteration.
|
2013-01-03 13:16:00 +00:00
|
|
|
int remaining_capacity = capacity_ - static_cast<int>(buffer - start_);
|
2013-01-03 12:59:54 +00:00
|
|
|
ASSERT(remaining_capacity >= 0);
|
|
|
|
for (; i < length && remaining_capacity > 0; i++) {
|
|
|
|
uint16_t character = *chars++;
|
2014-01-20 09:52:54 +00:00
|
|
|
// remaining_capacity is <= 3 bytes at this point, so we do not write out
|
|
|
|
// an umatched lead surrogate.
|
|
|
|
if (replace_invalid_utf8_ && Utf16::IsLeadSurrogate(character)) {
|
|
|
|
early_termination_ = true;
|
|
|
|
break;
|
|
|
|
}
|
2013-01-03 12:59:54 +00:00
|
|
|
int written = WriteEndCharacter(character,
|
|
|
|
last_character,
|
|
|
|
remaining_capacity,
|
2014-01-20 09:52:54 +00:00
|
|
|
buffer,
|
|
|
|
replace_invalid_utf8_);
|
2013-01-03 12:59:54 +00:00
|
|
|
if (written == 0) {
|
|
|
|
early_termination_ = true;
|
|
|
|
break;
|
2012-03-21 13:48:29 +00:00
|
|
|
}
|
2013-01-03 12:59:54 +00:00
|
|
|
buffer += written;
|
|
|
|
remaining_capacity -= written;
|
|
|
|
last_character = character;
|
2012-03-21 13:48:29 +00:00
|
|
|
}
|
2013-01-03 12:59:54 +00:00
|
|
|
// Write state back out to object.
|
|
|
|
last_character_ = last_character;
|
|
|
|
buffer_ = buffer;
|
|
|
|
utf16_chars_read_ += i;
|
2012-03-21 13:48:29 +00:00
|
|
|
}
|
|
|
|
|
2013-01-03 12:59:54 +00:00
|
|
|
inline bool IsDone() {
|
|
|
|
return early_termination_;
|
|
|
|
}
|
2012-03-21 13:48:29 +00:00
|
|
|
|
2013-03-06 15:39:57 +00:00
|
|
|
inline void VisitOneByteString(const uint8_t* chars, int length) {
|
|
|
|
Visit(chars, length);
|
2012-03-19 09:51:36 +00:00
|
|
|
}
|
2013-01-03 12:59:54 +00:00
|
|
|
|
2013-03-06 15:39:57 +00:00
|
|
|
inline void VisitTwoByteString(const uint16_t* chars, int length) {
|
|
|
|
Visit(chars, length);
|
2013-01-03 12:59:54 +00:00
|
|
|
}
|
|
|
|
|
2013-03-06 15:39:57 +00:00
|
|
|
int CompleteWrite(bool write_null, int* utf16_chars_read_out) {
|
2013-01-03 12:59:54 +00:00
|
|
|
// Write out number of utf16 characters written to the stream.
|
|
|
|
if (utf16_chars_read_out != NULL) {
|
|
|
|
*utf16_chars_read_out = utf16_chars_read_;
|
|
|
|
}
|
|
|
|
// Only null terminate if all of the string was written and there's space.
|
|
|
|
if (write_null &&
|
|
|
|
!early_termination_ &&
|
|
|
|
(capacity_ == -1 || (buffer_ - start_) < capacity_)) {
|
|
|
|
*buffer_++ = '\0';
|
|
|
|
}
|
2013-01-03 13:16:00 +00:00
|
|
|
return static_cast<int>(buffer_ - start_);
|
2013-01-03 12:59:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool early_termination_;
|
|
|
|
int last_character_;
|
|
|
|
char* buffer_;
|
|
|
|
char* const start_;
|
|
|
|
int capacity_;
|
2013-03-06 15:39:57 +00:00
|
|
|
bool const skip_capacity_check_;
|
2014-01-20 09:52:54 +00:00
|
|
|
bool const replace_invalid_utf8_;
|
2013-01-03 12:59:54 +00:00
|
|
|
int utf16_chars_read_;
|
|
|
|
DISALLOW_IMPLICIT_CONSTRUCTORS(Utf8WriterVisitor);
|
|
|
|
};
|
2012-03-19 09:51:36 +00:00
|
|
|
|
|
|
|
|
2013-03-06 15:39:57 +00:00
|
|
|
static bool RecursivelySerializeToUtf8(i::String* current,
|
2014-01-13 09:42:23 +00:00
|
|
|
Utf8WriterVisitor* writer,
|
|
|
|
int recursion_budget) {
|
2013-03-06 15:39:57 +00:00
|
|
|
while (!writer->IsDone()) {
|
|
|
|
i::ConsString* cons_string = i::String::VisitFlat(writer, current);
|
|
|
|
if (cons_string == NULL) return true; // Leaf node.
|
|
|
|
if (recursion_budget <= 0) return false;
|
|
|
|
// Must write the left branch first.
|
|
|
|
i::String* first = cons_string->first();
|
|
|
|
bool success = RecursivelySerializeToUtf8(first,
|
|
|
|
writer,
|
|
|
|
recursion_budget - 1);
|
|
|
|
if (!success) return false;
|
|
|
|
// Inline tail recurse for right branch.
|
|
|
|
current = cons_string->second();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-13 17:00:33 +00:00
|
|
|
int String::WriteUtf8(char* buffer,
|
|
|
|
int capacity,
|
|
|
|
int* nchars_ref,
|
2011-08-23 11:11:12 +00:00
|
|
|
int options) const {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
LOG_API(isolate, "String::WriteUtf8");
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2008-09-05 13:39:14 +00:00
|
|
|
i::Handle<i::String> str = Utils::OpenHandle(this);
|
2012-07-23 14:22:46 +00:00
|
|
|
if (options & HINT_MANY_WRITES_EXPECTED) {
|
2014-04-08 09:49:49 +00:00
|
|
|
str = i::String::Flatten(str); // Flatten the string for efficiency.
|
2012-07-23 14:22:46 +00:00
|
|
|
}
|
2013-03-06 15:39:57 +00:00
|
|
|
const int string_length = str->length();
|
|
|
|
bool write_null = !(options & NO_NULL_TERMINATION);
|
2014-01-20 09:52:54 +00:00
|
|
|
bool replace_invalid_utf8 = (options & REPLACE_INVALID_UTF8);
|
|
|
|
int max16BitCodeUnitSize = unibrow::Utf8::kMax16BitCodeUnitSize;
|
2013-03-06 15:39:57 +00:00
|
|
|
// First check if we can just write the string without checking capacity.
|
2014-01-20 09:52:54 +00:00
|
|
|
if (capacity == -1 || capacity / max16BitCodeUnitSize >= string_length) {
|
|
|
|
Utf8WriterVisitor writer(buffer, capacity, true, replace_invalid_utf8);
|
2013-03-06 15:39:57 +00:00
|
|
|
const int kMaxRecursion = 100;
|
|
|
|
bool success = RecursivelySerializeToUtf8(*str, &writer, kMaxRecursion);
|
|
|
|
if (success) return writer.CompleteWrite(write_null, nchars_ref);
|
|
|
|
} else if (capacity >= string_length) {
|
|
|
|
// First check that the buffer is large enough.
|
|
|
|
int utf8_bytes = v8::Utf8Length(*str, str->GetIsolate());
|
|
|
|
if (utf8_bytes <= capacity) {
|
|
|
|
// ASCII fast path.
|
|
|
|
if (utf8_bytes == string_length) {
|
|
|
|
WriteOneByte(reinterpret_cast<uint8_t*>(buffer), 0, capacity, options);
|
|
|
|
if (nchars_ref != NULL) *nchars_ref = string_length;
|
|
|
|
if (write_null && (utf8_bytes+1 <= capacity)) {
|
|
|
|
return string_length + 1;
|
|
|
|
}
|
|
|
|
return string_length;
|
|
|
|
}
|
|
|
|
if (write_null && (utf8_bytes+1 > capacity)) {
|
|
|
|
options |= NO_NULL_TERMINATION;
|
|
|
|
}
|
|
|
|
// Recurse once without a capacity limit.
|
|
|
|
// This will get into the first branch above.
|
|
|
|
// TODO(dcarney) Check max left rec. in Utf8Length and fall through.
|
|
|
|
return WriteUtf8(buffer, -1, nchars_ref, options);
|
2012-03-21 13:48:29 +00:00
|
|
|
}
|
2012-07-23 14:22:46 +00:00
|
|
|
}
|
2013-03-06 15:39:57 +00:00
|
|
|
// Recursive slow path can potentially be unreasonable slow. Flatten.
|
2014-04-08 09:49:49 +00:00
|
|
|
str = i::String::Flatten(str);
|
2014-01-20 09:52:54 +00:00
|
|
|
Utf8WriterVisitor writer(buffer, capacity, false, replace_invalid_utf8);
|
2013-03-06 15:39:57 +00:00
|
|
|
i::String::VisitFlat(&writer, *str);
|
|
|
|
return writer.CompleteWrite(write_null, nchars_ref);
|
2008-09-05 13:39:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-14 11:22:05 +00:00
|
|
|
template<typename CharType>
|
2013-01-17 14:31:03 +00:00
|
|
|
static inline int WriteHelper(const String* string,
|
|
|
|
CharType* buffer,
|
|
|
|
int start,
|
|
|
|
int length,
|
|
|
|
int options) {
|
|
|
|
i::Isolate* isolate = Utils::OpenHandle(string)->GetIsolate();
|
|
|
|
LOG_API(isolate, "String::Write");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
ASSERT(start >= 0 && length >= -1);
|
|
|
|
i::Handle<i::String> str = Utils::OpenHandle(string);
|
|
|
|
isolate->string_tracker()->RecordWrite(str);
|
|
|
|
if (options & String::HINT_MANY_WRITES_EXPECTED) {
|
|
|
|
// Flatten the string for efficiency. This applies whether we are
|
|
|
|
// using StringCharacterStream or Get(i) to access the characters.
|
2014-04-08 09:49:49 +00:00
|
|
|
str = i::String::Flatten(str);
|
2013-01-17 14:31:03 +00:00
|
|
|
}
|
|
|
|
int end = start + length;
|
|
|
|
if ((length == -1) || (length > str->length() - start) )
|
|
|
|
end = str->length();
|
|
|
|
if (end < 0) return 0;
|
|
|
|
i::String::WriteToFlat(*str, buffer, start, end);
|
|
|
|
if (!(options & String::NO_NULL_TERMINATION) &&
|
|
|
|
(length == -1 || end - start < length)) {
|
|
|
|
buffer[end - start] = '\0';
|
2013-01-14 11:22:05 +00:00
|
|
|
}
|
2013-01-17 14:31:03 +00:00
|
|
|
return end - start;
|
|
|
|
}
|
2013-01-14 11:22:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
int String::WriteOneByte(uint8_t* buffer,
|
|
|
|
int start,
|
|
|
|
int length,
|
|
|
|
int options) const {
|
2013-01-17 14:31:03 +00:00
|
|
|
return WriteHelper(this, buffer, start, length, options);
|
2013-01-14 11:22:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-13 17:00:33 +00:00
|
|
|
int String::Write(uint16_t* buffer,
|
|
|
|
int start,
|
|
|
|
int length,
|
2011-08-23 11:11:12 +00:00
|
|
|
int options) const {
|
2013-01-17 14:31:03 +00:00
|
|
|
return WriteHelper(this, buffer, start, length, options);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
bool v8::String::IsExternal() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::String> str = Utils::OpenHandle(this);
|
2011-03-24 18:49:45 +00:00
|
|
|
EnsureInitializedForIsolate(str->GetIsolate(), "v8::String::IsExternal()");
|
2009-03-17 09:33:06 +00:00
|
|
|
return i::StringShape(*str).IsExternalTwoByte();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
bool v8::String::IsExternalAscii() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::String> str = Utils::OpenHandle(this);
|
2009-03-17 09:33:06 +00:00
|
|
|
return i::StringShape(*str).IsExternalAscii();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-04 12:23:22 +00:00
|
|
|
void v8::String::VerifyExternalStringResource(
|
|
|
|
v8::String::ExternalStringResource* value) const {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::String> str = Utils::OpenHandle(this);
|
2012-09-04 12:23:22 +00:00
|
|
|
const v8::String::ExternalStringResource* expected;
|
2009-05-06 18:30:37 +00:00
|
|
|
if (i::StringShape(*str).IsExternalTwoByte()) {
|
2012-09-04 12:23:22 +00:00
|
|
|
const void* resource =
|
|
|
|
i::Handle<i::ExternalTwoByteString>::cast(str)->resource();
|
|
|
|
expected = reinterpret_cast<const ExternalStringResource*>(resource);
|
2009-05-06 18:30:37 +00:00
|
|
|
} else {
|
2012-09-04 12:23:22 +00:00
|
|
|
expected = NULL;
|
2009-05-06 18:30:37 +00:00
|
|
|
}
|
2012-09-04 12:23:22 +00:00
|
|
|
CHECK_EQ(expected, value);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2012-09-12 11:29:50 +00:00
|
|
|
void v8::String::VerifyExternalStringResourceBase(
|
|
|
|
v8::String::ExternalStringResourceBase* value, Encoding encoding) const {
|
|
|
|
i::Handle<i::String> str = Utils::OpenHandle(this);
|
|
|
|
const v8::String::ExternalStringResourceBase* expected;
|
|
|
|
Encoding expectedEncoding;
|
|
|
|
if (i::StringShape(*str).IsExternalAscii()) {
|
|
|
|
const void* resource =
|
|
|
|
i::Handle<i::ExternalAsciiString>::cast(str)->resource();
|
|
|
|
expected = reinterpret_cast<const ExternalStringResourceBase*>(resource);
|
|
|
|
expectedEncoding = ASCII_ENCODING;
|
|
|
|
} else if (i::StringShape(*str).IsExternalTwoByte()) {
|
|
|
|
const void* resource =
|
|
|
|
i::Handle<i::ExternalTwoByteString>::cast(str)->resource();
|
|
|
|
expected = reinterpret_cast<const ExternalStringResourceBase*>(resource);
|
|
|
|
expectedEncoding = TWO_BYTE_ENCODING;
|
|
|
|
} else {
|
|
|
|
expected = NULL;
|
2012-11-21 10:01:05 +00:00
|
|
|
expectedEncoding = str->IsOneByteRepresentation() ? ASCII_ENCODING
|
2014-01-13 09:42:23 +00:00
|
|
|
: TWO_BYTE_ENCODING;
|
2012-09-12 11:29:50 +00:00
|
|
|
}
|
|
|
|
CHECK_EQ(expected, value);
|
|
|
|
CHECK_EQ(expectedEncoding, encoding);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-09-21 13:28:09 +00:00
|
|
|
const v8::String::ExternalAsciiStringResource*
|
2014-01-13 09:42:23 +00:00
|
|
|
v8::String::GetExternalAsciiStringResource() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::String> str = Utils::OpenHandle(this);
|
2009-05-06 18:30:37 +00:00
|
|
|
if (i::StringShape(*str).IsExternalAscii()) {
|
2011-09-21 13:28:09 +00:00
|
|
|
const void* resource =
|
|
|
|
i::Handle<i::ExternalAsciiString>::cast(str)->resource();
|
|
|
|
return reinterpret_cast<const ExternalAsciiStringResource*>(resource);
|
2009-05-06 18:30:37 +00:00
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-10 12:16:29 +00:00
|
|
|
Local<Value> Symbol::Name() const {
|
|
|
|
i::Handle<i::Symbol> sym = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> name(sym->name(), sym->GetIsolate());
|
|
|
|
return Utils::ToLocal(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
|
|
|
Local<Value> Private::Name() const {
|
|
|
|
return reinterpret_cast<const Symbol*>(this)->Name();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
double Number::Value() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
return obj->Number();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
bool Boolean::Value() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
return obj->IsTrue();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
int64_t Integer::Value() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
if (obj->IsSmi()) {
|
|
|
|
return i::Smi::cast(*obj)->value();
|
|
|
|
} else {
|
|
|
|
return static_cast<int64_t>(obj->Number());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
int32_t Int32::Value() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
if (obj->IsSmi()) {
|
|
|
|
return i::Smi::cast(*obj)->value();
|
|
|
|
} else {
|
|
|
|
return static_cast<int32_t>(obj->Number());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-03 13:44:20 +00:00
|
|
|
uint32_t Uint32::Value() const {
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
if (obj->IsSmi()) {
|
|
|
|
return i::Smi::cast(*obj)->value();
|
|
|
|
} else {
|
|
|
|
return static_cast<uint32_t>(obj->Number());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
int v8::Object::InternalFieldCount() {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
|
2008-07-03 15:10:15 +00:00
|
|
|
return obj->GetInternalFieldCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-13 12:27:03 +00:00
|
|
|
static bool InternalFieldOK(i::Handle<i::JSObject> obj,
|
|
|
|
int index,
|
|
|
|
const char* location) {
|
2014-01-13 09:42:23 +00:00
|
|
|
return Utils::ApiCheck(index < obj->GetInternalFieldCount(),
|
|
|
|
location,
|
|
|
|
"Internal field out of bounds");
|
2012-11-13 12:27:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<Value> v8::Object::SlowGetInternalField(int index) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
|
2012-11-13 12:27:03 +00:00
|
|
|
const char* location = "v8::Object::GetInternalField()";
|
|
|
|
if (!InternalFieldOK(obj, index, location)) return Local<Value>();
|
|
|
|
i::Handle<i::Object> value(obj->GetInternalField(index), obj->GetIsolate());
|
|
|
|
return Utils::ToLocal(value);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-16 07:07:30 +00:00
|
|
|
void v8::Object::SetInternalField(int index, v8::Handle<Value> value) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
|
2012-11-13 12:27:03 +00:00
|
|
|
const char* location = "v8::Object::SetInternalField()";
|
|
|
|
if (!InternalFieldOK(obj, index, location)) return;
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> val = Utils::OpenHandle(*value);
|
|
|
|
obj->SetInternalField(index, *val);
|
2012-11-13 12:27:03 +00:00
|
|
|
ASSERT_EQ(value, GetInternalField(index));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-13 12:27:03 +00:00
|
|
|
void* v8::Object::SlowGetAlignedPointerFromInternalField(int index) {
|
|
|
|
i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
|
|
|
|
const char* location = "v8::Object::GetAlignedPointerFromInternalField()";
|
|
|
|
if (!InternalFieldOK(obj, index, location)) return NULL;
|
|
|
|
return DecodeSmiToAligned(obj->GetInternalField(index), location);
|
2011-01-13 15:56:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-13 12:27:03 +00:00
|
|
|
void v8::Object::SetAlignedPointerInInternalField(int index, void* value) {
|
|
|
|
i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
|
|
|
|
const char* location = "v8::Object::SetAlignedPointerInInternalField()";
|
|
|
|
if (!InternalFieldOK(obj, index, location)) return;
|
|
|
|
obj->SetInternalField(index, EncodeAlignedAsSmi(value, location));
|
|
|
|
ASSERT_EQ(value, GetAlignedPointerFromInternalField(index));
|
2012-11-05 10:25:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-13 12:27:03 +00:00
|
|
|
static void* ExternalValue(i::Object* obj) {
|
|
|
|
// Obscure semantics for undefined, but somehow checked in our unit tests...
|
|
|
|
if (obj->IsUndefined()) return NULL;
|
|
|
|
i::Object* foreign = i::JSObject::cast(obj)->GetInternalField(0);
|
|
|
|
return i::Foreign::cast(foreign)->foreign_address();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// --- E n v i r o n m e n t ---
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2013-11-21 14:07:06 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
bool v8::V8::Initialize() {
|
2012-03-30 14:30:46 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::UncheckedCurrent();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (isolate != NULL && isolate->IsInitialized()) {
|
|
|
|
return true;
|
|
|
|
}
|
2013-06-28 13:40:41 +00:00
|
|
|
return InitializeHelper(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-10 11:13:55 +00:00
|
|
|
void v8::V8::SetEntropySource(EntropySource entropy_source) {
|
|
|
|
i::RandomNumberGenerator::SetEntropySource(entropy_source);
|
2011-07-17 09:16:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-27 15:15:53 +00:00
|
|
|
void v8::V8::SetReturnAddressLocationResolver(
|
2014-01-13 09:42:23 +00:00
|
|
|
ReturnAddressLocationResolver return_address_resolver) {
|
2012-02-27 15:15:53 +00:00
|
|
|
i::V8::SetReturnAddressLocationResolver(return_address_resolver);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-28 13:40:41 +00:00
|
|
|
bool v8::V8::SetFunctionEntryHook(Isolate* ext_isolate,
|
|
|
|
FunctionEntryHook entry_hook) {
|
|
|
|
ASSERT(ext_isolate != NULL);
|
|
|
|
ASSERT(entry_hook != NULL);
|
|
|
|
|
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(ext_isolate);
|
|
|
|
|
|
|
|
// The entry hook can only be set before the Isolate is initialized, as
|
|
|
|
// otherwise the Isolate's code stubs generated at initialization won't
|
|
|
|
// contain entry hooks.
|
|
|
|
if (isolate->IsInitialized())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Setting an entry hook is a one-way operation, once set, it cannot be
|
|
|
|
// changed or unset.
|
|
|
|
if (isolate->function_entry_hook() != NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
isolate->set_function_entry_hook(entry_hook);
|
|
|
|
return true;
|
2012-07-17 15:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-28 14:43:28 +00:00
|
|
|
void v8::V8::SetJitCodeEventHandler(
|
|
|
|
JitCodeEventOptions options, JitCodeEventHandler event_handler) {
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
// Ensure that logging is initialized for our isolate.
|
|
|
|
isolate->InitializeLoggingAndCounters();
|
|
|
|
isolate->logger()->SetCodeEventHandler(options, event_handler);
|
|
|
|
}
|
|
|
|
|
2013-06-11 10:41:14 +00:00
|
|
|
void v8::V8::SetArrayBufferAllocator(
|
|
|
|
ArrayBuffer::Allocator* allocator) {
|
2014-01-13 09:42:23 +00:00
|
|
|
if (!Utils::ApiCheck(i::V8::ArrayBufferAllocator() == NULL,
|
|
|
|
"v8::V8::SetArrayBufferAllocator",
|
|
|
|
"ArrayBufferAllocator might only be set once"))
|
2013-06-11 10:41:14 +00:00
|
|
|
return;
|
|
|
|
i::V8::SetArrayBufferAllocator(allocator);
|
|
|
|
}
|
|
|
|
|
2012-08-28 14:43:28 +00:00
|
|
|
|
2009-03-27 00:24:49 +00:00
|
|
|
bool v8::V8::Dispose() {
|
2013-10-02 09:01:40 +00:00
|
|
|
i::V8::TearDown();
|
|
|
|
return true;
|
2009-03-27 00:24:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-10 08:38:42 +00:00
|
|
|
HeapStatistics::HeapStatistics(): total_heap_size_(0),
|
|
|
|
total_heap_size_executable_(0),
|
2012-10-22 16:33:10 +00:00
|
|
|
total_physical_size_(0),
|
2011-01-11 12:36:09 +00:00
|
|
|
used_heap_size_(0),
|
|
|
|
heap_size_limit_(0) { }
|
2009-10-20 07:51:49 +00:00
|
|
|
|
|
|
|
|
2012-01-13 15:14:45 +00:00
|
|
|
void v8::V8::VisitExternalResources(ExternalResourceVisitor* visitor) {
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
isolate->heap()->VisitExternalResources(visitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-24 15:53:16 +00:00
|
|
|
class VisitorAdapter : public i::ObjectVisitor {
|
|
|
|
public:
|
|
|
|
explicit VisitorAdapter(PersistentHandleVisitor* visitor)
|
|
|
|
: visitor_(visitor) {}
|
|
|
|
virtual void VisitPointers(i::Object** start, i::Object** end) {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
virtual void VisitEmbedderReference(i::Object** p, uint16_t class_id) {
|
2013-05-29 08:48:37 +00:00
|
|
|
Value* value = ToApi<Value>(i::Handle<i::Object>(p));
|
|
|
|
visitor_->VisitPersistentHandle(
|
|
|
|
reinterpret_cast<Persistent<Value>*>(&value), class_id);
|
2013-01-24 15:53:16 +00:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
PersistentHandleVisitor* visitor_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-10-18 06:52:37 +00:00
|
|
|
void v8::V8::VisitHandlesWithClassIds(PersistentHandleVisitor* visitor) {
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2013-06-03 15:32:22 +00:00
|
|
|
i::DisallowHeapAllocation no_allocation;
|
2012-10-18 06:52:37 +00:00
|
|
|
|
2013-01-24 15:53:16 +00:00
|
|
|
VisitorAdapter visitor_adapter(visitor);
|
2012-10-18 06:52:37 +00:00
|
|
|
isolate->global_handles()->IterateAllRootsWithClassIds(&visitor_adapter);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-24 15:53:16 +00:00
|
|
|
void v8::V8::VisitHandlesForPartialDependence(
|
|
|
|
Isolate* exported_isolate, PersistentHandleVisitor* visitor) {
|
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(exported_isolate);
|
|
|
|
ASSERT(isolate == i::Isolate::Current());
|
2013-06-03 15:32:22 +00:00
|
|
|
i::DisallowHeapAllocation no_allocation;
|
2013-01-24 15:53:16 +00:00
|
|
|
|
|
|
|
VisitorAdapter visitor_adapter(visitor);
|
|
|
|
isolate->global_handles()->IterateAllRootsInNewSpaceWithClassIds(
|
|
|
|
&visitor_adapter);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-30 11:13:36 +00:00
|
|
|
bool v8::V8::IdleNotification(int hint) {
|
2009-10-02 17:26:50 +00:00
|
|
|
// Returning true tells the caller that it need not
|
|
|
|
// continue to call IdleNotification.
|
2011-10-19 07:49:47 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (isolate == NULL || !isolate->IsInitialized()) return true;
|
2013-09-04 13:37:39 +00:00
|
|
|
if (!i::FLAG_use_idle_notification) return true;
|
|
|
|
return isolate->heap()->IdleNotification(hint);
|
2009-08-13 09:35:51 +00:00
|
|
|
}
|
|
|
|
|
2009-08-20 00:07:19 +00:00
|
|
|
|
|
|
|
void v8::V8::LowMemoryNotification() {
|
2011-03-28 09:11:14 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2011-10-19 07:49:47 +00:00
|
|
|
if (isolate == NULL || !isolate->IsInitialized()) return;
|
2012-02-03 14:16:40 +00:00
|
|
|
isolate->heap()->CollectAllAvailableGarbage("low memory notification");
|
2009-08-20 00:07:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-08 11:19:20 +00:00
|
|
|
int v8::V8::ContextDisposedNotification() {
|
2011-03-28 09:11:14 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (!isolate->IsInitialized()) return 0;
|
|
|
|
return isolate->heap()->NotifyContextDisposed();
|
2010-02-26 11:51:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-25 12:05:33 +00:00
|
|
|
bool v8::V8::InitializeICU(const char* icu_data_file) {
|
|
|
|
return i::InitializeICU(icu_data_file);
|
2013-07-11 09:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-30 08:49:36 +00:00
|
|
|
const char* v8::V8::GetVersion() {
|
2011-03-18 20:35:07 +00:00
|
|
|
return i::Version::GetVersion();
|
2008-07-30 08:49:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-10 09:34:37 +00:00
|
|
|
static i::Handle<i::Context> CreateEnvironment(
|
|
|
|
i::Isolate* isolate,
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
v8::ExtensionConfiguration* extensions,
|
|
|
|
v8::Handle<ObjectTemplate> global_template,
|
|
|
|
v8::Handle<Value> global_object) {
|
2013-04-10 09:34:37 +00:00
|
|
|
i::Handle<i::Context> env;
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
|
2009-04-03 07:49:20 +00:00
|
|
|
// Enter V8 via an ENTER_V8 scope.
|
|
|
|
{
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2009-04-03 07:49:20 +00:00
|
|
|
v8::Handle<ObjectTemplate> proxy_template = global_template;
|
|
|
|
i::Handle<i::FunctionTemplateInfo> proxy_constructor;
|
|
|
|
i::Handle<i::FunctionTemplateInfo> global_constructor;
|
|
|
|
|
|
|
|
if (!global_template.IsEmpty()) {
|
|
|
|
// Make sure that the global_template has a constructor.
|
2013-12-18 10:31:42 +00:00
|
|
|
global_constructor = EnsureConstructor(isolate, *global_template);
|
2009-04-03 07:49:20 +00:00
|
|
|
|
|
|
|
// Create a fresh template for the global proxy object.
|
2014-01-08 06:53:31 +00:00
|
|
|
proxy_template = ObjectTemplate::New(
|
|
|
|
reinterpret_cast<v8::Isolate*>(isolate));
|
2013-12-18 10:31:42 +00:00
|
|
|
proxy_constructor = EnsureConstructor(isolate, *proxy_template);
|
2009-04-03 07:49:20 +00:00
|
|
|
|
|
|
|
// Set the global template to be the prototype template of
|
|
|
|
// global proxy template.
|
|
|
|
proxy_constructor->set_prototype_template(
|
|
|
|
*Utils::OpenHandle(*global_template));
|
|
|
|
|
|
|
|
// Migrate security handlers from global_template to
|
|
|
|
// proxy_template. Temporarily removing access check
|
|
|
|
// information from the global template.
|
|
|
|
if (!global_constructor->access_check_info()->IsUndefined()) {
|
|
|
|
proxy_constructor->set_access_check_info(
|
|
|
|
global_constructor->access_check_info());
|
|
|
|
proxy_constructor->set_needs_access_check(
|
|
|
|
global_constructor->needs_access_check());
|
|
|
|
global_constructor->set_needs_access_check(false);
|
2011-03-28 09:11:14 +00:00
|
|
|
global_constructor->set_access_check_info(
|
|
|
|
isolate->heap()->undefined_value());
|
2009-04-03 07:49:20 +00:00
|
|
|
}
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
}
|
2008-12-11 11:09:51 +00:00
|
|
|
|
2009-04-03 07:49:20 +00:00
|
|
|
// Create the environment.
|
2011-03-18 20:35:07 +00:00
|
|
|
env = isolate->bootstrapper()->CreateEnvironment(
|
2012-09-05 16:06:53 +00:00
|
|
|
Utils::OpenHandle(*global_object, true),
|
2009-04-03 07:49:20 +00:00
|
|
|
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());
|
|
|
|
global_constructor->set_access_check_info(
|
|
|
|
proxy_constructor->access_check_info());
|
|
|
|
global_constructor->set_needs_access_check(
|
|
|
|
proxy_constructor->needs_access_check());
|
|
|
|
}
|
2008-12-11 11:09:51 +00:00
|
|
|
}
|
2009-04-03 07:49:20 +00:00
|
|
|
// Leave V8.
|
2008-12-11 11:09:51 +00:00
|
|
|
|
2013-04-10 09:34:37 +00:00
|
|
|
return env;
|
|
|
|
}
|
|
|
|
|
|
|
|
Local<Context> v8::Context::New(
|
|
|
|
v8::Isolate* external_isolate,
|
|
|
|
v8::ExtensionConfiguration* extensions,
|
|
|
|
v8::Handle<ObjectTemplate> global_template,
|
|
|
|
v8::Handle<Value> global_object) {
|
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
|
|
|
|
EnsureInitializedForIsolate(isolate, "v8::Context::New()");
|
|
|
|
LOG_API(isolate, "Context::New");
|
|
|
|
ON_BAILOUT(isolate, "v8::Context::New()", return Local<Context>());
|
|
|
|
i::HandleScope scope(isolate);
|
2014-01-16 08:17:40 +00:00
|
|
|
ExtensionConfiguration no_extensions;
|
|
|
|
if (extensions == NULL) extensions = &no_extensions;
|
2013-04-10 09:34:37 +00:00
|
|
|
i::Handle<i::Context> env =
|
|
|
|
CreateEnvironment(isolate, extensions, global_template, global_object);
|
|
|
|
if (env.is_null()) return Local<Context>();
|
|
|
|
return Utils::ToLocal(scope.CloseAndEscape(env));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void v8::Context::SetSecurityToken(Handle<Value> token) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
ENTER_V8(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Context> env = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> token_handle = Utils::OpenHandle(*token);
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
env->set_security_token(*token_handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void v8::Context::UseDefaultSecurityToken() {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
ENTER_V8(isolate);
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
i::Handle<i::Context> env = Utils::OpenHandle(this);
|
2012-08-17 12:59:00 +00:00
|
|
|
env->set_security_token(env->global_object());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Value> v8::Context::GetSecurityToken() {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Context> env = Utils::OpenHandle(this);
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
i::Object* security_token = env->security_token();
|
2013-02-25 14:46:09 +00:00
|
|
|
i::Handle<i::Object> token_handle(security_token, isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::ToLocal(token_handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-16 12:11:43 +00:00
|
|
|
v8::Isolate* Context::GetIsolate() {
|
|
|
|
i::Handle<i::Context> env = Utils::OpenHandle(this);
|
|
|
|
return reinterpret_cast<Isolate*>(env->GetIsolate());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
v8::Local<v8::Object> Context::Global() {
|
2013-09-23 11:25:52 +00:00
|
|
|
i::Handle<i::Context> context = Utils::OpenHandle(this);
|
|
|
|
i::Isolate* isolate = context->GetIsolate();
|
2012-11-16 08:38:11 +00:00
|
|
|
i::Handle<i::Object> global(context->global_proxy(), isolate);
|
2013-12-11 13:51:48 +00:00
|
|
|
// TODO(dcarney): This should always return the global proxy
|
|
|
|
// but can't presently as calls to GetProtoype will return the wrong result.
|
|
|
|
if (i::Handle<i::JSGlobalProxy>::cast(
|
|
|
|
global)->IsDetachedFrom(context->global_object())) {
|
2014-01-13 09:42:23 +00:00
|
|
|
global = i::Handle<i::Object>(context->global_object(), isolate);
|
2013-12-11 13:51:48 +00:00
|
|
|
}
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
return Utils::ToLocal(i::Handle<i::JSObject>::cast(global));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
void Context::DetachGlobal() {
|
2013-09-23 11:25:52 +00:00
|
|
|
i::Handle<i::Context> context = Utils::OpenHandle(this);
|
|
|
|
i::Isolate* isolate = context->GetIsolate();
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2011-03-23 14:07:52 +00:00
|
|
|
isolate->bootstrapper()->DetachGlobal(context);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-03 05:40:47 +00:00
|
|
|
void Context::AllowCodeGenerationFromStrings(bool allow) {
|
2013-09-23 11:25:52 +00:00
|
|
|
i::Handle<i::Context> context = Utils::OpenHandle(this);
|
|
|
|
i::Isolate* isolate = context->GetIsolate();
|
2011-05-03 05:40:47 +00:00
|
|
|
ENTER_V8(isolate);
|
|
|
|
context->set_allow_code_gen_from_strings(
|
|
|
|
allow ? isolate->heap()->true_value() : isolate->heap()->false_value());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-01 12:58:34 +00:00
|
|
|
bool Context::IsCodeGenerationFromStringsAllowed() {
|
2013-09-23 11:25:52 +00:00
|
|
|
i::Handle<i::Context> context = Utils::OpenHandle(this);
|
2012-02-01 12:58:34 +00:00
|
|
|
return !context->allow_code_gen_from_strings()->IsFalse();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-17 09:58:22 +00:00
|
|
|
void Context::SetErrorMessageForCodeGenerationFromStrings(
|
|
|
|
Handle<String> error) {
|
2013-09-23 11:25:52 +00:00
|
|
|
i::Handle<i::Context> context = Utils::OpenHandle(this);
|
2013-02-25 14:46:09 +00:00
|
|
|
i::Handle<i::String> error_handle = Utils::OpenHandle(*error);
|
2012-09-17 09:58:22 +00:00
|
|
|
context->set_error_message_for_code_gen_from_strings(*error_handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Local<v8::Object> ObjectTemplate::NewInstance() {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
ON_BAILOUT(isolate, "v8::ObjectTemplate::NewInstance()",
|
|
|
|
return Local<v8::Object>());
|
|
|
|
LOG_API(isolate, "ObjectTemplate::NewInstance");
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
i::Handle<i::Object> obj;
|
|
|
|
has_pending_exception = !i::Execution::InstantiateObject(
|
|
|
|
Utils::OpenHandle(this)).ToHandle(&obj);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>());
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::ToLocal(i::Handle<i::JSObject>::cast(obj));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<v8::Function> FunctionTemplate::GetFunction() {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
ON_BAILOUT(isolate, "v8::FunctionTemplate::GetFunction()",
|
2008-07-03 15:10:15 +00:00
|
|
|
return Local<v8::Function>());
|
2011-03-18 20:35:07 +00:00
|
|
|
LOG_API(isolate, "FunctionTemplate::GetFunction");
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
i::Handle<i::Object> obj;
|
|
|
|
has_pending_exception = !i::Execution::InstantiateFunction(
|
|
|
|
Utils::OpenHandle(this)).ToHandle(&obj);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Function>());
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::ToLocal(i::Handle<i::JSFunction>::cast(obj));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool FunctionTemplate::HasInstance(v8::Handle<v8::Value> value) {
|
2011-03-18 20:35:07 +00:00
|
|
|
ON_BAILOUT(i::Isolate::Current(), "v8::FunctionTemplate::HasInstanceOf()",
|
|
|
|
return false);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Object* obj = *Utils::OpenHandle(*value);
|
2013-11-19 13:38:15 +00:00
|
|
|
return Utils::OpenHandle(this)->IsTemplateFor(obj);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-12 11:44:58 +00:00
|
|
|
Local<External> v8::External::New(Isolate* isolate, void* value) {
|
2012-11-13 12:27:03 +00:00
|
|
|
STATIC_ASSERT(sizeof(value) == sizeof(i::Address));
|
2013-11-12 11:44:58 +00:00
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
EnsureInitializedForIsolate(i_isolate, "v8::External::New()");
|
|
|
|
LOG_API(i_isolate, "External::New");
|
|
|
|
ENTER_V8(i_isolate);
|
|
|
|
i::Handle<i::JSObject> external = i_isolate->factory()->NewExternal(value);
|
2012-11-13 12:27:03 +00:00
|
|
|
return Utils::ExternalToLocal(external);
|
2009-03-23 19:51:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void* External::Value() const {
|
2012-11-13 12:27:03 +00:00
|
|
|
return ExternalValue(*Utils::OpenHandle(this));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-22 15:20:28 +00:00
|
|
|
// anonymous namespace for string creation helper functions
|
|
|
|
namespace {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-04-22 15:20:28 +00:00
|
|
|
inline int StringLength(const char* string) {
|
|
|
|
return i::StrLength(string);
|
2009-10-14 15:26:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-22 15:20:28 +00:00
|
|
|
inline int StringLength(const uint8_t* string) {
|
|
|
|
return i::StrLength(reinterpret_cast<const char*>(string));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-22 15:20:28 +00:00
|
|
|
inline int StringLength(const uint16_t* string) {
|
2008-07-03 15:10:15 +00:00
|
|
|
int length = 0;
|
2013-04-22 15:20:28 +00:00
|
|
|
while (string[length] != '\0')
|
|
|
|
length++;
|
2008-07-03 15:10:15 +00:00
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-17 13:27:02 +00:00
|
|
|
MUST_USE_RESULT
|
|
|
|
inline i::MaybeHandle<i::String> NewString(i::Factory* factory,
|
|
|
|
String::NewStringType type,
|
|
|
|
i::Vector<const char> string) {
|
2014-04-24 08:35:04 +00:00
|
|
|
if (type == String::kInternalizedString) {
|
2013-04-22 15:20:28 +00:00
|
|
|
return factory->InternalizeUtf8String(string);
|
|
|
|
}
|
|
|
|
return factory->NewStringFromUtf8(string);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-17 13:27:02 +00:00
|
|
|
MUST_USE_RESULT
|
|
|
|
inline i::MaybeHandle<i::String> NewString(i::Factory* factory,
|
|
|
|
String::NewStringType type,
|
|
|
|
i::Vector<const uint8_t> string) {
|
2013-04-22 15:20:28 +00:00
|
|
|
if (type == String::kInternalizedString) {
|
|
|
|
return factory->InternalizeOneByteString(string);
|
|
|
|
}
|
|
|
|
return factory->NewStringFromOneByte(string);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-17 13:27:02 +00:00
|
|
|
MUST_USE_RESULT
|
|
|
|
inline i::MaybeHandle<i::String> NewString(i::Factory* factory,
|
|
|
|
String::NewStringType type,
|
|
|
|
i::Vector<const uint16_t> string) {
|
2013-04-22 15:20:28 +00:00
|
|
|
if (type == String::kInternalizedString) {
|
|
|
|
return factory->InternalizeTwoByteString(string);
|
|
|
|
}
|
|
|
|
return factory->NewStringFromTwoByte(string);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename Char>
|
|
|
|
inline Local<String> NewString(Isolate* v8_isolate,
|
|
|
|
const char* location,
|
|
|
|
const char* env,
|
|
|
|
const Char* data,
|
|
|
|
String::NewStringType type,
|
|
|
|
int length) {
|
|
|
|
i::Isolate* isolate = reinterpret_cast<internal::Isolate*>(v8_isolate);
|
|
|
|
EnsureInitializedForIsolate(isolate, location);
|
|
|
|
LOG_API(isolate, env);
|
|
|
|
if (length == 0 && type != String::kUndetectableString) {
|
2014-01-03 14:31:17 +00:00
|
|
|
return String::Empty(v8_isolate);
|
2013-04-22 15:20:28 +00:00
|
|
|
}
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2013-04-22 15:20:28 +00:00
|
|
|
if (length == -1) length = StringLength(data);
|
2014-03-25 09:09:24 +00:00
|
|
|
// We do not expect this to fail. Change this if it does.
|
2014-04-17 13:27:02 +00:00
|
|
|
i::Handle<i::String> result = NewString(
|
|
|
|
isolate->factory(),
|
|
|
|
type,
|
|
|
|
i::Vector<const Char>(data, length)).ToHandleChecked();
|
2013-04-22 15:20:28 +00:00
|
|
|
if (type == String::kUndetectableString) {
|
|
|
|
result->MarkAsUndetectable();
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::ToLocal(result);
|
|
|
|
}
|
|
|
|
|
2013-04-22 15:20:28 +00:00
|
|
|
} // anonymous namespace
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-04-22 15:20:28 +00:00
|
|
|
|
|
|
|
Local<String> String::NewFromUtf8(Isolate* isolate,
|
|
|
|
const char* data,
|
|
|
|
NewStringType type,
|
|
|
|
int length) {
|
|
|
|
return NewString(isolate,
|
|
|
|
"v8::String::NewFromUtf8()",
|
|
|
|
"String::NewFromUtf8",
|
|
|
|
data,
|
|
|
|
type,
|
|
|
|
length);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<String> String::NewFromOneByte(Isolate* isolate,
|
|
|
|
const uint8_t* data,
|
|
|
|
NewStringType type,
|
|
|
|
int length) {
|
|
|
|
return NewString(isolate,
|
|
|
|
"v8::String::NewFromOneByte()",
|
|
|
|
"String::NewFromOneByte",
|
|
|
|
data,
|
|
|
|
type,
|
|
|
|
length);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<String> String::NewFromTwoByte(Isolate* isolate,
|
|
|
|
const uint16_t* data,
|
|
|
|
NewStringType type,
|
|
|
|
int length) {
|
|
|
|
return NewString(isolate,
|
|
|
|
"v8::String::NewFromTwoByte()",
|
|
|
|
"String::NewFromTwoByte",
|
|
|
|
data,
|
|
|
|
type,
|
|
|
|
length);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<String> v8::String::Concat(Handle<String> left, Handle<String> right) {
|
|
|
|
i::Handle<i::String> left_string = Utils::OpenHandle(*left);
|
|
|
|
i::Isolate* isolate = left_string->GetIsolate();
|
|
|
|
EnsureInitializedForIsolate(isolate, "v8::String::New()");
|
|
|
|
LOG_API(isolate, "String::New(char)");
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2013-04-22 15:20:28 +00:00
|
|
|
i::Handle<i::String> right_string = Utils::OpenHandle(*right);
|
2014-03-25 09:09:24 +00:00
|
|
|
// We do not expect this to fail. Change this if it does.
|
2014-04-03 12:30:37 +00:00
|
|
|
i::Handle<i::String> result = isolate->factory()->NewConsString(
|
|
|
|
left_string, right_string).ToHandleChecked();
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::ToLocal(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-13 09:42:23 +00:00
|
|
|
static i::Handle<i::String> NewExternalStringHandle(
|
|
|
|
i::Isolate* isolate,
|
|
|
|
v8::String::ExternalStringResource* resource) {
|
2014-03-25 09:09:24 +00:00
|
|
|
// We do not expect this to fail. Change this if it does.
|
2014-04-03 12:41:37 +00:00
|
|
|
return isolate->factory()->NewExternalStringFromTwoByte(
|
|
|
|
resource).ToHandleChecked();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-13 09:42:23 +00:00
|
|
|
static i::Handle<i::String> NewExternalAsciiStringHandle(
|
|
|
|
i::Isolate* isolate,
|
|
|
|
v8::String::ExternalAsciiStringResource* resource) {
|
2014-03-25 09:09:24 +00:00
|
|
|
// We do not expect this to fail. Change this if it does.
|
2014-04-03 12:41:37 +00:00
|
|
|
return isolate->factory()->NewExternalStringFromAscii(
|
|
|
|
resource).ToHandleChecked();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<String> v8::String::NewExternal(
|
2014-01-13 09:42:23 +00:00
|
|
|
Isolate* isolate,
|
|
|
|
v8::String::ExternalStringResource* resource) {
|
2013-11-26 09:45:17 +00:00
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
EnsureInitializedForIsolate(i_isolate, "v8::String::NewExternal()");
|
|
|
|
LOG_API(i_isolate, "String::NewExternal");
|
|
|
|
ENTER_V8(i_isolate);
|
2012-08-14 12:16:38 +00:00
|
|
|
CHECK(resource && resource->data());
|
2013-11-26 09:45:17 +00:00
|
|
|
i::Handle<i::String> result = NewExternalStringHandle(i_isolate, resource);
|
|
|
|
i_isolate->heap()->external_string_table()->AddString(*result);
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::ToLocal(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-04 12:23:22 +00:00
|
|
|
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()) {
|
2011-03-24 18:49:45 +00:00
|
|
|
return false; // Already an external string.
|
|
|
|
}
|
|
|
|
ENTER_V8(isolate);
|
2012-09-04 12:23:22 +00:00
|
|
|
if (isolate->string_tracker()->IsFreshUnusedString(obj)) {
|
2011-03-18 20:35:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-06-01 11:46:14 +00:00
|
|
|
if (isolate->heap()->IsInGCPostProcessing()) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-14 12:16:38 +00:00
|
|
|
CHECK(resource && resource->data());
|
2013-07-26 12:32:06 +00:00
|
|
|
|
2014-02-05 09:29:04 +00:00
|
|
|
bool result = obj->MakeExternal(resource);
|
2013-12-10 12:11:45 +00:00
|
|
|
if (result) {
|
2014-02-05 09:29:04 +00:00
|
|
|
ASSERT(obj->IsExternalString());
|
|
|
|
isolate->heap()->external_string_table()->AddString(*obj);
|
2009-02-11 23:52:52 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Local<String> v8::String::NewExternal(
|
2014-01-13 09:42:23 +00:00
|
|
|
Isolate* isolate,
|
|
|
|
v8::String::ExternalAsciiStringResource* resource) {
|
2013-11-26 09:45:17 +00:00
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
EnsureInitializedForIsolate(i_isolate, "v8::String::NewExternal()");
|
|
|
|
LOG_API(i_isolate, "String::NewExternal");
|
|
|
|
ENTER_V8(i_isolate);
|
2012-08-14 12:16:38 +00:00
|
|
|
CHECK(resource && resource->data());
|
2013-11-26 09:45:17 +00:00
|
|
|
i::Handle<i::String> result =
|
|
|
|
NewExternalAsciiStringHandle(i_isolate, resource);
|
|
|
|
i_isolate->heap()->external_string_table()->AddString(*result);
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::ToLocal(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-04 12:23:22 +00:00
|
|
|
bool v8::String::MakeExternal(
|
|
|
|
v8::String::ExternalAsciiStringResource* resource) {
|
|
|
|
i::Handle<i::String> obj = Utils::OpenHandle(this);
|
|
|
|
i::Isolate* isolate = obj->GetIsolate();
|
|
|
|
if (i::StringShape(*obj).IsExternalTwoByte()) {
|
|
|
|
return false; // Already an external string.
|
|
|
|
}
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2012-09-04 12:23:22 +00:00
|
|
|
if (isolate->string_tracker()->IsFreshUnusedString(obj)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (isolate->heap()->IsInGCPostProcessing()) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-14 12:16:38 +00:00
|
|
|
CHECK(resource && resource->data());
|
2013-07-26 12:32:06 +00:00
|
|
|
|
2014-02-05 09:29:04 +00:00
|
|
|
bool result = obj->MakeExternal(resource);
|
2013-12-10 12:11:45 +00:00
|
|
|
if (result) {
|
2014-02-05 09:29:04 +00:00
|
|
|
ASSERT(obj->IsExternalString());
|
|
|
|
isolate->heap()->external_string_table()->AddString(*obj);
|
2009-02-11 23:52:52 +00:00
|
|
|
}
|
2012-09-04 12:23:22 +00:00
|
|
|
return result;
|
2009-02-11 23:52:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-12 10:27:35 +00:00
|
|
|
bool v8::String::CanMakeExternal() {
|
2011-10-11 11:35:04 +00:00
|
|
|
if (!internal::FLAG_clever_optimizations) return false;
|
2009-08-12 10:27:35 +00:00
|
|
|
i::Handle<i::String> obj = Utils::OpenHandle(this);
|
2011-03-22 15:16:29 +00:00
|
|
|
i::Isolate* isolate = obj->GetIsolate();
|
2013-09-30 16:42:19 +00:00
|
|
|
|
|
|
|
// TODO(yangguo): Externalizing sliced/cons strings allocates.
|
|
|
|
// This rule can be removed when all code that can
|
|
|
|
// trigger an access check is handlified and therefore GC safe.
|
|
|
|
if (isolate->heap()->old_pointer_space()->Contains(*obj)) return false;
|
|
|
|
|
2011-11-23 13:08:28 +00:00
|
|
|
if (isolate->string_tracker()->IsFreshUnusedString(obj)) return false;
|
2009-08-12 10:27:35 +00:00
|
|
|
int size = obj->Size(); // Byte size of the original string.
|
2011-11-23 13:08:28 +00:00
|
|
|
if (size < i::ExternalString::kShortSize) return false;
|
2009-08-12 11:08:10 +00:00
|
|
|
i::StringShape shape(*obj);
|
|
|
|
return !shape.IsExternal();
|
2009-08-12 10:27:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-26 09:45:17 +00:00
|
|
|
Local<v8::Object> v8::Object::New(Isolate* isolate) {
|
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
EnsureInitializedForIsolate(i_isolate, "v8::Object::New()");
|
|
|
|
LOG_API(i_isolate, "Object::New");
|
|
|
|
ENTER_V8(i_isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::JSObject> obj =
|
2013-11-26 09:45:17 +00:00
|
|
|
i_isolate->factory()->NewJSObject(i_isolate->object_function());
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::ToLocal(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-26 09:45:17 +00:00
|
|
|
Local<v8::Value> v8::NumberObject::New(Isolate* isolate, double value) {
|
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
EnsureInitializedForIsolate(i_isolate, "v8::NumberObject::New()");
|
|
|
|
LOG_API(i_isolate, "NumberObject::New");
|
|
|
|
ENTER_V8(i_isolate);
|
|
|
|
i::Handle<i::Object> number = i_isolate->factory()->NewNumber(value);
|
2014-04-14 09:19:09 +00:00
|
|
|
i::Handle<i::Object> obj =
|
|
|
|
i::Object::ToObject(i_isolate, number).ToHandleChecked();
|
2011-07-14 11:00:04 +00:00
|
|
|
return Utils::ToLocal(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-30 07:05:15 +00:00
|
|
|
double v8::NumberObject::ValueOf() const {
|
2011-07-14 11:00:04 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj);
|
2014-04-15 08:30:42 +00:00
|
|
|
i::Isolate* isolate = jsvalue->GetIsolate();
|
|
|
|
LOG_API(isolate, "NumberObject::NumberValue");
|
2011-07-14 11:00:04 +00:00
|
|
|
return jsvalue->value()->Number();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<v8::Value> v8::BooleanObject::New(bool value) {
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
EnsureInitializedForIsolate(isolate, "v8::BooleanObject::New()");
|
|
|
|
LOG_API(isolate, "BooleanObject::New");
|
|
|
|
ENTER_V8(isolate);
|
2013-02-25 14:46:09 +00:00
|
|
|
i::Handle<i::Object> boolean(value
|
|
|
|
? isolate->heap()->true_value()
|
|
|
|
: isolate->heap()->false_value(),
|
|
|
|
isolate);
|
2014-04-14 09:19:09 +00:00
|
|
|
i::Handle<i::Object> obj =
|
|
|
|
i::Object::ToObject(isolate, boolean).ToHandleChecked();
|
2011-07-14 11:00:04 +00:00
|
|
|
return Utils::ToLocal(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-30 07:05:15 +00:00
|
|
|
bool v8::BooleanObject::ValueOf() const {
|
2011-07-14 11:00:04 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj);
|
2014-04-15 08:30:42 +00:00
|
|
|
i::Isolate* isolate = jsvalue->GetIsolate();
|
|
|
|
LOG_API(isolate, "BooleanObject::BooleanValue");
|
2011-07-14 11:00:04 +00:00
|
|
|
return jsvalue->value()->IsTrue();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<v8::Value> v8::StringObject::New(Handle<String> value) {
|
2014-04-15 08:30:42 +00:00
|
|
|
i::Handle<i::String> string = Utils::OpenHandle(*value);
|
|
|
|
i::Isolate* isolate = string->GetIsolate();
|
2011-07-14 11:00:04 +00:00
|
|
|
EnsureInitializedForIsolate(isolate, "v8::StringObject::New()");
|
|
|
|
LOG_API(isolate, "StringObject::New");
|
|
|
|
ENTER_V8(isolate);
|
2014-04-15 08:30:42 +00:00
|
|
|
i::Handle<i::Object> obj =
|
|
|
|
i::Object::ToObject(isolate, string).ToHandleChecked();
|
2011-07-14 11:00:04 +00:00
|
|
|
return Utils::ToLocal(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-30 07:05:15 +00:00
|
|
|
Local<v8::String> v8::StringObject::ValueOf() const {
|
2011-07-14 11:00:04 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj);
|
2014-04-15 08:30:42 +00:00
|
|
|
i::Isolate* isolate = jsvalue->GetIsolate();
|
|
|
|
LOG_API(isolate, "StringObject::StringValue");
|
2011-07-14 11:00:04 +00:00
|
|
|
return Utils::ToLocal(
|
|
|
|
i::Handle<i::String>(i::String::cast(jsvalue->value())));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-10 12:16:29 +00:00
|
|
|
Local<v8::Value> v8::SymbolObject::New(Isolate* isolate, Handle<Symbol> value) {
|
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
EnsureInitializedForIsolate(i_isolate, "v8::SymbolObject::New()");
|
|
|
|
LOG_API(i_isolate, "SymbolObject::New");
|
|
|
|
ENTER_V8(i_isolate);
|
2014-04-14 09:19:09 +00:00
|
|
|
i::Handle<i::Object> obj = i::Object::ToObject(
|
|
|
|
i_isolate, Utils::OpenHandle(*value)).ToHandleChecked();
|
2013-04-10 12:16:29 +00:00
|
|
|
return Utils::ToLocal(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-30 07:05:15 +00:00
|
|
|
Local<v8::Symbol> v8::SymbolObject::ValueOf() const {
|
2013-04-10 12:16:29 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj);
|
2014-04-15 08:30:42 +00:00
|
|
|
i::Isolate* isolate = jsvalue->GetIsolate();
|
|
|
|
LOG_API(isolate, "SymbolObject::SymbolValue");
|
2013-04-10 12:16:29 +00:00
|
|
|
return Utils::ToLocal(
|
|
|
|
i::Handle<i::Symbol>(i::Symbol::cast(jsvalue->value())));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-26 09:45:17 +00:00
|
|
|
Local<v8::Value> v8::Date::New(Isolate* isolate, double time) {
|
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
EnsureInitializedForIsolate(i_isolate, "v8::Date::New()");
|
|
|
|
LOG_API(i_isolate, "Date::New");
|
2013-04-19 13:26:47 +00:00
|
|
|
if (std::isnan(time)) {
|
2009-10-27 08:13:59 +00:00
|
|
|
// Introduce only canonical NaN value into the VM, to avoid signaling NaNs.
|
|
|
|
time = i::OS::nan_value();
|
|
|
|
}
|
2013-11-26 09:45:17 +00:00
|
|
|
ENTER_V8(i_isolate);
|
|
|
|
EXCEPTION_PREAMBLE(i_isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
i::Handle<i::Object> obj;
|
|
|
|
has_pending_exception = !i::Execution::NewDate(
|
|
|
|
i_isolate, time).ToHandle(&obj);
|
2013-11-26 09:45:17 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(i_isolate, Local<v8::Value>());
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::ToLocal(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-30 07:05:15 +00:00
|
|
|
double v8::Date::ValueOf() const {
|
2008-10-23 08:25:23 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
2012-03-09 11:11:55 +00:00
|
|
|
i::Handle<i::JSDate> jsdate = i::Handle<i::JSDate>::cast(obj);
|
2014-04-15 08:30:42 +00:00
|
|
|
i::Isolate* isolate = jsdate->GetIsolate();
|
|
|
|
LOG_API(isolate, "Date::NumberValue");
|
2012-03-09 11:11:55 +00:00
|
|
|
return jsdate->value()->Number();
|
2008-10-23 08:25:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-26 09:45:17 +00:00
|
|
|
void v8::Date::DateTimeConfigurationChangeNotification(Isolate* isolate) {
|
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
2014-03-28 08:59:25 +00:00
|
|
|
if (!i_isolate->IsInitialized()) return;
|
2013-11-26 09:45:17 +00:00
|
|
|
ON_BAILOUT(i_isolate, "v8::Date::DateTimeConfigurationChangeNotification()",
|
2011-03-18 20:35:07 +00:00
|
|
|
return);
|
2013-11-26 09:45:17 +00:00
|
|
|
LOG_API(i_isolate, "Date::DateTimeConfigurationChangeNotification");
|
|
|
|
ENTER_V8(i_isolate);
|
2010-12-17 12:45:27 +00:00
|
|
|
|
2013-11-26 09:45:17 +00:00
|
|
|
i_isolate->date_cache()->ResetDateCache();
|
2012-03-09 12:07:29 +00:00
|
|
|
|
2014-03-11 09:04:14 +00:00
|
|
|
if (!i_isolate->eternal_handles()->Exists(
|
|
|
|
i::EternalHandles::DATE_CACHE_VERSION)) {
|
2010-12-17 12:45:27 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-03-11 09:04:14 +00:00
|
|
|
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());
|
2014-03-11 09:35:24 +00:00
|
|
|
CHECK(date_cache_version->get(0)->IsSmi());
|
|
|
|
date_cache_version->set(
|
|
|
|
0,
|
|
|
|
i::Smi::FromInt(i::Smi::cast(date_cache_version->get(0))->value() + 1));
|
2010-12-17 12:45:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-04 15:04:16 +00:00
|
|
|
static i::Handle<i::String> RegExpFlagsToString(RegExp::Flags flags) {
|
2013-06-04 10:30:05 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2013-01-09 10:30:54 +00:00
|
|
|
uint8_t flags_buf[3];
|
2010-10-04 15:04:16 +00:00
|
|
|
int num_flags = 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)));
|
2013-06-04 10:30:05 +00:00
|
|
|
return isolate->factory()->InternalizeOneByteString(
|
2013-01-09 10:30:54 +00:00
|
|
|
i::Vector<const uint8_t>(flags_buf, num_flags));
|
2010-10-04 15:04:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<v8::RegExp> v8::RegExp::New(Handle<String> pattern,
|
|
|
|
Flags flags) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(*pattern)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
EnsureInitializedForIsolate(isolate, "v8::RegExp::New()");
|
|
|
|
LOG_API(isolate, "RegExp::New");
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
i::Handle<i::JSRegExp> obj;
|
|
|
|
has_pending_exception = !i::Execution::NewJSRegExp(
|
2010-10-05 11:51:41 +00:00
|
|
|
Utils::OpenHandle(*pattern),
|
2014-04-11 10:41:09 +00:00
|
|
|
RegExpFlagsToString(flags)).ToHandle(&obj);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::RegExp>());
|
2010-10-04 15:04:16 +00:00
|
|
|
return Utils::ToLocal(i::Handle<i::JSRegExp>::cast(obj));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<v8::String> v8::RegExp::GetSource() const {
|
|
|
|
i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this);
|
|
|
|
return Utils::ToLocal(i::Handle<i::String>(obj->Pattern()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Assert that the static flags cast in GetFlags is valid.
|
2014-01-13 09:42:23 +00:00
|
|
|
#define REGEXP_FLAG_ASSERT_EQ(api_flag, internal_flag) \
|
|
|
|
STATIC_ASSERT(static_cast<int>(v8::RegExp::api_flag) == \
|
2010-10-04 15:04:16 +00:00
|
|
|
static_cast<int>(i::JSRegExp::internal_flag))
|
|
|
|
REGEXP_FLAG_ASSERT_EQ(kNone, NONE);
|
|
|
|
REGEXP_FLAG_ASSERT_EQ(kGlobal, GLOBAL);
|
|
|
|
REGEXP_FLAG_ASSERT_EQ(kIgnoreCase, IGNORE_CASE);
|
|
|
|
REGEXP_FLAG_ASSERT_EQ(kMultiline, MULTILINE);
|
|
|
|
#undef REGEXP_FLAG_ASSERT_EQ
|
|
|
|
|
|
|
|
v8::RegExp::Flags v8::RegExp::GetFlags() const {
|
|
|
|
i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this);
|
|
|
|
return static_cast<RegExp::Flags>(obj->GetFlags().value());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-26 09:45:17 +00:00
|
|
|
Local<v8::Array> v8::Array::New(Isolate* isolate, int length) {
|
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
EnsureInitializedForIsolate(i_isolate, "v8::Array::New()");
|
|
|
|
LOG_API(i_isolate, "Array::New");
|
|
|
|
ENTER_V8(i_isolate);
|
2011-03-16 19:55:31 +00:00
|
|
|
int real_length = length > 0 ? length : 0;
|
2013-11-26 09:45:17 +00:00
|
|
|
i::Handle<i::JSArray> obj = i_isolate->factory()->NewJSArray(real_length);
|
2011-03-30 10:46:55 +00:00
|
|
|
i::Handle<i::Object> length_obj =
|
2013-11-26 09:45:17 +00:00
|
|
|
i_isolate->factory()->NewNumberFromInt(real_length);
|
2011-03-30 10:46:55 +00:00
|
|
|
obj->set_length(*length_obj);
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::ToLocal(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
uint32_t v8::Array::Length() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::JSArray> obj = Utils::OpenHandle(this);
|
|
|
|
i::Object* length = obj->length();
|
|
|
|
if (length->IsSmi()) {
|
|
|
|
return i::Smi::cast(length)->value();
|
|
|
|
} else {
|
|
|
|
return static_cast<uint32_t>(length->Number());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-24 11:52:52 +00:00
|
|
|
Local<Object> Array::CloneElementAt(uint32_t index) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
ON_BAILOUT(isolate, "v8::Array::CloneElementAt()", return Local<Object>());
|
2009-06-24 11:52:52 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
2012-05-23 14:24:29 +00:00
|
|
|
if (!self->HasFastObjectElements()) {
|
2009-06-24 11:52:52 +00:00
|
|
|
return Local<Object>();
|
|
|
|
}
|
2009-07-28 08:43:51 +00:00
|
|
|
i::FixedArray* elms = i::FixedArray::cast(self->elements());
|
2009-06-24 11:52:52 +00:00
|
|
|
i::Object* paragon = elms->get(index);
|
|
|
|
if (!paragon->IsJSObject()) {
|
|
|
|
return Local<Object>();
|
|
|
|
}
|
|
|
|
i::Handle<i::JSObject> paragon_handle(i::JSObject::cast(paragon));
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
|
|
|
ENTER_V8(isolate);
|
2014-04-29 07:02:11 +00:00
|
|
|
i::Handle<i::JSObject> result =
|
|
|
|
isolate->factory()->CopyJSObject(paragon_handle);
|
2009-06-24 11:52:52 +00:00
|
|
|
has_pending_exception = result.is_null();
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>());
|
2009-06-24 11:52:52 +00:00
|
|
|
return Utils::ToLocal(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-11 16:17:20 +00:00
|
|
|
bool Value::IsPromise() const {
|
|
|
|
i::Handle<i::Object> val = Utils::OpenHandle(this);
|
2014-05-06 14:48:34 +00:00
|
|
|
if (!val->IsJSObject()) return false;
|
2014-03-11 16:17:20 +00:00
|
|
|
i::Handle<i::JSObject> obj = i::Handle<i::JSObject>::cast(val);
|
|
|
|
i::Isolate* isolate = obj->GetIsolate();
|
|
|
|
LOG_API(isolate, "IsPromise");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
|
|
|
i::Handle<i::Object> argv[] = { obj };
|
2014-04-11 10:41:09 +00:00
|
|
|
i::Handle<i::Object> b;
|
|
|
|
has_pending_exception = !i::Execution::Call(
|
2014-03-11 16:17:20 +00:00
|
|
|
isolate,
|
|
|
|
handle(
|
|
|
|
isolate->context()->global_object()->native_context()->is_promise()),
|
|
|
|
isolate->factory()->undefined_value(),
|
|
|
|
ARRAY_SIZE(argv), argv,
|
2014-04-11 10:41:09 +00:00
|
|
|
false).ToHandle(&b);
|
2014-03-11 16:17:20 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, false);
|
|
|
|
return b->BooleanValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-17 09:57:25 +00:00
|
|
|
Local<Promise::Resolver> Promise::Resolver::New(Isolate* v8_isolate) {
|
2014-03-11 16:17:20 +00:00
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
|
2014-03-17 09:57:25 +00:00
|
|
|
LOG_API(isolate, "Promise::Resolver::New");
|
2014-03-11 16:17:20 +00:00
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
i::Handle<i::Object> result;
|
|
|
|
has_pending_exception = !i::Execution::Call(
|
2014-03-11 16:17:20 +00:00
|
|
|
isolate,
|
|
|
|
handle(isolate->context()->global_object()->native_context()->
|
|
|
|
promise_create()),
|
|
|
|
isolate->factory()->undefined_value(),
|
|
|
|
0, NULL,
|
2014-04-11 10:41:09 +00:00
|
|
|
false).ToHandle(&result);
|
2014-03-17 09:57:25 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<Promise::Resolver>());
|
|
|
|
return Local<Promise::Resolver>::Cast(Utils::ToLocal(result));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<Promise> Promise::Resolver::GetPromise() {
|
|
|
|
i::Handle<i::JSObject> promise = Utils::OpenHandle(this);
|
|
|
|
return Local<Promise>::Cast(Utils::ToLocal(promise));
|
2014-03-11 16:17:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-17 09:57:25 +00:00
|
|
|
void Promise::Resolver::Resolve(Handle<Value> value) {
|
2014-03-11 16:17:20 +00:00
|
|
|
i::Handle<i::JSObject> promise = Utils::OpenHandle(this);
|
|
|
|
i::Isolate* isolate = promise->GetIsolate();
|
2014-03-17 09:57:25 +00:00
|
|
|
LOG_API(isolate, "Promise::Resolver::Resolve");
|
2014-03-11 16:17:20 +00:00
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
|
|
|
i::Handle<i::Object> argv[] = { promise, Utils::OpenHandle(*value) };
|
2014-04-11 10:41:09 +00:00
|
|
|
has_pending_exception = i::Execution::Call(
|
2014-03-11 16:17:20 +00:00
|
|
|
isolate,
|
|
|
|
handle(isolate->context()->global_object()->native_context()->
|
|
|
|
promise_resolve()),
|
|
|
|
isolate->factory()->undefined_value(),
|
|
|
|
ARRAY_SIZE(argv), argv,
|
2014-04-11 10:41:09 +00:00
|
|
|
false).is_null();
|
2014-03-11 16:17:20 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, /* void */ ;);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-17 09:57:25 +00:00
|
|
|
void Promise::Resolver::Reject(Handle<Value> value) {
|
2014-03-11 16:17:20 +00:00
|
|
|
i::Handle<i::JSObject> promise = Utils::OpenHandle(this);
|
|
|
|
i::Isolate* isolate = promise->GetIsolate();
|
2014-03-17 09:57:25 +00:00
|
|
|
LOG_API(isolate, "Promise::Resolver::Reject");
|
2014-03-11 16:17:20 +00:00
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
|
|
|
i::Handle<i::Object> argv[] = { promise, Utils::OpenHandle(*value) };
|
2014-04-11 10:41:09 +00:00
|
|
|
has_pending_exception = i::Execution::Call(
|
2014-03-11 16:17:20 +00:00
|
|
|
isolate,
|
|
|
|
handle(isolate->context()->global_object()->native_context()->
|
|
|
|
promise_reject()),
|
|
|
|
isolate->factory()->undefined_value(),
|
|
|
|
ARRAY_SIZE(argv), argv,
|
2014-04-11 10:41:09 +00:00
|
|
|
false).is_null();
|
2014-03-11 16:17:20 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, /* void */ ;);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<Promise> Promise::Chain(Handle<Function> handler) {
|
|
|
|
i::Handle<i::JSObject> promise = Utils::OpenHandle(this);
|
|
|
|
i::Isolate* isolate = promise->GetIsolate();
|
|
|
|
LOG_API(isolate, "Promise::Chain");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
|
|
|
i::Handle<i::Object> argv[] = { Utils::OpenHandle(*handler) };
|
2014-04-11 10:41:09 +00:00
|
|
|
i::Handle<i::Object> result;
|
|
|
|
has_pending_exception = !i::Execution::Call(
|
2014-03-11 16:17:20 +00:00
|
|
|
isolate,
|
|
|
|
handle(isolate->context()->global_object()->native_context()->
|
|
|
|
promise_chain()),
|
|
|
|
promise,
|
|
|
|
ARRAY_SIZE(argv), argv,
|
2014-04-11 10:41:09 +00:00
|
|
|
false).ToHandle(&result);
|
2014-03-11 16:17:20 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<Promise>());
|
|
|
|
return Local<Promise>::Cast(Utils::ToLocal(result));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<Promise> Promise::Catch(Handle<Function> handler) {
|
|
|
|
i::Handle<i::JSObject> promise = Utils::OpenHandle(this);
|
|
|
|
i::Isolate* isolate = promise->GetIsolate();
|
|
|
|
LOG_API(isolate, "Promise::Catch");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
|
|
|
i::Handle<i::Object> argv[] = { Utils::OpenHandle(*handler) };
|
2014-04-11 10:41:09 +00:00
|
|
|
i::Handle<i::Object> result;
|
|
|
|
has_pending_exception = !i::Execution::Call(
|
2014-03-11 16:17:20 +00:00
|
|
|
isolate,
|
|
|
|
handle(isolate->context()->global_object()->native_context()->
|
|
|
|
promise_catch()),
|
|
|
|
promise,
|
|
|
|
ARRAY_SIZE(argv), argv,
|
2014-04-11 10:41:09 +00:00
|
|
|
false).ToHandle(&result);
|
2014-03-11 16:17:20 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<Promise>());
|
|
|
|
return Local<Promise>::Cast(Utils::ToLocal(result));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-23 10:01:42 +00:00
|
|
|
bool v8::ArrayBuffer::IsExternal() const {
|
|
|
|
return Utils::OpenHandle(this)->is_external();
|
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2013-06-11 10:41:14 +00:00
|
|
|
v8::ArrayBuffer::Contents v8::ArrayBuffer::Externalize() {
|
2013-04-25 12:02:23 +00:00
|
|
|
i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this);
|
2014-01-13 09:42:23 +00:00
|
|
|
Utils::ApiCheck(!obj->is_external(),
|
|
|
|
"v8::ArrayBuffer::Externalize",
|
|
|
|
"ArrayBuffer already externalized");
|
2013-05-23 10:01:42 +00:00
|
|
|
obj->set_is_external(true);
|
|
|
|
size_t byte_length = static_cast<size_t>(obj->byte_length()->Number());
|
2013-06-11 10:41:14 +00:00
|
|
|
Contents contents;
|
|
|
|
contents.data_ = obj->backing_store();
|
|
|
|
contents.byte_length_ = byte_length;
|
|
|
|
return contents;
|
2013-04-25 12:02:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-07 15:02:20 +00:00
|
|
|
void v8::ArrayBuffer::Neuter() {
|
|
|
|
i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this);
|
|
|
|
i::Isolate* isolate = obj->GetIsolate();
|
2014-01-13 09:42:23 +00:00
|
|
|
Utils::ApiCheck(obj->is_external(),
|
|
|
|
"v8::ArrayBuffer::Neuter",
|
|
|
|
"Only externalized ArrayBuffers can be neutered");
|
2013-06-07 15:02:20 +00:00
|
|
|
LOG_API(obj->GetIsolate(), "v8::ArrayBuffer::Neuter()");
|
|
|
|
ENTER_V8(isolate);
|
2014-03-18 10:55:29 +00:00
|
|
|
i::Runtime::NeuterArrayBuffer(obj);
|
2013-06-07 15:02:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-23 10:01:42 +00:00
|
|
|
size_t v8::ArrayBuffer::ByteLength() const {
|
2013-04-25 12:02:23 +00:00
|
|
|
i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this);
|
2013-05-23 10:01:42 +00:00
|
|
|
return static_cast<size_t>(obj->byte_length()->Number());
|
2013-04-25 12:02:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-26 09:45:17 +00:00
|
|
|
Local<ArrayBuffer> v8::ArrayBuffer::New(Isolate* isolate, size_t byte_length) {
|
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
EnsureInitializedForIsolate(i_isolate, "v8::ArrayBuffer::New(size_t)");
|
|
|
|
LOG_API(i_isolate, "v8::ArrayBuffer::New(size_t)");
|
|
|
|
ENTER_V8(i_isolate);
|
2013-04-25 12:02:23 +00:00
|
|
|
i::Handle<i::JSArrayBuffer> obj =
|
2013-11-26 09:45:17 +00:00
|
|
|
i_isolate->factory()->NewJSArrayBuffer();
|
|
|
|
i::Runtime::SetupArrayBufferAllocatingData(i_isolate, obj, byte_length);
|
2013-04-25 12:02:23 +00:00
|
|
|
return Utils::ToLocal(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-26 09:45:17 +00:00
|
|
|
Local<ArrayBuffer> v8::ArrayBuffer::New(Isolate* isolate, void* data,
|
|
|
|
size_t byte_length) {
|
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
EnsureInitializedForIsolate(i_isolate, "v8::ArrayBuffer::New(void*, size_t)");
|
|
|
|
LOG_API(i_isolate, "v8::ArrayBuffer::New(void*, size_t)");
|
|
|
|
ENTER_V8(i_isolate);
|
2013-04-25 12:02:23 +00:00
|
|
|
i::Handle<i::JSArrayBuffer> obj =
|
2013-11-26 09:45:17 +00:00
|
|
|
i_isolate->factory()->NewJSArrayBuffer();
|
|
|
|
i::Runtime::SetupArrayBuffer(i_isolate, obj, true, data, byte_length);
|
2013-04-25 12:02:23 +00:00
|
|
|
return Utils::ToLocal(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-24 11:23:50 +00:00
|
|
|
Local<ArrayBuffer> v8::ArrayBufferView::Buffer() {
|
|
|
|
i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this);
|
2014-03-26 12:50:13 +00:00
|
|
|
i::Handle<i::JSArrayBuffer> buffer;
|
|
|
|
if (obj->IsJSDataView()) {
|
|
|
|
i::Handle<i::JSDataView> data_view(i::JSDataView::cast(*obj));
|
|
|
|
ASSERT(data_view->buffer()->IsJSArrayBuffer());
|
|
|
|
buffer = i::handle(i::JSArrayBuffer::cast(data_view->buffer()));
|
|
|
|
} else {
|
|
|
|
ASSERT(obj->IsJSTypedArray());
|
|
|
|
buffer = i::JSTypedArray::cast(*obj)->GetBuffer();
|
|
|
|
}
|
2013-04-29 11:09:03 +00:00
|
|
|
return Utils::ToLocal(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-24 11:23:50 +00:00
|
|
|
size_t v8::ArrayBufferView::ByteOffset() {
|
|
|
|
i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this);
|
2013-04-29 11:09:03 +00:00
|
|
|
return static_cast<size_t>(obj->byte_offset()->Number());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-24 11:23:50 +00:00
|
|
|
size_t v8::ArrayBufferView::ByteLength() {
|
|
|
|
i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this);
|
2013-04-29 11:09:03 +00:00
|
|
|
return static_cast<size_t>(obj->byte_length()->Number());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
size_t v8::TypedArray::Length() {
|
|
|
|
i::Handle<i::JSTypedArray> obj = Utils::OpenHandle(this);
|
|
|
|
return static_cast<size_t>(obj->length()->Number());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-24 11:23:50 +00:00
|
|
|
static inline void SetupArrayBufferView(
|
|
|
|
i::Isolate* isolate,
|
|
|
|
i::Handle<i::JSArrayBufferView> obj,
|
|
|
|
i::Handle<i::JSArrayBuffer> buffer,
|
|
|
|
size_t byte_offset,
|
|
|
|
size_t byte_length) {
|
|
|
|
ASSERT(byte_offset + byte_length <=
|
2014-01-13 09:42:23 +00:00
|
|
|
static_cast<size_t>(buffer->byte_length()->Number()));
|
2013-06-24 11:23:50 +00:00
|
|
|
|
|
|
|
obj->set_buffer(*buffer);
|
2013-04-29 11:09:03 +00:00
|
|
|
|
2013-06-24 11:23:50 +00:00
|
|
|
obj->set_weak_next(buffer->weak_first_view());
|
|
|
|
buffer->set_weak_first_view(*obj);
|
|
|
|
|
|
|
|
i::Handle<i::Object> byte_offset_object =
|
2014-01-13 09:42:23 +00:00
|
|
|
isolate->factory()->NewNumberFromSize(byte_offset);
|
2013-06-24 11:23:50 +00:00
|
|
|
obj->set_byte_offset(*byte_offset_object);
|
|
|
|
|
|
|
|
i::Handle<i::Object> byte_length_object =
|
2014-01-13 09:42:23 +00:00
|
|
|
isolate->factory()->NewNumberFromSize(byte_length);
|
2013-06-24 11:23:50 +00:00
|
|
|
obj->set_byte_length(*byte_length_object);
|
|
|
|
}
|
2013-04-29 11:09:03 +00:00
|
|
|
|
|
|
|
template<typename ElementType,
|
|
|
|
ExternalArrayType array_type,
|
|
|
|
i::ElementsKind elements_kind>
|
|
|
|
i::Handle<i::JSTypedArray> NewTypedArray(
|
|
|
|
i::Isolate* isolate,
|
|
|
|
Handle<ArrayBuffer> array_buffer, size_t byte_offset, size_t length) {
|
|
|
|
i::Handle<i::JSTypedArray> obj =
|
|
|
|
isolate->factory()->NewJSTypedArray(array_type);
|
|
|
|
i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer);
|
|
|
|
|
|
|
|
ASSERT(byte_offset % sizeof(ElementType) == 0);
|
2013-06-07 10:52:11 +00:00
|
|
|
|
2013-11-14 11:52:24 +00:00
|
|
|
CHECK(length <= (std::numeric_limits<size_t>::max() / sizeof(ElementType)));
|
2014-04-07 05:54:32 +00:00
|
|
|
CHECK(length <= static_cast<size_t>(i::Smi::kMaxValue));
|
2013-11-14 11:52:24 +00:00
|
|
|
size_t byte_length = length * sizeof(ElementType);
|
2013-06-24 11:23:50 +00:00
|
|
|
SetupArrayBufferView(
|
2013-11-14 11:52:24 +00:00
|
|
|
isolate, obj, buffer, byte_offset, byte_length);
|
2013-04-29 11:09:03 +00:00
|
|
|
|
2013-06-24 11:23:50 +00:00
|
|
|
i::Handle<i::Object> length_object =
|
2014-01-13 09:42:23 +00:00
|
|
|
isolate->factory()->NewNumberFromSize(length);
|
2013-04-29 11:09:03 +00:00
|
|
|
obj->set_length(*length_object);
|
|
|
|
|
|
|
|
i::Handle<i::ExternalArray> elements =
|
|
|
|
isolate->factory()->NewExternalArray(
|
|
|
|
static_cast<int>(length), array_type,
|
|
|
|
static_cast<uint8_t*>(buffer->backing_store()) + byte_offset);
|
2014-03-26 12:50:13 +00:00
|
|
|
i::Handle<i::Map> map =
|
|
|
|
i::JSObject::GetElementsTransitionMap(obj, elements_kind);
|
2014-03-31 15:30:13 +00:00
|
|
|
i::JSObject::SetMapAndElements(obj, map, elements);
|
2013-04-29 11:09:03 +00:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-24 16:01:15 +00:00
|
|
|
#define TYPED_ARRAY_NEW(Type, type, TYPE, ctype, size) \
|
|
|
|
Local<Type##Array> Type##Array::New(Handle<ArrayBuffer> array_buffer, \
|
2013-04-29 11:09:03 +00:00
|
|
|
size_t byte_offset, size_t length) { \
|
2014-04-15 08:30:42 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(*array_buffer)->GetIsolate(); \
|
2013-04-29 11:09:03 +00:00
|
|
|
EnsureInitializedForIsolate(isolate, \
|
2014-01-24 16:01:15 +00:00
|
|
|
"v8::" #Type "Array::New(Handle<ArrayBuffer>, size_t, size_t)"); \
|
2013-04-29 11:09:03 +00:00
|
|
|
LOG_API(isolate, \
|
2014-01-24 16:01:15 +00:00
|
|
|
"v8::" #Type "Array::New(Handle<ArrayBuffer>, size_t, size_t)"); \
|
2013-04-29 11:09:03 +00:00
|
|
|
ENTER_V8(isolate); \
|
2014-04-07 05:54:32 +00:00
|
|
|
if (!Utils::ApiCheck(length <= static_cast<size_t>(i::Smi::kMaxValue), \
|
|
|
|
"v8::" #Type "Array::New(Handle<ArrayBuffer>, size_t, size_t)", \
|
|
|
|
"length exceeds max allowed value")) { \
|
|
|
|
return Local<Type##Array>(); \
|
|
|
|
} \
|
2013-04-29 11:09:03 +00:00
|
|
|
i::Handle<i::JSTypedArray> obj = \
|
2014-01-24 16:01:15 +00:00
|
|
|
NewTypedArray<ctype, v8::kExternal##Type##Array, \
|
|
|
|
i::EXTERNAL_##TYPE##_ELEMENTS>( \
|
2013-04-29 11:09:03 +00:00
|
|
|
isolate, array_buffer, byte_offset, length); \
|
2014-01-24 16:01:15 +00:00
|
|
|
return Utils::ToLocal##Type##Array(obj); \
|
|
|
|
}
|
|
|
|
|
2013-04-29 11:09:03 +00:00
|
|
|
|
2014-01-24 16:01:15 +00:00
|
|
|
TYPED_ARRAYS(TYPED_ARRAY_NEW)
|
2013-04-29 11:09:03 +00:00
|
|
|
#undef TYPED_ARRAY_NEW
|
|
|
|
|
2013-06-24 11:23:50 +00:00
|
|
|
Local<DataView> DataView::New(Handle<ArrayBuffer> array_buffer,
|
|
|
|
size_t byte_offset, size_t byte_length) {
|
2014-04-15 08:30:42 +00:00
|
|
|
i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer);
|
|
|
|
i::Isolate* isolate = buffer->GetIsolate();
|
2013-06-24 11:23:50 +00:00
|
|
|
EnsureInitializedForIsolate(
|
|
|
|
isolate, "v8::DataView::New(void*, size_t, size_t)");
|
|
|
|
LOG_API(isolate, "v8::DataView::New(void*, size_t, size_t)");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
i::Handle<i::JSDataView> obj = isolate->factory()->NewJSDataView();
|
|
|
|
SetupArrayBufferView(
|
|
|
|
isolate, obj, buffer, byte_offset, byte_length);
|
|
|
|
return Utils::ToLocal(obj);
|
|
|
|
}
|
|
|
|
|
2013-04-29 11:09:03 +00:00
|
|
|
|
2014-03-24 16:34:06 +00:00
|
|
|
Local<Symbol> v8::Symbol::New(Isolate* isolate, Local<String> name) {
|
2013-04-10 12:16:29 +00:00
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
EnsureInitializedForIsolate(i_isolate, "v8::Symbol::New()");
|
|
|
|
LOG_API(i_isolate, "Symbol::New()");
|
|
|
|
ENTER_V8(i_isolate);
|
|
|
|
i::Handle<i::Symbol> result = i_isolate->factory()->NewSymbol();
|
2014-03-24 16:34:06 +00:00
|
|
|
if (!name.IsEmpty()) result->set_name(*Utils::OpenHandle(*name));
|
2013-04-10 12:16:29 +00:00
|
|
|
return Utils::ToLocal(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-24 16:34:06 +00:00
|
|
|
Local<Symbol> v8::Symbol::For(Isolate* isolate, Local<String> name) {
|
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
i::Handle<i::String> i_name = Utils::OpenHandle(*name);
|
|
|
|
i::Handle<i::JSObject> registry = i_isolate->GetSymbolRegistry();
|
|
|
|
i::Handle<i::String> part = i_isolate->factory()->for_string();
|
|
|
|
i::Handle<i::JSObject> symbols =
|
2014-03-28 09:49:27 +00:00
|
|
|
i::Handle<i::JSObject>::cast(
|
2014-04-10 09:20:11 +00:00
|
|
|
i::Object::GetPropertyOrElement(registry, part).ToHandleChecked());
|
2014-03-28 09:49:27 +00:00
|
|
|
i::Handle<i::Object> symbol =
|
2014-04-10 09:20:11 +00:00
|
|
|
i::Object::GetPropertyOrElement(symbols, i_name).ToHandleChecked();
|
2014-03-24 16:34:06 +00:00
|
|
|
if (!symbol->IsSymbol()) {
|
|
|
|
ASSERT(symbol->IsUndefined());
|
|
|
|
symbol = i_isolate->factory()->NewSymbol();
|
|
|
|
i::Handle<i::Symbol>::cast(symbol)->set_name(*i_name);
|
2014-04-04 12:06:11 +00:00
|
|
|
i::JSObject::SetProperty(
|
|
|
|
symbols, i_name, symbol, NONE, i::STRICT).Assert();
|
2014-03-24 16:34:06 +00:00
|
|
|
}
|
|
|
|
return Utils::ToLocal(i::Handle<i::Symbol>::cast(symbol));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<Symbol> v8::Symbol::ForApi(Isolate* isolate, Local<String> name) {
|
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
i::Handle<i::String> i_name = Utils::OpenHandle(*name);
|
|
|
|
i::Handle<i::JSObject> registry = i_isolate->GetSymbolRegistry();
|
|
|
|
i::Handle<i::String> part = i_isolate->factory()->for_api_string();
|
|
|
|
i::Handle<i::JSObject> symbols =
|
2014-03-28 09:49:27 +00:00
|
|
|
i::Handle<i::JSObject>::cast(
|
2014-04-10 09:20:11 +00:00
|
|
|
i::Object::GetPropertyOrElement(registry, part).ToHandleChecked());
|
2014-03-28 09:49:27 +00:00
|
|
|
i::Handle<i::Object> symbol =
|
2014-04-10 09:20:11 +00:00
|
|
|
i::Object::GetPropertyOrElement(symbols, i_name).ToHandleChecked();
|
2014-03-24 16:34:06 +00:00
|
|
|
if (!symbol->IsSymbol()) {
|
|
|
|
ASSERT(symbol->IsUndefined());
|
|
|
|
symbol = i_isolate->factory()->NewSymbol();
|
|
|
|
i::Handle<i::Symbol>::cast(symbol)->set_name(*i_name);
|
2014-04-04 12:06:11 +00:00
|
|
|
i::JSObject::SetProperty(
|
|
|
|
symbols, i_name, symbol, NONE, i::STRICT).Assert();
|
2014-03-24 16:34:06 +00:00
|
|
|
}
|
|
|
|
return Utils::ToLocal(i::Handle<i::Symbol>::cast(symbol));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<Private> v8::Private::New(Isolate* isolate, Local<String> name) {
|
2013-04-10 12:16:29 +00:00
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
|
|
|
EnsureInitializedForIsolate(i_isolate, "v8::Private::New()");
|
|
|
|
LOG_API(i_isolate, "Private::New()");
|
2013-04-10 12:16:29 +00:00
|
|
|
ENTER_V8(i_isolate);
|
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
|
|
|
i::Handle<i::Symbol> symbol = i_isolate->factory()->NewPrivateSymbol();
|
2014-03-10 08:20:56 +00:00
|
|
|
if (!name.IsEmpty()) symbol->set_name(*Utils::OpenHandle(*name));
|
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
|
|
|
Local<Symbol> result = Utils::ToLocal(symbol);
|
2013-11-13 12:18:52 +00:00
|
|
|
return v8::Handle<Private>(reinterpret_cast<Private*>(*result));
|
2013-04-10 12:16:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-24 16:34:06 +00:00
|
|
|
Local<Private> v8::Private::ForApi(Isolate* isolate, Local<String> name) {
|
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
i::Handle<i::String> i_name = Utils::OpenHandle(*name);
|
|
|
|
i::Handle<i::JSObject> registry = i_isolate->GetSymbolRegistry();
|
|
|
|
i::Handle<i::String> part = i_isolate->factory()->private_api_string();
|
|
|
|
i::Handle<i::JSObject> privates =
|
2014-03-28 09:49:27 +00:00
|
|
|
i::Handle<i::JSObject>::cast(
|
2014-04-10 09:20:11 +00:00
|
|
|
i::Object::GetPropertyOrElement(registry, part).ToHandleChecked());
|
2014-03-28 09:49:27 +00:00
|
|
|
i::Handle<i::Object> symbol =
|
2014-04-10 09:20:11 +00:00
|
|
|
i::Object::GetPropertyOrElement(privates, i_name).ToHandleChecked();
|
2014-03-24 16:34:06 +00:00
|
|
|
if (!symbol->IsSymbol()) {
|
|
|
|
ASSERT(symbol->IsUndefined());
|
|
|
|
symbol = i_isolate->factory()->NewPrivateSymbol();
|
|
|
|
i::Handle<i::Symbol>::cast(symbol)->set_name(*i_name);
|
2014-04-04 12:06:11 +00:00
|
|
|
i::JSObject::SetProperty(
|
|
|
|
privates, i_name, symbol, NONE, i::STRICT).Assert();
|
2014-03-24 16:34:06 +00:00
|
|
|
}
|
|
|
|
Local<Symbol> result = Utils::ToLocal(i::Handle<i::Symbol>::cast(symbol));
|
|
|
|
return v8::Handle<Private>(reinterpret_cast<Private*>(*result));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-22 06:35:38 +00:00
|
|
|
Local<Number> v8::Number::New(Isolate* isolate, double value) {
|
|
|
|
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
ASSERT(internal_isolate->IsInitialized());
|
2013-04-19 13:26:47 +00:00
|
|
|
if (std::isnan(value)) {
|
2009-10-27 08:13:59 +00:00
|
|
|
// Introduce only canonical NaN value into the VM, to avoid signaling NaNs.
|
|
|
|
value = i::OS::nan_value();
|
|
|
|
}
|
2013-05-22 06:35:38 +00:00
|
|
|
ENTER_V8(internal_isolate);
|
|
|
|
i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value);
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::NumberToLocal(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-26 09:45:17 +00:00
|
|
|
Local<Integer> v8::Integer::New(Isolate* isolate, int32_t value) {
|
2012-10-19 11:15:04 +00:00
|
|
|
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
ASSERT(internal_isolate->IsInitialized());
|
2008-07-03 15:10:15 +00:00
|
|
|
if (i::Smi::IsValid(value)) {
|
2011-03-18 20:35:07 +00:00
|
|
|
return Utils::IntegerToLocal(i::Handle<i::Object>(i::Smi::FromInt(value),
|
2012-10-19 11:15:04 +00:00
|
|
|
internal_isolate));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2012-10-19 11:15:04 +00:00
|
|
|
ENTER_V8(internal_isolate);
|
|
|
|
i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value);
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::IntegerToLocal(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-26 09:45:17 +00:00
|
|
|
Local<Integer> v8::Integer::NewFromUnsigned(Isolate* isolate, uint32_t value) {
|
2012-10-19 11:15:04 +00:00
|
|
|
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
ASSERT(internal_isolate->IsInitialized());
|
2009-10-16 12:51:18 +00:00
|
|
|
bool fits_into_int32_t = (value & (1 << 31)) == 0;
|
|
|
|
if (fits_into_int32_t) {
|
2014-01-03 14:31:17 +00:00
|
|
|
return Integer::New(isolate, static_cast<int32_t>(value));
|
2009-10-16 12:51:18 +00:00
|
|
|
}
|
2012-10-19 11:15:04 +00:00
|
|
|
ENTER_V8(internal_isolate);
|
|
|
|
i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value);
|
2009-10-16 12:51:18 +00:00
|
|
|
return Utils::IntegerToLocal(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-27 14:35:39 +00:00
|
|
|
bool V8::AddMessageListener(MessageCallback that, Handle<Value> data) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
EnsureInitializedForIsolate(isolate, "v8::V8::AddMessageListener()");
|
|
|
|
ON_BAILOUT(isolate, "v8::V8::AddMessageListener()", return false);
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
|
|
|
NeanderArray listeners(isolate->factory()->message_listeners());
|
2014-01-08 14:44:30 +00:00
|
|
|
NeanderObject obj(isolate, 2);
|
2013-02-27 14:35:39 +00:00
|
|
|
obj.set(0, *isolate->factory()->NewForeign(FUNCTION_ADDR(that)));
|
|
|
|
obj.set(1, data.IsEmpty() ? isolate->heap()->undefined_value()
|
2014-01-13 09:42:23 +00:00
|
|
|
: *Utils::OpenHandle(*data));
|
2013-02-27 14:35:39 +00:00
|
|
|
listeners.add(obj.value());
|
2008-07-03 15:10:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void V8::RemoveMessageListeners(MessageCallback that) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
EnsureInitializedForIsolate(isolate, "v8::V8::RemoveMessageListener()");
|
|
|
|
ON_BAILOUT(isolate, "v8::V8::RemoveMessageListeners()", return);
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
|
|
|
NeanderArray listeners(isolate->factory()->message_listeners());
|
2008-07-03 15:10:15 +00:00
|
|
|
for (int i = 0; i < listeners.length(); i++) {
|
|
|
|
if (listeners.get(i)->IsUndefined()) continue; // skip deleted ones
|
|
|
|
|
2013-02-27 14:35:39 +00:00
|
|
|
NeanderObject listener(i::JSObject::cast(listeners.get(i)));
|
|
|
|
i::Handle<i::Foreign> callback_obj(i::Foreign::cast(listener.get(0)));
|
2011-10-28 12:37:29 +00:00
|
|
|
if (callback_obj->foreign_address() == FUNCTION_ADDR(that)) {
|
2011-03-28 09:11:14 +00:00
|
|
|
listeners.set(i, isolate->heap()->undefined_value());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-12 13:17:27 +00:00
|
|
|
void V8::SetCaptureStackTraceForUncaughtExceptions(
|
2014-01-13 09:42:23 +00:00
|
|
|
bool capture,
|
|
|
|
int frame_limit,
|
|
|
|
StackTrace::StackTraceOptions options) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate::Current()->SetCaptureStackTraceForUncaughtExceptions(
|
2010-07-12 13:17:27 +00:00
|
|
|
capture,
|
|
|
|
frame_limit,
|
|
|
|
options);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void V8::SetCounterFunction(CounterLookupCallback callback) {
|
2014-04-15 10:45:34 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::UncheckedCurrent();
|
2014-04-16 08:42:08 +00:00
|
|
|
// TODO(svenpanne) The Isolate should really be a parameter.
|
|
|
|
if (isolate == NULL) return;
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->stats_table()->SetCounterFunction(callback);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2009-03-13 16:06:31 +00:00
|
|
|
void V8::SetCreateHistogramFunction(CreateHistogramCallback callback) {
|
2014-04-15 10:45:34 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::UncheckedCurrent();
|
2014-04-16 08:42:08 +00:00
|
|
|
// TODO(svenpanne) The Isolate should really be a parameter.
|
|
|
|
if (isolate == NULL) return;
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->stats_table()->SetCreateHistogramFunction(callback);
|
2012-08-01 12:51:24 +00:00
|
|
|
isolate->InitializeLoggingAndCounters();
|
|
|
|
isolate->counters()->ResetHistograms();
|
2009-03-13 16:06:31 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2009-03-13 16:06:31 +00:00
|
|
|
void V8::SetAddHistogramSampleFunction(AddHistogramSampleCallback callback) {
|
2014-04-15 10:45:34 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::UncheckedCurrent();
|
2014-04-16 08:42:08 +00:00
|
|
|
// TODO(svenpanne) The Isolate should really be a parameter.
|
|
|
|
if (isolate == NULL) return;
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->stats_table()->
|
|
|
|
SetAddHistogramSampleFunction(callback);
|
2009-03-13 16:06:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
void V8::SetFailedAccessCheckCallbackFunction(
|
2014-01-13 09:42:23 +00:00
|
|
|
FailedAccessCheckCallback callback) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
isolate->SetFailedAccessCheckCallback(callback);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 10:14:10 +00:00
|
|
|
|
2013-11-21 08:06:02 +00:00
|
|
|
int64_t Isolate::AdjustAmountOfExternalAllocatedMemory(
|
|
|
|
int64_t change_in_bytes) {
|
2013-03-13 13:15:09 +00:00
|
|
|
i::Heap* heap = reinterpret_cast<i::Isolate*>(this)->heap();
|
|
|
|
return heap->AdjustAmountOfExternalAllocatedMemory(change_in_bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-02 08:03:01 +00:00
|
|
|
HeapProfiler* Isolate::GetHeapProfiler() {
|
|
|
|
i::HeapProfiler* heap_profiler =
|
|
|
|
reinterpret_cast<i::Isolate*>(this)->heap_profiler();
|
|
|
|
return reinterpret_cast<HeapProfiler*>(heap_profiler);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-02 08:16:53 +00:00
|
|
|
CpuProfiler* Isolate::GetCpuProfiler() {
|
|
|
|
i::CpuProfiler* cpu_profiler =
|
|
|
|
reinterpret_cast<i::Isolate*>(this)->cpu_profiler();
|
|
|
|
return reinterpret_cast<CpuProfiler*>(cpu_profiler);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-23 11:25:52 +00:00
|
|
|
bool Isolate::InContext() {
|
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
|
|
|
|
return isolate->context() != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-09 07:34:32 +00:00
|
|
|
v8::Local<v8::Context> Isolate::GetCurrentContext() {
|
2013-09-23 11:25:52 +00:00
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
|
|
|
|
i::Context* context = isolate->context();
|
2013-06-21 12:34:47 +00:00
|
|
|
if (context == NULL) return Local<Context>();
|
|
|
|
i::Context* native_context = context->global_object()->native_context();
|
|
|
|
if (native_context == NULL) return Local<Context>();
|
|
|
|
return Utils::ToLocal(i::Handle<i::Context>(native_context));
|
2013-04-09 07:34:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-23 11:25:52 +00:00
|
|
|
v8::Local<v8::Context> Isolate::GetCallingContext() {
|
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
|
|
|
|
i::Handle<i::Object> calling = isolate->GetCallingNativeContext();
|
|
|
|
if (calling.is_null()) return Local<Context>();
|
|
|
|
return Utils::ToLocal(i::Handle<i::Context>::cast(calling));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
v8::Local<v8::Context> Isolate::GetEnteredContext() {
|
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
|
|
|
|
i::Handle<i::Object> last =
|
|
|
|
isolate->handle_scope_implementer()->LastEnteredContext();
|
|
|
|
if (last.is_null()) return Local<Context>();
|
|
|
|
return Utils::ToLocal(i::Handle<i::Context>::cast(last));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-26 07:37:59 +00:00
|
|
|
v8::Local<Value> Isolate::ThrowException(v8::Local<v8::Value> value) {
|
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
// If we're passed an empty handle, we throw an undefined exception
|
|
|
|
// to deal more gracefully with out of memory situations.
|
|
|
|
if (value.IsEmpty()) {
|
|
|
|
isolate->ScheduleThrow(isolate->heap()->undefined_value());
|
|
|
|
} else {
|
|
|
|
isolate->ScheduleThrow(*Utils::OpenHandle(*value));
|
|
|
|
}
|
2013-09-26 08:21:48 +00:00
|
|
|
return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
|
2013-09-26 07:37:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-17 11:48:03 +00:00
|
|
|
void Isolate::SetObjectGroupId(internal::Object** object, UniqueId id) {
|
2013-04-24 15:59:23 +00:00
|
|
|
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this);
|
|
|
|
internal_isolate->global_handles()->SetObjectGroupId(
|
2013-10-17 11:48:03 +00:00
|
|
|
v8::internal::Handle<v8::internal::Object>(object).location(),
|
2013-06-13 09:27:09 +00:00
|
|
|
id);
|
2013-04-24 15:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-17 11:48:03 +00:00
|
|
|
void Isolate::SetReferenceFromGroup(UniqueId id, internal::Object** object) {
|
2013-04-24 15:59:23 +00:00
|
|
|
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this);
|
2013-06-13 09:27:09 +00:00
|
|
|
internal_isolate->global_handles()->SetReferenceFromGroup(
|
|
|
|
id,
|
2013-10-17 11:48:03 +00:00
|
|
|
v8::internal::Handle<v8::internal::Object>(object).location());
|
2013-04-24 15:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-17 11:48:03 +00:00
|
|
|
void Isolate::SetReference(internal::Object** parent,
|
|
|
|
internal::Object** child) {
|
2013-04-24 15:59:23 +00:00
|
|
|
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this);
|
2013-10-17 11:48:03 +00:00
|
|
|
i::Object** parent_location =
|
|
|
|
v8::internal::Handle<v8::internal::Object>(parent).location();
|
2013-04-24 15:59:23 +00:00
|
|
|
internal_isolate->global_handles()->SetReference(
|
2013-06-13 09:27:09 +00:00
|
|
|
reinterpret_cast<i::HeapObject**>(parent_location),
|
2013-10-17 11:48:03 +00:00
|
|
|
v8::internal::Handle<v8::internal::Object>(child).location());
|
2013-04-24 15:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-17 12:37:22 +00:00
|
|
|
void Isolate::AddGCPrologueCallback(GCPrologueCallback callback,
|
|
|
|
GCType gc_type) {
|
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
|
|
|
|
isolate->heap()->AddGCPrologueCallback(callback, gc_type);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-17 12:37:22 +00:00
|
|
|
void Isolate::RemoveGCPrologueCallback(GCPrologueCallback callback) {
|
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
|
|
|
|
isolate->heap()->RemoveGCPrologueCallback(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::AddGCEpilogueCallback(GCEpilogueCallback callback,
|
|
|
|
GCType gc_type) {
|
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
|
|
|
|
isolate->heap()->AddGCEpilogueCallback(callback, gc_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::RemoveGCEpilogueCallback(GCEpilogueCallback callback) {
|
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
|
|
|
|
isolate->heap()->RemoveGCEpilogueCallback(callback);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-23 13:11:44 +00:00
|
|
|
void V8::AddGCPrologueCallback(GCPrologueCallback callback, GCType gc_type) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2013-09-17 12:37:22 +00:00
|
|
|
isolate->heap()->AddGCPrologueCallback(
|
|
|
|
reinterpret_cast<v8::Isolate::GCPrologueCallback>(callback),
|
|
|
|
gc_type,
|
|
|
|
false);
|
2010-03-23 13:11:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void V8::RemoveGCPrologueCallback(GCPrologueCallback callback) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2013-09-17 12:37:22 +00:00
|
|
|
isolate->heap()->RemoveGCPrologueCallback(
|
|
|
|
reinterpret_cast<v8::Isolate::GCPrologueCallback>(callback));
|
2010-03-23 13:11:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void V8::AddGCEpilogueCallback(GCEpilogueCallback callback, GCType gc_type) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2013-09-17 12:37:22 +00:00
|
|
|
isolate->heap()->AddGCEpilogueCallback(
|
|
|
|
reinterpret_cast<v8::Isolate::GCEpilogueCallback>(callback),
|
|
|
|
gc_type,
|
|
|
|
false);
|
2010-03-23 13:11:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void V8::RemoveGCEpilogueCallback(GCEpilogueCallback callback) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2013-09-17 12:37:22 +00:00
|
|
|
isolate->heap()->RemoveGCEpilogueCallback(
|
|
|
|
reinterpret_cast<v8::Isolate::GCEpilogueCallback>(callback));
|
2010-03-23 13:11:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-03 11:31:58 +00:00
|
|
|
void V8::AddMemoryAllocationCallback(MemoryAllocationCallback callback,
|
|
|
|
ObjectSpace space,
|
|
|
|
AllocationAction action) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
isolate->memory_allocator()->AddMemoryAllocationCallback(
|
|
|
|
callback, space, action);
|
2010-09-03 11:31:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void V8::RemoveMemoryAllocationCallback(MemoryAllocationCallback callback) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
isolate->memory_allocator()->RemoveMemoryAllocationCallback(
|
|
|
|
callback);
|
2010-09-03 11:31:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
void V8::TerminateExecution(Isolate* isolate) {
|
2014-05-09 09:13:12 +00:00
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
i_isolate->stack_guard()->RequestTerminateExecution();
|
2009-08-19 15:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-10 09:54:04 +00:00
|
|
|
bool V8::IsExecutionTerminating(Isolate* isolate) {
|
|
|
|
i::Isolate* i_isolate = isolate != NULL ?
|
|
|
|
reinterpret_cast<i::Isolate*>(isolate) : i::Isolate::Current();
|
|
|
|
return IsExecutionTerminatingCheck(i_isolate);
|
2010-03-04 12:13:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-22 15:01:45 +00:00
|
|
|
void V8::CancelTerminateExecution(Isolate* isolate) {
|
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
2014-05-09 09:13:12 +00:00
|
|
|
i_isolate->stack_guard()->ClearTerminateExecution();
|
|
|
|
i_isolate->CancelTerminateExecution();
|
2013-04-22 15:01:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-19 16:45:58 +00:00
|
|
|
void Isolate::RequestInterrupt(InterruptCallback callback, void* data) {
|
2014-05-09 09:13:12 +00:00
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(this);
|
|
|
|
i_isolate->set_api_interrupt_callback(callback);
|
|
|
|
i_isolate->set_api_interrupt_callback_data(data);
|
|
|
|
i_isolate->stack_guard()->RequestApiInterrupt();
|
2013-12-19 16:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::ClearInterrupt() {
|
2014-05-09 09:13:12 +00:00
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(this);
|
|
|
|
i_isolate->stack_guard()->ClearApiInterrupt();
|
|
|
|
i_isolate->set_api_interrupt_callback(NULL);
|
|
|
|
i_isolate->set_api_interrupt_callback_data(NULL);
|
2013-12-19 16:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-13 12:03:31 +00:00
|
|
|
void Isolate::RequestGarbageCollectionForTesting(GarbageCollectionType type) {
|
|
|
|
CHECK(i::FLAG_expose_gc);
|
|
|
|
if (type == kMinorGarbageCollection) {
|
|
|
|
reinterpret_cast<i::Isolate*>(this)->heap()->CollectGarbage(
|
|
|
|
i::NEW_SPACE, "Isolate::RequestGarbageCollection",
|
|
|
|
kGCCallbackFlagForced);
|
|
|
|
} else {
|
|
|
|
ASSERT_EQ(kFullGarbageCollection, type);
|
|
|
|
reinterpret_cast<i::Isolate*>(this)->heap()->CollectAllGarbage(
|
2014-01-20 15:44:03 +00:00
|
|
|
i::Heap::kAbortIncrementalMarkingMask,
|
|
|
|
"Isolate::RequestGarbageCollection", kGCCallbackFlagForced);
|
2014-01-13 12:03:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* Isolate::GetCurrent() {
|
2012-03-30 14:30:46 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::UncheckedCurrent();
|
2011-03-18 20:35:07 +00:00
|
|
|
return reinterpret_cast<Isolate*>(isolate);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Isolate* Isolate::New() {
|
|
|
|
i::Isolate* isolate = new i::Isolate();
|
|
|
|
return reinterpret_cast<Isolate*>(isolate);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::Dispose() {
|
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
|
2014-01-13 09:42:23 +00:00
|
|
|
if (!Utils::ApiCheck(!isolate->IsInUse(),
|
|
|
|
"v8::Isolate::Dispose()",
|
|
|
|
"Disposing the isolate that is entered by a thread.")) {
|
2011-03-18 20:35:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
isolate->TearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::Enter() {
|
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
|
|
|
|
isolate->Enter();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::Exit() {
|
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
|
|
|
|
isolate->Exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-19 11:31:43 +00:00
|
|
|
Isolate::DisallowJavascriptExecutionScope::DisallowJavascriptExecutionScope(
|
2014-03-19 13:06:53 +00:00
|
|
|
Isolate* isolate,
|
|
|
|
Isolate::DisallowJavascriptExecutionScope::OnFailure on_failure)
|
|
|
|
: on_failure_(on_failure) {
|
2014-03-19 11:31:43 +00:00
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
2014-03-19 13:06:53 +00:00
|
|
|
if (on_failure_ == CRASH_ON_FAILURE) {
|
|
|
|
internal_ = reinterpret_cast<void*>(
|
|
|
|
new i::DisallowJavascriptExecution(i_isolate));
|
|
|
|
} else {
|
|
|
|
ASSERT_EQ(THROW_ON_FAILURE, on_failure);
|
|
|
|
internal_ = reinterpret_cast<void*>(
|
|
|
|
new i::ThrowOnJavascriptExecution(i_isolate));
|
|
|
|
}
|
2014-03-19 11:31:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Isolate::DisallowJavascriptExecutionScope::~DisallowJavascriptExecutionScope() {
|
2014-03-19 13:06:53 +00:00
|
|
|
if (on_failure_ == CRASH_ON_FAILURE) {
|
|
|
|
delete reinterpret_cast<i::DisallowJavascriptExecution*>(internal_);
|
|
|
|
} else {
|
|
|
|
delete reinterpret_cast<i::ThrowOnJavascriptExecution*>(internal_);
|
|
|
|
}
|
2014-03-19 11:31:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Isolate::AllowJavascriptExecutionScope::AllowJavascriptExecutionScope(
|
|
|
|
Isolate* isolate) {
|
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
2014-03-19 13:06:53 +00:00
|
|
|
internal_assert_ = reinterpret_cast<void*>(
|
2014-03-19 11:31:43 +00:00
|
|
|
new i::AllowJavascriptExecution(i_isolate));
|
2014-03-19 13:06:53 +00:00
|
|
|
internal_throws_ = reinterpret_cast<void*>(
|
|
|
|
new i::NoThrowOnJavascriptExecution(i_isolate));
|
2014-03-19 11:31:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Isolate::AllowJavascriptExecutionScope::~AllowJavascriptExecutionScope() {
|
2014-03-19 13:06:53 +00:00
|
|
|
delete reinterpret_cast<i::AllowJavascriptExecution*>(internal_assert_);
|
|
|
|
delete reinterpret_cast<i::NoThrowOnJavascriptExecution*>(internal_throws_);
|
2014-03-19 11:31:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-02 19:30:54 +00:00
|
|
|
Isolate::SuppressMicrotaskExecutionScope::SuppressMicrotaskExecutionScope(
|
|
|
|
Isolate* isolate)
|
|
|
|
: isolate_(reinterpret_cast<i::Isolate*>(isolate)) {
|
|
|
|
isolate_->handle_scope_implementer()->IncrementCallDepth();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Isolate::SuppressMicrotaskExecutionScope::~SuppressMicrotaskExecutionScope() {
|
|
|
|
isolate_->handle_scope_implementer()->DecrementCallDepth();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-08 12:41:55 +00:00
|
|
|
void Isolate::GetHeapStatistics(HeapStatistics* heap_statistics) {
|
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
|
2013-03-27 10:33:25 +00:00
|
|
|
if (!isolate->IsInitialized()) {
|
|
|
|
heap_statistics->total_heap_size_ = 0;
|
|
|
|
heap_statistics->total_heap_size_executable_ = 0;
|
|
|
|
heap_statistics->total_physical_size_ = 0;
|
|
|
|
heap_statistics->used_heap_size_ = 0;
|
|
|
|
heap_statistics->heap_size_limit_ = 0;
|
|
|
|
return;
|
|
|
|
}
|
2013-02-08 12:41:55 +00:00
|
|
|
i::Heap* heap = isolate->heap();
|
|
|
|
heap_statistics->total_heap_size_ = heap->CommittedMemory();
|
|
|
|
heap_statistics->total_heap_size_executable_ =
|
|
|
|
heap->CommittedMemoryExecutable();
|
|
|
|
heap_statistics->total_physical_size_ = heap->CommittedPhysicalMemory();
|
|
|
|
heap_statistics->used_heap_size_ = heap->SizeOfObjects();
|
|
|
|
heap_statistics->heap_size_limit_ = heap->MaxReserved();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-10 08:56:48 +00:00
|
|
|
void Isolate::SetEventLogger(LogEventCallback that) {
|
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
|
|
|
|
isolate->set_event_logger(that);
|
|
|
|
}
|
|
|
|
|
2014-04-03 07:51:27 +00:00
|
|
|
|
|
|
|
void Isolate::AddCallCompletedCallback(CallCompletedCallback callback) {
|
|
|
|
if (callback == NULL) return;
|
2014-04-25 13:49:22 +00:00
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
|
|
|
|
isolate->AddCallCompletedCallback(callback);
|
2014-04-03 07:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::RemoveCallCompletedCallback(CallCompletedCallback callback) {
|
2014-04-25 13:49:22 +00:00
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
|
|
|
|
isolate->RemoveCallCompletedCallback(callback);
|
2014-04-03 07:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-02 19:30:54 +00:00
|
|
|
void Isolate::RunMicrotasks() {
|
2014-05-19 07:57:04 +00:00
|
|
|
reinterpret_cast<i::Isolate*>(this)->RunMicrotasks();
|
2014-05-02 19:30:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::EnqueueMicrotask(Handle<Function> microtask) {
|
2014-05-19 07:57:04 +00:00
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
|
|
|
|
isolate->EnqueueMicrotask(Utils::OpenHandle(*microtask));
|
2014-05-02 19:30:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::SetAutorunMicrotasks(bool autorun) {
|
|
|
|
reinterpret_cast<i::Isolate*>(this)->set_autorun_microtasks(autorun);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-12 06:27:38 +00:00
|
|
|
bool Isolate::WillAutorunMicrotasks() const {
|
|
|
|
return reinterpret_cast<const i::Isolate*>(this)->autorun_microtasks();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-09 10:39:02 +00:00
|
|
|
String::Utf8Value::Utf8Value(v8::Handle<v8::Value> obj)
|
|
|
|
: str_(NULL), length_(0) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2011-05-09 10:39:02 +00:00
|
|
|
if (obj.IsEmpty()) return;
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
|
|
|
i::HandleScope scope(isolate);
|
2012-09-14 11:43:46 +00:00
|
|
|
TryCatch try_catch;
|
2008-09-10 11:41:48 +00:00
|
|
|
Handle<String> str = obj->ToString();
|
2011-05-09 10:39:02 +00:00
|
|
|
if (str.IsEmpty()) return;
|
2012-03-12 12:35:28 +00:00
|
|
|
i::Handle<i::String> i_str = Utils::OpenHandle(*str);
|
2013-01-03 12:59:54 +00:00
|
|
|
length_ = v8::Utf8Length(*i_str, isolate);
|
2011-05-09 10:39:02 +00:00
|
|
|
str_ = i::NewArray<char>(length_ + 1);
|
|
|
|
str->WriteUtf8(str_);
|
2008-09-10 11:41:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String::Utf8Value::~Utf8Value() {
|
|
|
|
i::DeleteArray(str_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-09 10:39:02 +00:00
|
|
|
String::Value::Value(v8::Handle<v8::Value> obj)
|
|
|
|
: str_(NULL), length_(0) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2011-05-09 10:39:02 +00:00
|
|
|
if (obj.IsEmpty()) return;
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
|
|
|
i::HandleScope scope(isolate);
|
2012-09-14 11:43:46 +00:00
|
|
|
TryCatch try_catch;
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<String> str = obj->ToString();
|
2011-05-09 10:39:02 +00:00
|
|
|
if (str.IsEmpty()) return;
|
|
|
|
length_ = str->Length();
|
|
|
|
str_ = i::NewArray<uint16_t>(length_ + 1);
|
|
|
|
str->Write(str_);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String::Value::~Value() {
|
|
|
|
i::DeleteArray(str_);
|
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Local<Value> Exception::RangeError(v8::Handle<v8::String> raw_message) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
LOG_API(isolate, "RangeError");
|
|
|
|
ON_BAILOUT(isolate, "v8::Exception::RangeError()", return Local<Value>());
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Object* error;
|
|
|
|
{
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::String> message = Utils::OpenHandle(*raw_message);
|
2011-03-23 09:02:15 +00:00
|
|
|
i::Handle<i::Object> result = isolate->factory()->NewRangeError(message);
|
2008-07-03 15:10:15 +00:00
|
|
|
error = *result;
|
|
|
|
}
|
2013-02-25 14:46:09 +00:00
|
|
|
i::Handle<i::Object> result(error, isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::ToLocal(result);
|
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Local<Value> Exception::ReferenceError(v8::Handle<v8::String> raw_message) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
LOG_API(isolate, "ReferenceError");
|
|
|
|
ON_BAILOUT(isolate, "v8::Exception::ReferenceError()", return Local<Value>());
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Object* error;
|
|
|
|
{
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::String> message = Utils::OpenHandle(*raw_message);
|
2011-03-23 09:02:15 +00:00
|
|
|
i::Handle<i::Object> result =
|
|
|
|
isolate->factory()->NewReferenceError(message);
|
2008-07-03 15:10:15 +00:00
|
|
|
error = *result;
|
|
|
|
}
|
2013-02-25 14:46:09 +00:00
|
|
|
i::Handle<i::Object> result(error, isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::ToLocal(result);
|
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Local<Value> Exception::SyntaxError(v8::Handle<v8::String> raw_message) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
LOG_API(isolate, "SyntaxError");
|
|
|
|
ON_BAILOUT(isolate, "v8::Exception::SyntaxError()", return Local<Value>());
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Object* error;
|
|
|
|
{
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::String> message = Utils::OpenHandle(*raw_message);
|
2011-03-23 09:02:15 +00:00
|
|
|
i::Handle<i::Object> result = isolate->factory()->NewSyntaxError(message);
|
2008-07-03 15:10:15 +00:00
|
|
|
error = *result;
|
|
|
|
}
|
2013-02-25 14:46:09 +00:00
|
|
|
i::Handle<i::Object> result(error, isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::ToLocal(result);
|
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Local<Value> Exception::TypeError(v8::Handle<v8::String> raw_message) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
LOG_API(isolate, "TypeError");
|
|
|
|
ON_BAILOUT(isolate, "v8::Exception::TypeError()", return Local<Value>());
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Object* error;
|
|
|
|
{
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::String> message = Utils::OpenHandle(*raw_message);
|
2011-03-23 09:02:15 +00:00
|
|
|
i::Handle<i::Object> result = isolate->factory()->NewTypeError(message);
|
2008-07-03 15:10:15 +00:00
|
|
|
error = *result;
|
|
|
|
}
|
2013-02-25 14:46:09 +00:00
|
|
|
i::Handle<i::Object> result(error, isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::ToLocal(result);
|
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Local<Value> Exception::Error(v8::Handle<v8::String> raw_message) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
LOG_API(isolate, "Error");
|
|
|
|
ON_BAILOUT(isolate, "v8::Exception::Error()", return Local<Value>());
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Object* error;
|
|
|
|
{
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::String> message = Utils::OpenHandle(*raw_message);
|
2011-03-23 09:02:15 +00:00
|
|
|
i::Handle<i::Object> result = isolate->factory()->NewError(message);
|
2008-07-03 15:10:15 +00:00
|
|
|
error = *result;
|
|
|
|
}
|
2013-02-25 14:46:09 +00:00
|
|
|
i::Handle<i::Object> result(error, isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::ToLocal(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// --- D e b u g S u p p o r t ---
|
|
|
|
|
2014-05-14 08:07:21 +00:00
|
|
|
bool Debug::SetDebugEventListener(EventCallback that, Handle<Value> data) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2014-05-14 08:07:21 +00:00
|
|
|
EnsureInitializedForIsolate(isolate, "v8::Debug::SetDebugEventListener()");
|
|
|
|
ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener()", return false);
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2011-05-19 11:47:34 +00:00
|
|
|
i::Handle<i::Object> foreign = isolate->factory()->undefined_value();
|
2009-02-13 12:36:58 +00:00
|
|
|
if (that != NULL) {
|
2011-05-19 11:47:34 +00:00
|
|
|
foreign = isolate->factory()->NewForeign(FUNCTION_ADDR(that));
|
2009-02-13 12:36:58 +00:00
|
|
|
}
|
2014-05-27 13:20:58 +00:00
|
|
|
isolate->debug()->SetEventListener(foreign,
|
|
|
|
Utils::OpenHandle(*data, true));
|
2008-07-03 15:10:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
void Debug::DebugBreak(Isolate* isolate) {
|
2014-05-09 09:13:12 +00:00
|
|
|
reinterpret_cast<i::Isolate*>(isolate)->stack_guard()->RequestDebugBreak();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
void Debug::CancelDebugBreak(Isolate* isolate) {
|
2014-04-15 07:47:33 +00:00
|
|
|
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
2014-05-09 09:13:12 +00:00
|
|
|
internal_isolate->stack_guard()->ClearDebugBreak();
|
2010-09-27 15:09:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-15 07:47:33 +00:00
|
|
|
void Debug::DebugBreakForCommand(Isolate* isolate, ClientData* data) {
|
|
|
|
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
2014-05-27 13:20:58 +00:00
|
|
|
internal_isolate->debug()->EnqueueDebugCommand(data);
|
2010-07-14 08:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-14 08:07:21 +00:00
|
|
|
void Debug::SetMessageHandler(v8::Debug::MessageHandler handler) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
EnsureInitializedForIsolate(isolate, "v8::Debug::SetMessageHandler");
|
|
|
|
ENTER_V8(isolate);
|
2014-05-27 13:20:58 +00:00
|
|
|
isolate->debug()->SetMessageHandler(handler);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-19 07:33:45 +00:00
|
|
|
void Debug::SendCommand(Isolate* isolate,
|
|
|
|
const uint16_t* command,
|
|
|
|
int length,
|
|
|
|
ClientData* client_data) {
|
|
|
|
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
2014-05-27 13:20:58 +00:00
|
|
|
internal_isolate->debug()->EnqueueCommandMessage(
|
2013-09-19 07:33:45 +00:00
|
|
|
i::Vector<const uint16_t>(command, length), client_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-17 14:26:48 +00:00
|
|
|
Local<Value> Debug::Call(v8::Handle<v8::Function> fun,
|
|
|
|
v8::Handle<v8::Value> data) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (!isolate->IsInitialized()) return Local<Value>();
|
|
|
|
ON_BAILOUT(isolate, "v8::Debug::Call()", return Local<Value>());
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
i::MaybeHandle<i::Object> maybe_result;
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2008-11-27 08:01:27 +00:00
|
|
|
if (data.IsEmpty()) {
|
2014-05-27 13:20:58 +00:00
|
|
|
maybe_result = isolate->debug()->Call(
|
2014-04-11 10:41:09 +00:00
|
|
|
Utils::OpenHandle(*fun), isolate->factory()->undefined_value());
|
2008-11-27 08:01:27 +00:00
|
|
|
} else {
|
2014-05-27 13:20:58 +00:00
|
|
|
maybe_result = isolate->debug()->Call(
|
2014-04-11 10:41:09 +00:00
|
|
|
Utils::OpenHandle(*fun), Utils::OpenHandle(*data));
|
2008-11-27 08:01:27 +00:00
|
|
|
}
|
2014-04-11 10:41:09 +00:00
|
|
|
i::Handle<i::Object> result;
|
|
|
|
has_pending_exception = !maybe_result.ToHandle(&result);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>());
|
2008-11-27 08:01:27 +00:00
|
|
|
return Utils::ToLocal(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-17 14:26:48 +00:00
|
|
|
Local<Value> Debug::GetMirror(v8::Handle<v8::Value> obj) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (!isolate->IsInitialized()) return Local<Value>();
|
|
|
|
ON_BAILOUT(isolate, "v8::Debug::GetMirror()", return Local<Value>());
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2013-12-02 18:12:01 +00:00
|
|
|
v8::EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
|
2011-03-23 14:07:52 +00:00
|
|
|
i::Debug* isolate_debug = isolate->debug();
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2014-04-04 12:06:11 +00:00
|
|
|
has_pending_exception = !isolate_debug->Load();
|
|
|
|
v8::Local<v8::Value> result;
|
|
|
|
if (!has_pending_exception) {
|
|
|
|
i::Handle<i::JSObject> debug(
|
|
|
|
isolate_debug->debug_context()->global_object());
|
|
|
|
i::Handle<i::String> name = isolate->factory()->InternalizeOneByteString(
|
|
|
|
STATIC_ASCII_VECTOR("MakeMirror"));
|
2014-04-11 12:47:34 +00:00
|
|
|
i::Handle<i::Object> fun_obj =
|
|
|
|
i::Object::GetProperty(debug, name).ToHandleChecked();
|
2014-04-04 12:06:11 +00:00
|
|
|
i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(fun_obj);
|
|
|
|
v8::Handle<v8::Function> v8_fun = Utils::ToLocal(fun);
|
|
|
|
const int kArgc = 1;
|
|
|
|
v8::Handle<v8::Value> argv[kArgc] = { obj };
|
|
|
|
result = v8_fun->Call(Utils::ToLocal(debug), kArgc, argv);
|
|
|
|
has_pending_exception = result.IsEmpty();
|
|
|
|
}
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>());
|
2013-12-02 18:12:01 +00:00
|
|
|
return scope.Escape(result);
|
2009-08-17 14:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-15 21:14:56 +00:00
|
|
|
void Debug::ProcessDebugMessages() {
|
2013-09-03 06:59:01 +00:00
|
|
|
i::Execution::ProcessDebugMessages(i::Isolate::Current(), true);
|
2010-01-15 21:14:56 +00:00
|
|
|
}
|
|
|
|
|
2012-09-10 09:24:17 +00:00
|
|
|
|
2010-03-24 13:09:02 +00:00
|
|
|
Local<Context> Debug::GetDebugContext() {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
EnsureInitializedForIsolate(isolate, "v8::Debug::GetDebugContext()");
|
|
|
|
ENTER_V8(isolate);
|
2014-05-27 13:20:58 +00:00
|
|
|
return Utils::ToLocal(i::Isolate::Current()->debug()->GetDebugContext());
|
2010-03-24 13:09:02 +00:00
|
|
|
}
|
|
|
|
|
2012-09-10 09:24:17 +00:00
|
|
|
|
2014-04-15 07:47:33 +00:00
|
|
|
void Debug::SetLiveEditEnabled(Isolate* isolate, bool enable) {
|
|
|
|
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
2014-05-27 13:20:58 +00:00
|
|
|
internal_isolate->debug()->set_live_edit_enabled(enable);
|
2012-09-10 09:24:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-06 14:54:20 +00:00
|
|
|
Handle<String> CpuProfileNode::GetFunctionName() const {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2010-04-06 14:54:20 +00:00
|
|
|
const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
|
|
|
|
const i::CodeEntry* entry = node->entry();
|
2014-04-03 12:30:37 +00:00
|
|
|
i::Handle<i::String> name =
|
|
|
|
isolate->factory()->InternalizeUtf8String(entry->name());
|
2010-04-06 14:54:20 +00:00
|
|
|
if (!entry->has_name_prefix()) {
|
2014-04-03 12:30:37 +00:00
|
|
|
return ToApiHandle<String>(name);
|
2010-04-06 14:54:20 +00:00
|
|
|
} else {
|
2014-04-03 12:30:37 +00:00
|
|
|
// We do not expect this to fail. Change this if it does.
|
2014-03-20 12:27:36 +00:00
|
|
|
i::Handle<i::String> cons = isolate->factory()->NewConsString(
|
2013-02-28 17:03:34 +00:00
|
|
|
isolate->factory()->InternalizeUtf8String(entry->name_prefix()),
|
2014-04-03 12:30:37 +00:00
|
|
|
name).ToHandleChecked();
|
2014-03-20 12:27:36 +00:00
|
|
|
return ToApiHandle<String>(cons);
|
2010-04-06 14:54:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-02 06:14:01 +00:00
|
|
|
int CpuProfileNode::GetScriptId() const {
|
|
|
|
const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
|
|
|
|
const i::CodeEntry* entry = node->entry();
|
|
|
|
return entry->script_id();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-06 14:54:20 +00:00
|
|
|
Handle<String> CpuProfileNode::GetScriptResourceName() const {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2010-04-06 14:54:20 +00:00
|
|
|
const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
|
2013-06-13 09:27:09 +00:00
|
|
|
return ToApiHandle<String>(isolate->factory()->InternalizeUtf8String(
|
|
|
|
node->entry()->resource_name()));
|
2010-04-06 14:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CpuProfileNode::GetLineNumber() const {
|
|
|
|
return reinterpret_cast<const i::ProfileNode*>(this)->entry()->line_number();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-10 13:15:47 +00:00
|
|
|
int CpuProfileNode::GetColumnNumber() const {
|
|
|
|
return reinterpret_cast<const i::ProfileNode*>(this)->
|
|
|
|
entry()->column_number();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-05 13:20:51 +00:00
|
|
|
const char* CpuProfileNode::GetBailoutReason() const {
|
|
|
|
const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
|
|
|
|
return node->entry()->bailout_reason();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-09 07:38:26 +00:00
|
|
|
unsigned CpuProfileNode::GetHitCount() const {
|
|
|
|
return reinterpret_cast<const i::ProfileNode*>(this)->self_ticks();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-06 14:54:20 +00:00
|
|
|
unsigned CpuProfileNode::GetCallUid() const {
|
2010-09-20 09:29:12 +00:00
|
|
|
return reinterpret_cast<const i::ProfileNode*>(this)->entry()->GetCallUid();
|
2010-04-06 14:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-02 07:48:25 +00:00
|
|
|
unsigned CpuProfileNode::GetNodeId() const {
|
|
|
|
return reinterpret_cast<const i::ProfileNode*>(this)->id();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-06 14:54:20 +00:00
|
|
|
int CpuProfileNode::GetChildrenCount() const {
|
|
|
|
return reinterpret_cast<const i::ProfileNode*>(this)->children()->length();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const CpuProfileNode* CpuProfileNode::GetChild(int index) const {
|
|
|
|
const i::ProfileNode* child =
|
|
|
|
reinterpret_cast<const i::ProfileNode*>(this)->children()->at(index);
|
|
|
|
return reinterpret_cast<const CpuProfileNode*>(child);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-22 16:10:01 +00:00
|
|
|
void CpuProfile::Delete() {
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2013-04-02 07:53:50 +00:00
|
|
|
i::CpuProfiler* profiler = isolate->cpu_profiler();
|
|
|
|
ASSERT(profiler != NULL);
|
|
|
|
profiler->DeleteProfile(reinterpret_cast<i::CpuProfile*>(this));
|
2011-03-22 16:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-06 14:54:20 +00:00
|
|
|
Handle<String> CpuProfile::GetTitle() const {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2010-04-06 14:54:20 +00:00
|
|
|
const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
|
2013-06-13 09:27:09 +00:00
|
|
|
return ToApiHandle<String>(isolate->factory()->InternalizeUtf8String(
|
|
|
|
profile->title()));
|
2010-04-06 14:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const CpuProfileNode* CpuProfile::GetTopDownRoot() const {
|
|
|
|
const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
|
|
|
|
return reinterpret_cast<const CpuProfileNode*>(profile->top_down()->root());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-02 07:48:25 +00:00
|
|
|
const CpuProfileNode* CpuProfile::GetSample(int index) const {
|
|
|
|
const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
|
|
|
|
return reinterpret_cast<const CpuProfileNode*>(profile->sample(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-25 18:53:06 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-06 08:00:58 +00:00
|
|
|
int64_t CpuProfile::GetStartTime() const {
|
2013-08-05 07:17:08 +00:00
|
|
|
const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
|
2014-04-19 14:33:18 +00:00
|
|
|
return (profile->start_time() - i::TimeTicks()).InMicroseconds();
|
2013-08-05 07:17:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-06 08:00:58 +00:00
|
|
|
int64_t CpuProfile::GetEndTime() const {
|
2013-08-05 07:17:08 +00:00
|
|
|
const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
|
2014-04-19 14:33:18 +00:00
|
|
|
return (profile->end_time() - i::TimeTicks()).InMicroseconds();
|
2013-08-05 07:17:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-02 07:48:25 +00:00
|
|
|
int CpuProfile::GetSamplesCount() const {
|
|
|
|
return reinterpret_cast<const i::CpuProfile*>(this)->samples_count();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-04 11:55:28 +00:00
|
|
|
void CpuProfiler::SetSamplingInterval(int us) {
|
|
|
|
ASSERT(us >= 0);
|
|
|
|
return reinterpret_cast<i::CpuProfiler*>(this)->set_sampling_interval(
|
|
|
|
i::TimeDelta::FromMicroseconds(us));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-14 09:26:31 +00:00
|
|
|
void CpuProfiler::StartProfiling(Handle<String> title, bool record_samples) {
|
2013-04-02 08:16:53 +00:00
|
|
|
reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling(
|
|
|
|
*Utils::OpenHandle(*title), record_samples);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-14 09:26:31 +00:00
|
|
|
void CpuProfiler::StartCpuProfiling(Handle<String> title, bool record_samples) {
|
|
|
|
StartProfiling(title, record_samples);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CpuProfile* CpuProfiler::StopProfiling(Handle<String> title) {
|
|
|
|
return reinterpret_cast<CpuProfile*>(
|
2013-05-28 08:00:16 +00:00
|
|
|
reinterpret_cast<i::CpuProfiler*>(this)->StopProfiling(
|
|
|
|
*Utils::OpenHandle(*title)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-14 09:26:31 +00:00
|
|
|
const CpuProfile* CpuProfiler::StopCpuProfiling(Handle<String> title) {
|
|
|
|
return StopProfiling(title);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-07 17:04:27 +00:00
|
|
|
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);
|
|
|
|
if (isolate->js_entry_sp() != NULL) return;
|
|
|
|
if (is_idle) {
|
|
|
|
isolate->set_current_vm_state(i::IDLE);
|
|
|
|
} else if (state == i::IDLE) {
|
|
|
|
isolate->set_current_vm_state(i::EXTERNAL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-09 11:37:24 +00:00
|
|
|
static i::HeapGraphEdge* ToInternal(const HeapGraphEdge* edge) {
|
|
|
|
return const_cast<i::HeapGraphEdge*>(
|
|
|
|
reinterpret_cast<const i::HeapGraphEdge*>(edge));
|
|
|
|
}
|
2011-06-03 19:45:59 +00:00
|
|
|
|
2010-08-09 11:37:24 +00:00
|
|
|
|
2010-06-15 11:44:07 +00:00
|
|
|
HeapGraphEdge::Type HeapGraphEdge::GetType() const {
|
2010-08-09 11:37:24 +00:00
|
|
|
return static_cast<HeapGraphEdge::Type>(ToInternal(this)->type());
|
2010-06-15 11:44:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Value> HeapGraphEdge::GetName() const {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2010-08-09 11:37:24 +00:00
|
|
|
i::HeapGraphEdge* edge = ToInternal(this);
|
2010-06-15 11:44:07 +00:00
|
|
|
switch (edge->type()) {
|
2010-08-09 11:37:24 +00:00
|
|
|
case i::HeapGraphEdge::kContextVariable:
|
|
|
|
case i::HeapGraphEdge::kInternal:
|
|
|
|
case i::HeapGraphEdge::kProperty:
|
2010-11-18 10:38:25 +00:00
|
|
|
case i::HeapGraphEdge::kShortcut:
|
2014-01-27 09:37:02 +00:00
|
|
|
case i::HeapGraphEdge::kWeak:
|
2013-06-13 09:27:09 +00:00
|
|
|
return ToApiHandle<String>(
|
|
|
|
isolate->factory()->InternalizeUtf8String(edge->name()));
|
2010-08-09 11:37:24 +00:00
|
|
|
case i::HeapGraphEdge::kElement:
|
2010-11-18 10:38:25 +00:00
|
|
|
case i::HeapGraphEdge::kHidden:
|
2013-06-13 09:27:09 +00:00
|
|
|
return ToApiHandle<Number>(
|
|
|
|
isolate->factory()->NewNumberFromInt(edge->index()));
|
2010-06-15 11:44:07 +00:00
|
|
|
default: UNREACHABLE();
|
|
|
|
}
|
2013-09-26 08:21:48 +00:00
|
|
|
return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
|
2010-06-15 11:44:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const HeapGraphNode* HeapGraphEdge::GetFromNode() const {
|
2012-04-16 14:31:13 +00:00
|
|
|
const i::HeapEntry* from = ToInternal(this)->from();
|
2010-06-15 11:44:07 +00:00
|
|
|
return reinterpret_cast<const HeapGraphNode*>(from);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const HeapGraphNode* HeapGraphEdge::GetToNode() const {
|
2010-08-09 11:37:24 +00:00
|
|
|
const i::HeapEntry* to = ToInternal(this)->to();
|
2010-06-15 11:44:07 +00:00
|
|
|
return reinterpret_cast<const HeapGraphNode*>(to);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-09 11:37:24 +00:00
|
|
|
static i::HeapEntry* ToInternal(const HeapGraphNode* entry) {
|
|
|
|
return const_cast<i::HeapEntry*>(
|
|
|
|
reinterpret_cast<const i::HeapEntry*>(entry));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-15 11:44:07 +00:00
|
|
|
HeapGraphNode::Type HeapGraphNode::GetType() const {
|
2010-08-09 11:37:24 +00:00
|
|
|
return static_cast<HeapGraphNode::Type>(ToInternal(this)->type());
|
2010-06-15 11:44:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<String> HeapGraphNode::GetName() const {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2013-06-13 09:27:09 +00:00
|
|
|
return ToApiHandle<String>(
|
|
|
|
isolate->factory()->InternalizeUtf8String(ToInternal(this)->name()));
|
2010-06-15 11:44:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-26 13:47:37 +00:00
|
|
|
SnapshotObjectId HeapGraphNode::GetId() const {
|
2010-08-09 11:37:24 +00:00
|
|
|
return ToInternal(this)->id();
|
2010-07-15 13:21:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-15 11:44:07 +00:00
|
|
|
int HeapGraphNode::GetSelfSize() const {
|
2014-02-18 13:22:07 +00:00
|
|
|
size_t size = ToInternal(this)->self_size();
|
|
|
|
CHECK(size <= static_cast<size_t>(internal::kMaxInt));
|
|
|
|
return static_cast<int>(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
size_t HeapGraphNode::GetShallowSize() const {
|
2010-08-09 11:37:24 +00:00
|
|
|
return ToInternal(this)->self_size();
|
2010-06-15 11:44:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int HeapGraphNode::GetChildrenCount() const {
|
2010-08-09 11:37:24 +00:00
|
|
|
return ToInternal(this)->children().length();
|
2010-06-15 11:44:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const HeapGraphEdge* HeapGraphNode::GetChild(int index) const {
|
|
|
|
return reinterpret_cast<const HeapGraphEdge*>(
|
2012-05-09 14:34:13 +00:00
|
|
|
ToInternal(this)->children()[index]);
|
2010-06-15 11:44:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-09 11:37:24 +00:00
|
|
|
static i::HeapSnapshot* ToInternal(const HeapSnapshot* snapshot) {
|
|
|
|
return const_cast<i::HeapSnapshot*>(
|
|
|
|
reinterpret_cast<const i::HeapSnapshot*>(snapshot));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-22 16:10:01 +00:00
|
|
|
void HeapSnapshot::Delete() {
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2013-04-02 08:03:01 +00:00
|
|
|
if (isolate->heap_profiler()->GetSnapshotsCount() > 1) {
|
2011-03-22 16:10:01 +00:00
|
|
|
ToInternal(this)->Delete();
|
|
|
|
} else {
|
|
|
|
// If this is the last snapshot, clean up all accessory data as well.
|
2013-04-02 08:03:01 +00:00
|
|
|
isolate->heap_profiler()->DeleteAllSnapshots();
|
2011-03-22 16:10:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-15 11:44:07 +00:00
|
|
|
unsigned HeapSnapshot::GetUid() const {
|
2010-08-09 11:37:24 +00:00
|
|
|
return ToInternal(this)->uid();
|
2010-06-15 11:44:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<String> HeapSnapshot::GetTitle() const {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2013-06-13 09:27:09 +00:00
|
|
|
return ToApiHandle<String>(
|
|
|
|
isolate->factory()->InternalizeUtf8String(ToInternal(this)->title()));
|
2010-06-15 11:44:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-15 13:21:50 +00:00
|
|
|
const HeapGraphNode* HeapSnapshot::GetRoot() const {
|
2010-08-09 11:37:24 +00:00
|
|
|
return reinterpret_cast<const HeapGraphNode*>(ToInternal(this)->root());
|
2010-06-15 11:44:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-26 13:47:37 +00:00
|
|
|
const HeapGraphNode* HeapSnapshot::GetNodeById(SnapshotObjectId id) const {
|
2010-12-02 15:38:51 +00:00
|
|
|
return reinterpret_cast<const HeapGraphNode*>(
|
2012-03-26 13:47:37 +00:00
|
|
|
ToInternal(this)->GetEntryById(id));
|
2010-12-02 15:38:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-21 08:02:34 +00:00
|
|
|
int HeapSnapshot::GetNodesCount() const {
|
2012-05-09 14:34:13 +00:00
|
|
|
return ToInternal(this)->entries().length();
|
2011-06-21 08:02:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const HeapGraphNode* HeapSnapshot::GetNode(int index) const {
|
|
|
|
return reinterpret_cast<const HeapGraphNode*>(
|
2012-05-09 14:34:13 +00:00
|
|
|
&ToInternal(this)->entries().at(index));
|
2011-06-21 08:02:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-27 11:54:47 +00:00
|
|
|
SnapshotObjectId HeapSnapshot::GetMaxSnapshotJSObjectId() const {
|
|
|
|
return ToInternal(this)->max_snapshot_js_object_id();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-14 11:49:06 +00:00
|
|
|
void HeapSnapshot::Serialize(OutputStream* stream,
|
|
|
|
HeapSnapshot::SerializationFormat format) const {
|
2014-01-13 09:42:23 +00:00
|
|
|
Utils::ApiCheck(format == kJSON,
|
|
|
|
"v8::HeapSnapshot::Serialize",
|
|
|
|
"Unknown serialization format");
|
|
|
|
Utils::ApiCheck(stream->GetChunkSize() > 0,
|
|
|
|
"v8::HeapSnapshot::Serialize",
|
|
|
|
"Invalid stream chunk size");
|
2010-09-14 11:49:06 +00:00
|
|
|
i::HeapSnapshotJSONSerializer serializer(ToInternal(this));
|
|
|
|
serializer.Serialize(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-02 08:03:01 +00:00
|
|
|
int HeapProfiler::GetSnapshotCount() {
|
|
|
|
return reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshotsCount();
|
2010-06-15 11:44:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-02 08:03:01 +00:00
|
|
|
const HeapSnapshot* HeapProfiler::GetHeapSnapshot(int index) {
|
|
|
|
return reinterpret_cast<const HeapSnapshot*>(
|
|
|
|
reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshot(index));
|
2010-06-15 11:44:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-02 08:03:01 +00:00
|
|
|
SnapshotObjectId HeapProfiler::GetObjectId(Handle<Value> value) {
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(*value);
|
|
|
|
return reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshotObjectId(obj);
|
2012-04-16 15:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-18 08:17:03 +00:00
|
|
|
Handle<Value> HeapProfiler::FindObjectById(SnapshotObjectId id) {
|
|
|
|
i::Handle<i::Object> obj =
|
|
|
|
reinterpret_cast<i::HeapProfiler*>(this)->FindHeapObjectById(id);
|
|
|
|
if (obj.is_null()) return Local<Value>();
|
|
|
|
return Utils::ToLocal(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HeapProfiler::ClearObjectIds() {
|
|
|
|
reinterpret_cast<i::HeapProfiler*>(this)->ClearHeapObjectMap();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-02 08:03:01 +00:00
|
|
|
const HeapSnapshot* HeapProfiler::TakeHeapSnapshot(
|
|
|
|
Handle<String> title,
|
|
|
|
ActivityControl* control,
|
|
|
|
ObjectNameResolver* resolver) {
|
|
|
|
return reinterpret_cast<const HeapSnapshot*>(
|
|
|
|
reinterpret_cast<i::HeapProfiler*>(this)->TakeSnapshot(
|
2013-04-02 08:09:59 +00:00
|
|
|
*Utils::OpenHandle(*title), control, resolver));
|
2013-04-02 08:03:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-02 14:27:24 +00:00
|
|
|
void HeapProfiler::StartTrackingHeapObjects(bool track_allocations) {
|
|
|
|
reinterpret_cast<i::HeapProfiler*>(this)->StartHeapObjectsTracking(
|
|
|
|
track_allocations);
|
2012-04-13 08:52:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-02 08:03:01 +00:00
|
|
|
void HeapProfiler::StopTrackingHeapObjects() {
|
|
|
|
reinterpret_cast<i::HeapProfiler*>(this)->StopHeapObjectsTracking();
|
2012-04-13 08:52:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-02 08:03:01 +00:00
|
|
|
SnapshotObjectId HeapProfiler::GetHeapStats(OutputStream* stream) {
|
|
|
|
return reinterpret_cast<i::HeapProfiler*>(this)->PushHeapObjectsStats(stream);
|
2012-04-13 08:52:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-02 08:03:01 +00:00
|
|
|
void HeapProfiler::DeleteAllHeapSnapshots() {
|
|
|
|
reinterpret_cast<i::HeapProfiler*>(this)->DeleteAllSnapshots();
|
2011-03-22 16:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-02 08:03:01 +00:00
|
|
|
void HeapProfiler::SetWrapperClassInfoProvider(uint16_t class_id,
|
|
|
|
WrapperInfoCallback callback) {
|
|
|
|
reinterpret_cast<i::HeapProfiler*>(this)->DefineWrapperClass(class_id,
|
|
|
|
callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
size_t HeapProfiler::GetProfilerMemorySize() {
|
|
|
|
return reinterpret_cast<i::HeapProfiler*>(this)->
|
|
|
|
GetMemorySizeUsedByProfiler();
|
2012-06-13 11:02:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-24 15:59:23 +00:00
|
|
|
void HeapProfiler::SetRetainedObjectInfo(UniqueId id,
|
|
|
|
RetainedObjectInfo* info) {
|
|
|
|
reinterpret_cast<i::HeapProfiler*>(this)->SetRetainedObjectInfo(id, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
v8::Testing::StressType internal::Testing::stress_type_ =
|
|
|
|
v8::Testing::kStressTypeOpt;
|
|
|
|
|
|
|
|
|
|
|
|
void Testing::SetStressRunType(Testing::StressType type) {
|
|
|
|
internal::Testing::set_stress_type(type);
|
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
int Testing::GetStressRuns() {
|
2010-12-16 13:24:23 +00:00
|
|
|
if (internal::FLAG_stress_runs != 0) return internal::FLAG_stress_runs;
|
2010-12-07 11:31:57 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
// In debug mode the code runs much slower so stressing will only make two
|
|
|
|
// runs.
|
|
|
|
return 2;
|
|
|
|
#else
|
|
|
|
return 5;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void SetFlagsFromString(const char* flags) {
|
|
|
|
V8::SetFlagsFromString(flags, i::StrLength(flags));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Testing::PrepareStressRun(int run) {
|
|
|
|
static const char* kLazyOptimizations =
|
2012-04-20 10:42:12 +00:00
|
|
|
"--prepare-always-opt "
|
|
|
|
"--max-inlined-source-size=999999 "
|
|
|
|
"--max-inlined-nodes=999999 "
|
|
|
|
"--max-inlined-nodes-cumulative=999999 "
|
|
|
|
"--noalways-opt";
|
2010-12-07 11:31:57 +00:00
|
|
|
static const char* kForcedOptimizations = "--always-opt";
|
|
|
|
|
|
|
|
// If deoptimization stressed turn on frequent deoptimization. If no value
|
|
|
|
// is spefified through --deopt-every-n-times use a default default value.
|
|
|
|
static const char* kDeoptEvery13Times = "--deopt-every-n-times=13";
|
|
|
|
if (internal::Testing::stress_type() == Testing::kStressTypeDeopt &&
|
|
|
|
internal::FLAG_deopt_every_n_times == 0) {
|
|
|
|
SetFlagsFromString(kDeoptEvery13Times);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
// As stressing in debug mode only make two runs skip the deopt stressing
|
|
|
|
// here.
|
|
|
|
if (run == GetStressRuns() - 1) {
|
|
|
|
SetFlagsFromString(kForcedOptimizations);
|
|
|
|
} else {
|
|
|
|
SetFlagsFromString(kLazyOptimizations);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (run == GetStressRuns() - 1) {
|
|
|
|
SetFlagsFromString(kForcedOptimizations);
|
2012-02-08 12:49:04 +00:00
|
|
|
} else if (run != GetStressRuns() - 2) {
|
2010-12-07 11:31:57 +00:00
|
|
|
SetFlagsFromString(kLazyOptimizations);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-15 09:27:10 +00:00
|
|
|
// TODO(svenpanne) Deprecate this.
|
2011-03-10 13:58:20 +00:00
|
|
|
void Testing::DeoptimizeAll() {
|
2013-02-15 09:27:10 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
i::HandleScope scope(isolate);
|
2013-03-18 13:57:49 +00:00
|
|
|
internal::Deoptimizer::DeoptimizeAll(isolate);
|
2011-03-10 13:58:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
2009-09-28 12:25:21 +00:00
|
|
|
void HandleScopeImplementer::FreeThreadResources() {
|
2011-03-18 20:35:07 +00:00
|
|
|
Free();
|
2009-09-28 12:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
char* HandleScopeImplementer::ArchiveThread(char* storage) {
|
2014-01-16 08:17:40 +00:00
|
|
|
HandleScopeData* current = isolate_->handle_scope_data();
|
2008-07-03 15:10:15 +00:00
|
|
|
handle_scope_data_ = *current;
|
2014-05-27 07:57:22 +00:00
|
|
|
MemCopy(storage, this, sizeof(*this));
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-09-28 12:25:21 +00:00
|
|
|
ResetAfterArchive();
|
2008-07-03 15:10:15 +00:00
|
|
|
current->Initialize();
|
|
|
|
|
|
|
|
return storage + ArchiveSpacePerThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int HandleScopeImplementer::ArchiveSpacePerThread() {
|
2011-03-18 20:35:07 +00:00
|
|
|
return sizeof(HandleScopeImplementer);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char* HandleScopeImplementer::RestoreThread(char* storage) {
|
2014-05-27 07:57:22 +00:00
|
|
|
MemCopy(this, storage, sizeof(*this));
|
2011-05-05 18:55:31 +00:00
|
|
|
*isolate_->handle_scope_data() = handle_scope_data_;
|
2008-07-03 15:10:15 +00:00
|
|
|
return storage + ArchiveSpacePerThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-04 07:34:25 +00:00
|
|
|
void HandleScopeImplementer::IterateThis(ObjectVisitor* v) {
|
2012-07-06 09:31:31 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool found_block_before_deferred = false;
|
|
|
|
#endif
|
2008-07-03 15:10:15 +00:00
|
|
|
// Iterate over all handles in the blocks except for the last.
|
2009-09-28 12:25:21 +00:00
|
|
|
for (int i = blocks()->length() - 2; i >= 0; --i) {
|
|
|
|
Object** block = blocks()->at(i);
|
2012-07-06 09:31:31 +00:00
|
|
|
if (last_handle_before_deferred_block_ != NULL &&
|
2013-03-18 11:26:09 +00:00
|
|
|
(last_handle_before_deferred_block_ <= &block[kHandleBlockSize]) &&
|
2012-07-06 09:31:31 +00:00
|
|
|
(last_handle_before_deferred_block_ >= block)) {
|
|
|
|
v->VisitPointers(block, last_handle_before_deferred_block_);
|
|
|
|
ASSERT(!found_block_before_deferred);
|
|
|
|
#ifdef DEBUG
|
|
|
|
found_block_before_deferred = true;
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
v->VisitPointers(block, &block[kHandleBlockSize]);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2012-07-06 09:31:31 +00:00
|
|
|
ASSERT(last_handle_before_deferred_block_ == NULL ||
|
|
|
|
found_block_before_deferred);
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Iterate over live handles in the last block (if any).
|
2009-09-28 12:25:21 +00:00
|
|
|
if (!blocks()->is_empty()) {
|
|
|
|
v->VisitPointers(blocks()->last(), handle_scope_data_.next);
|
2009-09-04 07:34:25 +00:00
|
|
|
}
|
|
|
|
|
2013-09-24 11:40:28 +00:00
|
|
|
List<Context*>* context_lists[2] = { &saved_contexts_, &entered_contexts_};
|
|
|
|
for (unsigned i = 0; i < ARRAY_SIZE(context_lists); i++) {
|
|
|
|
if (context_lists[i]->is_empty()) continue;
|
|
|
|
Object** start = reinterpret_cast<Object**>(&context_lists[i]->first());
|
|
|
|
v->VisitPointers(start, start + context_lists[i]->length());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HandleScopeImplementer::Iterate(ObjectVisitor* v) {
|
2014-01-16 08:17:40 +00:00
|
|
|
HandleScopeData* current = isolate_->handle_scope_data();
|
2011-03-18 20:35:07 +00:00
|
|
|
handle_scope_data_ = *current;
|
|
|
|
IterateThis(v);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) {
|
2011-03-29 08:04:26 +00:00
|
|
|
HandleScopeImplementer* scope_implementer =
|
2008-07-03 15:10:15 +00:00
|
|
|
reinterpret_cast<HandleScopeImplementer*>(storage);
|
2011-03-29 08:04:26 +00:00
|
|
|
scope_implementer->IterateThis(v);
|
2008-07-03 15:10:15 +00:00
|
|
|
return storage + ArchiveSpacePerThread();
|
|
|
|
}
|
|
|
|
|
2012-07-06 09:31:31 +00:00
|
|
|
|
|
|
|
DeferredHandles* HandleScopeImplementer::Detach(Object** prev_limit) {
|
2012-07-18 14:15:02 +00:00
|
|
|
DeferredHandles* deferred =
|
|
|
|
new DeferredHandles(isolate()->handle_scope_data()->next, isolate());
|
2012-07-06 09:31:31 +00:00
|
|
|
|
|
|
|
while (!blocks_.is_empty()) {
|
|
|
|
Object** block_start = blocks_.last();
|
|
|
|
Object** block_limit = &block_start[kHandleBlockSize];
|
2013-06-03 15:32:22 +00:00
|
|
|
// We should not need to check for SealHandleScope here. Assert this.
|
2012-07-06 09:31:31 +00:00
|
|
|
ASSERT(prev_limit == block_limit ||
|
|
|
|
!(block_start <= prev_limit && prev_limit <= block_limit));
|
|
|
|
if (prev_limit == block_limit) break;
|
|
|
|
deferred->blocks_.Add(blocks_.last());
|
|
|
|
blocks_.RemoveLast();
|
|
|
|
}
|
|
|
|
|
2012-07-06 14:09:11 +00:00
|
|
|
// deferred->blocks_ now contains the blocks installed on the
|
|
|
|
// HandleScope stack since BeginDeferredScope was called, but in
|
|
|
|
// reverse order.
|
|
|
|
|
|
|
|
ASSERT(prev_limit == NULL || !blocks_.is_empty());
|
|
|
|
|
2012-07-06 09:31:31 +00:00
|
|
|
ASSERT(!blocks_.is_empty() && prev_limit != NULL);
|
|
|
|
ASSERT(last_handle_before_deferred_block_ != NULL);
|
|
|
|
last_handle_before_deferred_block_ = NULL;
|
|
|
|
return deferred;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HandleScopeImplementer::BeginDeferredScope() {
|
|
|
|
ASSERT(last_handle_before_deferred_block_ == NULL);
|
|
|
|
last_handle_before_deferred_block_ = isolate()->handle_scope_data()->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DeferredHandles::~DeferredHandles() {
|
2012-07-18 14:15:02 +00:00
|
|
|
isolate_->UnlinkDeferredHandles(this);
|
|
|
|
|
|
|
|
for (int i = 0; i < blocks_.length(); i++) {
|
2013-09-30 11:56:52 +00:00
|
|
|
#ifdef ENABLE_HANDLE_ZAPPING
|
2012-07-18 14:15:02 +00:00
|
|
|
HandleScope::ZapRange(blocks_[i], &blocks_[i][kHandleBlockSize]);
|
|
|
|
#endif
|
|
|
|
isolate_->handle_scope_implementer()->ReturnBlock(blocks_[i]);
|
|
|
|
}
|
2012-07-06 09:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DeferredHandles::Iterate(ObjectVisitor* v) {
|
|
|
|
ASSERT(!blocks_.is_empty());
|
|
|
|
|
2012-07-06 14:09:11 +00:00
|
|
|
ASSERT((first_block_limit_ >= blocks_.first()) &&
|
2012-07-16 13:00:57 +00:00
|
|
|
(first_block_limit_ <= &(blocks_.first())[kHandleBlockSize]));
|
2012-07-06 09:31:31 +00:00
|
|
|
|
2012-07-06 14:09:11 +00:00
|
|
|
v->VisitPointers(blocks_.first(), first_block_limit_);
|
2012-07-06 09:31:31 +00:00
|
|
|
|
2012-07-06 14:09:11 +00:00
|
|
|
for (int i = 1; i < blocks_.length(); i++) {
|
|
|
|
v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]);
|
|
|
|
}
|
2012-07-06 09:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-13 19:16:35 +00:00
|
|
|
void InvokeAccessorGetterCallback(
|
|
|
|
v8::Local<v8::String> property,
|
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info,
|
|
|
|
v8::AccessorGetterCallback getter) {
|
|
|
|
// Leaving JavaScript.
|
|
|
|
Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
|
|
|
|
Address getter_address = reinterpret_cast<Address>(reinterpret_cast<intptr_t>(
|
|
|
|
getter));
|
|
|
|
VMState<EXTERNAL> state(isolate);
|
|
|
|
ExternalCallbackScope call_scope(isolate, getter_address);
|
2013-09-09 07:52:52 +00:00
|
|
|
getter(property, info);
|
2013-06-13 19:16:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InvokeFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>& info,
|
|
|
|
v8::FunctionCallback callback) {
|
|
|
|
Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
|
|
|
|
Address callback_address =
|
|
|
|
reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
|
|
|
|
VMState<EXTERNAL> state(isolate);
|
|
|
|
ExternalCallbackScope call_scope(isolate, callback_address);
|
2013-09-09 07:52:52 +00:00
|
|
|
callback(info);
|
2013-06-13 19:16:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|