2012-01-10 10:05:45 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2008-07-03 15:10:15 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#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.
|
2013-04-19 13:26:47 +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"
|
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"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "snapshot.h"
|
2012-01-25 16:31:25 +00:00
|
|
|
#include "unicode-inl.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) \
|
|
|
|
if (IsDeadCheck(isolate, location) || \
|
2011-03-25 13:32:06 +00:00
|
|
|
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
|
|
|
if (handle_scope_implementer->CallDepthIsZero() && \
|
2011-03-24 18:49:45 +00:00
|
|
|
(isolate)->is_out_of_memory()) { \
|
2011-08-04 15:18:18 +00:00
|
|
|
if (!(isolate)->ignore_out_of_memory()) \
|
2008-07-03 15:10:15 +00:00
|
|
|
i::V8::FatalProcessOutOfMemory(NULL); \
|
|
|
|
} \
|
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( \
|
|
|
|
isolate, value, i::V8::FireCallCompletedCallback(isolate);)
|
|
|
|
|
|
|
|
|
|
|
|
#define EXCEPTION_BAILOUT_CHECK(isolate, value) \
|
|
|
|
EXCEPTION_BAILOUT_CHECK_GENERIC(isolate, value, ;)
|
|
|
|
|
|
|
|
|
2011-06-07 13:09:01 +00:00
|
|
|
#define API_ENTRY_CHECK(isolate, msg) \
|
2009-01-23 17:22:23 +00:00
|
|
|
do { \
|
|
|
|
if (v8::Locker::IsActive()) { \
|
2011-06-07 13:09:01 +00:00
|
|
|
ApiCheck(isolate->thread_manager()->IsLockedByCurrentThread(), \
|
2009-01-23 17:22:23 +00:00
|
|
|
msg, \
|
|
|
|
"Entering the V8 API without proper locking in place"); \
|
|
|
|
} \
|
|
|
|
} while (false)
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
|
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 ---
|
|
|
|
|
|
|
|
|
|
|
|
static void DefaultFatalErrorHandler(const char* location,
|
|
|
|
const char* message) {
|
2013-01-10 15:53:11 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (isolate->IsInitialized()) {
|
2013-04-24 14:44:08 +00:00
|
|
|
i::VMState<i::OTHER> state(isolate);
|
2013-01-10 15:53:11 +00:00
|
|
|
API_Fatal(location, message);
|
|
|
|
} else {
|
|
|
|
API_Fatal(location, message);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
static FatalErrorCallback GetFatalErrorHandler() {
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (isolate->exception_behavior() == NULL) {
|
|
|
|
isolate->set_exception_behavior(DefaultFatalErrorHandler);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
return isolate->exception_behavior();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2013-09-03 09:35:26 +00:00
|
|
|
isolate->SignalFatalError();
|
2008-07-03 15:10:15 +00:00
|
|
|
FatalErrorCallback callback = GetFatalErrorHandler();
|
2013-01-10 15:53:11 +00:00
|
|
|
const char* message = "Allocation failed - process out of memory";
|
2013-04-24 14:44:08 +00:00
|
|
|
callback(location, message);
|
2008-07-03 15:10:15 +00:00
|
|
|
// If the callback 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Utils::ReportApiFailure(const char* location, const char* message) {
|
|
|
|
FatalErrorCallback callback = GetFatalErrorHandler();
|
2009-04-03 07:49:20 +00:00
|
|
|
callback(location, message);
|
2013-09-03 09:35:26 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
isolate->SignalFatalError();
|
2008-07-03 15:10:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline bool ApiCheck(bool condition,
|
|
|
|
const char* location,
|
|
|
|
const char* message) {
|
|
|
|
return condition ? true : Utils::ReportApiFailure(location, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool ReportV8Dead(const char* location) {
|
|
|
|
FatalErrorCallback callback = GetFatalErrorHandler();
|
2009-04-03 07:49:20 +00:00
|
|
|
callback(location, "V8 is no longer usable");
|
2008-07-03 15:10:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool ReportEmptyHandle(const char* location) {
|
|
|
|
FatalErrorCallback callback = GetFatalErrorHandler();
|
2009-04-03 07:49:20 +00:00
|
|
|
callback(location, "Reading from empty handle");
|
2008-07-03 15:10:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2009-01-15 19:08:34 +00:00
|
|
|
* IsDeadCheck checks that the vm is usable. If, for instance, the vm has been
|
2008-07-03 15:10:15 +00:00
|
|
|
* out of memory at some point this check will fail. It should be called on
|
|
|
|
* entry to all methods that touch anything in the heap, except destructors
|
|
|
|
* which you sometimes can't avoid calling after the vm has crashed. Functions
|
|
|
|
* that call EnsureInitialized or ON_BAILOUT don't have to also call
|
|
|
|
* IsDeadCheck. ON_BAILOUT has the advantage over EnsureInitialized that you
|
|
|
|
* can arrange to return if the VM is dead. This is needed to ensure that no VM
|
|
|
|
* heap allocations are attempted on a dead VM. EnsureInitialized has the
|
|
|
|
* advantage over ON_BAILOUT that it actually initializes the VM if this has not
|
|
|
|
* yet been done.
|
|
|
|
*/
|
2011-03-18 20:35:07 +00:00
|
|
|
static inline bool IsDeadCheck(i::Isolate* isolate, const char* location) {
|
|
|
|
return !isolate->IsInitialized()
|
2013-09-03 09:35:26 +00:00
|
|
|
&& isolate->IsDead() ? ReportV8Dead(location) : false;
|
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
|
|
|
static inline bool EmptyCheck(const char* location, v8::Handle<v8::Data> obj) {
|
|
|
|
return obj.IsEmpty() ? ReportEmptyHandle(location) : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
static inline bool EmptyCheck(const char* location, const v8::Data* obj) {
|
2008-07-03 15:10:15 +00:00
|
|
|
return (obj == 0) ? ReportEmptyHandle(location) : false;
|
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
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) {
|
|
|
|
if (IsDeadCheck(isolate, location)) return false;
|
|
|
|
if (isolate != NULL) {
|
|
|
|
if (isolate->IsInitialized()) return true;
|
2011-03-18 19:41:05 +00:00
|
|
|
}
|
2011-05-05 18:55:31 +00:00
|
|
|
ASSERT(isolate == i::Isolate::Current());
|
2013-06-28 13:40:41 +00:00
|
|
|
return ApiCheck(InitializeHelper(isolate), location, "Error initializing V8");
|
2011-03-18 18:49:56 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
// Some initializing API functions are called early and may be
|
|
|
|
// called on a thread different from static initializer thread.
|
|
|
|
// If Isolate API is used, Isolate::Enter() will initialize TLS so
|
|
|
|
// Isolate::Current() works. If it's a legacy case, then the thread
|
|
|
|
// may not have TLS initialized yet. However, in initializing APIs it
|
|
|
|
// may be too early to call EnsureInitialized() - some pre-init
|
|
|
|
// parameters still have to be configured.
|
|
|
|
static inline i::Isolate* EnterIsolateIfNeeded() {
|
|
|
|
i::Isolate* isolate = i::Isolate::UncheckedCurrent();
|
|
|
|
if (isolate != NULL)
|
|
|
|
return isolate;
|
|
|
|
|
|
|
|
i::Isolate::EnterDefaultIsolate();
|
|
|
|
isolate = i::Isolate::Current();
|
|
|
|
return isolate;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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,
|
2013-08-26 17:00:58 +00:00
|
|
|
#if defined(V8_I18N_SUPPORT)
|
|
|
|
kI18NExtension,
|
|
|
|
#endif
|
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();
|
2013-08-26 17:00:58 +00:00
|
|
|
|
|
|
|
#if defined(V8_I18N_SUPPORT)
|
|
|
|
i::Vector<const ii:byte> i18n_extension_source =
|
|
|
|
i::I18NNatives::GetScriptsSource();
|
|
|
|
compressed_data[kI18NExtension].data =
|
|
|
|
reinterpret_cast<const char*>(i18n_extension_source.start());
|
|
|
|
compressed_data[kI18NExtension].compressed_size =
|
|
|
|
i18n_extension_source.length();
|
|
|
|
compressed_data[kI18NExtension].raw_size =
|
|
|
|
i::I18NNatives::GetRawScriptsSize();
|
|
|
|
#endif
|
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);
|
2013-08-26 17:00:58 +00:00
|
|
|
|
|
|
|
#if defined(V8_I18N_SUPPORT)
|
|
|
|
ASSERT_EQ(i::I18NNatives::GetRawScriptsSize(),
|
|
|
|
decompressed_data[kI18NExtension].raw_size);
|
|
|
|
i::Vector<const char> i18n_extension_source(
|
|
|
|
decompressed_data[kI18NExtension].data,
|
|
|
|
decompressed_data[kI18NExtension].raw_size);
|
|
|
|
i::I18NNatives::SetRawScriptsSource(i18n_extension_source);
|
|
|
|
#endif
|
2011-04-29 12:08:33 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
void V8::SetFatalErrorHandler(FatalErrorCallback that) {
|
|
|
|
i::Isolate* isolate = EnterIsolateIfNeeded();
|
|
|
|
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) {
|
|
|
|
i::Isolate* isolate = EnterIsolateIfNeeded();
|
|
|
|
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
|
|
|
v8::Handle<Value> ThrowException(v8::Handle<v8::Value> value) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::ThrowException()")) {
|
|
|
|
return v8::Handle<Value>();
|
|
|
|
}
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2008-10-28 08:29:23 +00:00
|
|
|
// If we're passed an empty handle, we throw an undefined exception
|
|
|
|
// to deal more gracefully with out of memory situations.
|
|
|
|
if (value.IsEmpty()) {
|
2011-03-28 09:11:14 +00:00
|
|
|
isolate->ScheduleThrow(isolate->heap()->undefined_value());
|
2008-10-28 08:29:23 +00:00
|
|
|
} else {
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->ScheduleThrow(*Utils::OpenHandle(*value));
|
2008-10-28 08:29:23 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
return v8::Undefined();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
v8::Handle<Primitive> Undefined() {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2011-03-25 14:09:14 +00:00
|
|
|
if (!EnsureInitializedForIsolate(isolate, "v8::Undefined()")) {
|
|
|
|
return v8::Handle<v8::Primitive>();
|
|
|
|
}
|
2013-06-13 09:27:09 +00:00
|
|
|
return ToApiHandle<Primitive>(isolate->factory()->undefined_value());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
v8::Handle<Primitive> Null() {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2011-03-25 14:09:14 +00:00
|
|
|
if (!EnsureInitializedForIsolate(isolate, "v8::Null()")) {
|
|
|
|
return v8::Handle<v8::Primitive>();
|
|
|
|
}
|
2013-06-13 09:27:09 +00:00
|
|
|
return ToApiHandle<Primitive>(isolate->factory()->null_value());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
v8::Handle<Boolean> True() {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2011-03-25 14:09:14 +00:00
|
|
|
if (!EnsureInitializedForIsolate(isolate, "v8::True()")) {
|
|
|
|
return v8::Handle<Boolean>();
|
|
|
|
}
|
2013-06-13 09:27:09 +00:00
|
|
|
return ToApiHandle<Boolean>(isolate->factory()->true_value());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
v8::Handle<Boolean> False() {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2011-03-25 14:09:14 +00:00
|
|
|
if (!EnsureInitializedForIsolate(isolate, "v8::False()")) {
|
|
|
|
return v8::Handle<Boolean>();
|
|
|
|
}
|
2013-06-13 09:27:09 +00:00
|
|
|
return ToApiHandle<Boolean>(isolate->factory()->false_value());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ResourceConstraints::ResourceConstraints()
|
|
|
|
: max_young_space_size_(0),
|
|
|
|
max_old_space_size_(0),
|
2010-11-10 08:38:42 +00:00
|
|
|
max_executable_size_(0),
|
2008-07-03 15:10:15 +00:00
|
|
|
stack_limit_(NULL) { }
|
|
|
|
|
|
|
|
|
|
|
|
bool SetResourceConstraints(ResourceConstraints* constraints) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = EnterIsolateIfNeeded();
|
|
|
|
|
2009-10-21 15:03:34 +00:00
|
|
|
int young_space_size = constraints->max_young_space_size();
|
2009-10-01 10:33:05 +00:00
|
|
|
int old_gen_size = constraints->max_old_space_size();
|
2010-11-10 08:38:42 +00:00
|
|
|
int max_executable_size = constraints->max_executable_size();
|
|
|
|
if (young_space_size != 0 || old_gen_size != 0 || max_executable_size != 0) {
|
2011-03-18 20:35:07 +00:00
|
|
|
// After initialization it's too late to change Heap constraints.
|
|
|
|
ASSERT(!isolate->IsInitialized());
|
|
|
|
bool result = isolate->heap()->ConfigureHeap(young_space_size / 2,
|
|
|
|
old_gen_size,
|
|
|
|
max_executable_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
|
|
|
}
|
|
|
|
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
|
|
|
if (IsDeadCheck(isolate, "V8::Persistent::New")) return NULL;
|
|
|
|
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
|
|
|
|
(*obj)->Verify();
|
|
|
|
#endif // DEBUG
|
2009-08-26 10:33:11 +00:00
|
|
|
return result.location();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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-06-03 08:17:04 +00:00
|
|
|
RevivableCallback weak_reference_callback) {
|
2013-05-29 08:32:45 +00:00
|
|
|
i::GlobalHandles::MakeWeak(object,
|
|
|
|
parameters,
|
2013-06-03 08:17:04 +00:00
|
|
|
weak_reference_callback);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-29 08:32:45 +00:00
|
|
|
void V8::ClearWeak(i::Object** obj) {
|
|
|
|
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 ---
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
HandleScope::HandleScope() {
|
2013-03-15 12:06:53 +00:00
|
|
|
Initialize(reinterpret_cast<Isolate*>(i::Isolate::Current()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HandleScope::HandleScope(Isolate* isolate) {
|
|
|
|
Initialize(isolate);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HandleScope::Initialize(Isolate* isolate) {
|
|
|
|
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
API_ENTRY_CHECK(internal_isolate, "HandleScope::HandleScope");
|
2011-03-18 20:35:07 +00:00
|
|
|
v8::ImplementationUtilities::HandleScopeData* current =
|
2013-03-15 12:06:53 +00:00
|
|
|
internal_isolate->handle_scope_data();
|
|
|
|
isolate_ = internal_isolate;
|
2011-03-18 20:35:07 +00:00
|
|
|
prev_next_ = current->next;
|
|
|
|
prev_limit_ = current->limit;
|
|
|
|
is_closed_ = false;
|
|
|
|
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() {
|
|
|
|
if (!is_closed_) {
|
2010-10-21 14:21:00 +00:00
|
|
|
Leave();
|
2009-01-23 17:22:23 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-21 14:21:00 +00:00
|
|
|
void HandleScope::Leave() {
|
2013-05-29 11:09:01 +00:00
|
|
|
return i::HandleScope::CloseScope(isolate_, prev_next_, prev_limit_);
|
2010-10-21 14:21:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-23 17:22:23 +00:00
|
|
|
int HandleScope::NumberOfHandles() {
|
2013-02-25 14:46:09 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (!EnsureInitializedForIsolate(isolate, "HandleScope::NumberOfHandles")) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return i::HandleScope::NumberOfHandles(isolate);
|
2009-01-23 17:22:23 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Object** HandleScope::CreateHandle(i::Object* value) {
|
2013-02-25 14:46:09 +00:00
|
|
|
return i::HandleScope::CreateHandle(i::Isolate::Current(), value);
|
2011-03-18 20:35:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-05 09:13:53 +00:00
|
|
|
i::Object** HandleScope::CreateHandle(i::Isolate* isolate, i::Object* value) {
|
|
|
|
ASSERT(isolate == i::Isolate::Current());
|
2013-02-25 14:46:09 +00:00
|
|
|
return i::HandleScope::CreateHandle(isolate, value);
|
2012-12-05 09:13:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Object** HandleScope::CreateHandle(i::HeapObject* value) {
|
|
|
|
ASSERT(value->IsHeapObject());
|
|
|
|
return reinterpret_cast<i::Object**>(
|
2013-02-25 14:46:09 +00:00
|
|
|
i::HandleScope::CreateHandle(value->GetIsolate(), value));
|
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-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::Context::Enter()")) return;
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->handle_scope_implementer()->EnterContext(env);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->handle_scope_implementer()->SaveContext(isolate->context());
|
|
|
|
isolate->set_context(*env);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Context::Exit() {
|
2011-06-07 13:09:01 +00:00
|
|
|
// Exit is essentially a static function and doesn't use the
|
|
|
|
// receiver, so we have to get the current isolate from the thread
|
|
|
|
// local.
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (!isolate->IsInitialized()) return;
|
|
|
|
|
|
|
|
if (!ApiCheck(isolate->handle_scope_implementer()->LeaveLastContext(),
|
2008-07-25 07:37:58 +00:00
|
|
|
"v8::Context::Exit()",
|
|
|
|
"Cannot exit non-entered context")) {
|
|
|
|
return;
|
|
|
|
}
|
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
|
|
|
// Content of 'last_context' could be NULL.
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Context* last_context =
|
|
|
|
isolate->handle_scope_implementer()->RestoreContext();
|
|
|
|
isolate->set_context(last_context);
|
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) {
|
|
|
|
ApiCheck(value->IsSmi(), location, "Not a Smi");
|
|
|
|
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);
|
2012-11-13 12:27:03 +00:00
|
|
|
ApiCheck(smi->IsSmi(), location, "Pointer is not aligned");
|
|
|
|
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);
|
|
|
|
bool ok = !IsDeadCheck(env->GetIsolate(), location) &&
|
|
|
|
ApiCheck(env->IsNativeContext(), location, "Not a native context") &&
|
|
|
|
ApiCheck(index >= 0, location, "Negative index");
|
|
|
|
if (!ok) return i::Handle<i::FixedArray>();
|
|
|
|
i::Handle<i::FixedArray> data(env->embedder_data());
|
|
|
|
if (index < data->length()) return data;
|
|
|
|
if (!can_grow) {
|
|
|
|
Utils::ReportApiFailure(location, "Index too large");
|
|
|
|
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;
|
|
|
|
data = env->GetIsolate()->factory()->CopySizeFixedArray(data, new_size);
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-26 10:33:11 +00:00
|
|
|
i::Object** v8::HandleScope::RawClose(i::Object** value) {
|
2008-07-03 15:10:15 +00:00
|
|
|
if (!ApiCheck(!is_closed_,
|
|
|
|
"v8::HandleScope::Close()",
|
|
|
|
"Local scope has already been closed")) {
|
|
|
|
return 0;
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
LOG_API(isolate_, "CloseHandleScope");
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Read the result before popping the handle block.
|
2010-03-25 14:07:17 +00:00
|
|
|
i::Object* result = NULL;
|
|
|
|
if (value != NULL) {
|
|
|
|
result = *value;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
is_closed_ = true;
|
2010-10-21 14:21:00 +00:00
|
|
|
Leave();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-03-25 14:07:17 +00:00
|
|
|
if (value == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Allocate a new handle on the previous handle block.
|
2012-11-16 08:38:11 +00:00
|
|
|
i::Handle<i::Object> handle(result, isolate_);
|
2009-08-26 10:33:11 +00:00
|
|
|
return handle.location();
|
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.
|
|
|
|
NeanderObject::NeanderObject(int size) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NeanderArray::NeanderArray() : obj_(2) {
|
|
|
|
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()) {
|
|
|
|
list = NeanderArray().value();
|
|
|
|
Utils::OpenHandle(templ)->set_property_list(*list);
|
|
|
|
}
|
|
|
|
NeanderArray array(list);
|
|
|
|
array.add(Utils::OpenHandle(*v8::Integer::New(length)));
|
|
|
|
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();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Template::Set()")) return;
|
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;
|
|
|
|
v8::Handle<v8::Data> data[kSize] = {
|
|
|
|
name,
|
|
|
|
value,
|
|
|
|
v8::Integer::New(attribute)};
|
|
|
|
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();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Template::SetAccessor()")) return;
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
ASSERT(!name.IsEmpty());
|
|
|
|
ASSERT(!getter.IsEmpty() || !setter.IsEmpty());
|
|
|
|
i::HandleScope scope(isolate);
|
|
|
|
const int kSize = 5;
|
|
|
|
v8::Handle<v8::Data> data[kSize] = {
|
|
|
|
name,
|
|
|
|
getter,
|
|
|
|
setter,
|
|
|
|
v8::Integer::New(attribute),
|
|
|
|
v8::Integer::New(access_control)};
|
|
|
|
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(
|
|
|
|
i::Handle<i::FunctionTemplateInfo> info) {
|
|
|
|
info->set_tag(i::Smi::FromInt(Consts::FUNCTION_TEMPLATE));
|
|
|
|
info->set_flag(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<ObjectTemplate> FunctionTemplate::PrototypeTemplate() {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::FunctionTemplate::PrototypeTemplate()")) {
|
2008-07-03 15:10:15 +00:00
|
|
|
return Local<ObjectTemplate>();
|
|
|
|
}
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2013-02-25 14:46:09 +00:00
|
|
|
i::Handle<i::Object> result(Utils::OpenHandle(this)->prototype_template(),
|
|
|
|
isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
if (result->IsUndefined()) {
|
|
|
|
result = Utils::OpenHandle(*ObjectTemplate::New());
|
|
|
|
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();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::FunctionTemplate::Inherit()")) return;
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
Utils::OpenHandle(this)->set_parent_template(*Utils::OpenHandle(*value));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-27 11:47:52 +00:00
|
|
|
Local<FunctionTemplate> FunctionTemplate::New(
|
|
|
|
FunctionCallback callback,
|
2013-05-21 06:36:24 +00:00
|
|
|
v8::Handle<Value> data,
|
|
|
|
v8::Handle<Signature> signature,
|
|
|
|
int length) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
EnsureInitializedForIsolate(isolate, "v8::FunctionTemplate::New()");
|
|
|
|
LOG_API(isolate, "FunctionTemplate::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-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);
|
2011-03-18 20:35:07 +00:00
|
|
|
int next_serial_number = isolate->next_serial_number();
|
|
|
|
isolate->set_next_serial_number(next_serial_number + 1);
|
|
|
|
obj->set_serial_number(i::Smi::FromInt(next_serial_number));
|
2013-05-24 07:59:33 +00:00
|
|
|
if (callback != 0) {
|
2008-07-03 15:10:15 +00:00
|
|
|
if (data.IsEmpty()) data = v8::Undefined();
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<Signature> Signature::New(Handle<FunctionTemplate> receiver,
|
|
|
|
int argc, Handle<FunctionTemplate> argv[]) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
EnsureInitializedForIsolate(isolate, "v8::Signature::New()");
|
|
|
|
LOG_API(isolate, "Signature::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-23 09:02:15 +00:00
|
|
|
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) {
|
2011-03-23 09:02:15 +00:00
|
|
|
i::Handle<i::FixedArray> args = 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-08 07:45:11 +00:00
|
|
|
Local<AccessorSignature> AccessorSignature::New(
|
|
|
|
Handle<FunctionTemplate> receiver) {
|
|
|
|
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(
|
|
|
|
static_cast<DeclaredAccessorDescriptor*>(previous_descriptor));
|
|
|
|
}
|
|
|
|
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>
|
|
|
|
ObjectOperationDescriptor::NewInternalFieldDereference(
|
|
|
|
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++) {
|
|
|
|
if (obj->IsInstanceOf(i::FunctionTemplateInfo::cast(types->get(i))))
|
|
|
|
return i + 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-19 11:47:34 +00:00
|
|
|
#define SET_FIELD_WRAPPED(obj, setter, cdata) do { \
|
2013-09-02 09:27:27 +00:00
|
|
|
i::Handle<i::Object> foreign = FromCData(obj->GetIsolate(), cdata); \
|
2011-05-19 11:47:34 +00:00
|
|
|
(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-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::FunctionTemplate::SetCallHandler()")) return;
|
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);
|
2008-07-03 15:10:15 +00:00
|
|
|
if (data.IsEmpty()) data = v8::Undefined();
|
|
|
|
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);
|
2008-10-30 12:51:06 +00:00
|
|
|
if (settings & PROHIBITS_OVERWRITING) obj->set_prohibits_overwriting(true);
|
2008-07-03 15:10:15 +00:00
|
|
|
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(
|
2010-05-25 12:14:49 +00:00
|
|
|
v8::Handle<String> name,
|
2013-08-27 11:47:52 +00:00
|
|
|
Getter getter,
|
|
|
|
Setter setter,
|
2010-05-25 12:14:49 +00:00
|
|
|
v8::Handle<Value> data,
|
|
|
|
v8::AccessControl settings,
|
2012-06-08 07:45:11 +00:00
|
|
|
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);
|
|
|
|
if (data.IsEmpty()) data = v8::Undefined();
|
|
|
|
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(
|
|
|
|
v8::Handle<String> name,
|
|
|
|
v8::Handle<v8::DeclaredAccessorDescriptor> descriptor,
|
2013-05-21 06:36:24 +00:00
|
|
|
void* setter_ignored,
|
|
|
|
void* data_ignored,
|
2013-03-07 11:42:58 +00:00
|
|
|
v8::AccessControl settings,
|
|
|
|
v8::PropertyAttribute attributes,
|
|
|
|
v8::Handle<AccessorSignature> signature) {
|
|
|
|
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();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::FunctionTemplate::InstanceTemplate()")
|
2008-07-03 15:10:15 +00:00
|
|
|
|| EmptyCheck("v8::FunctionTemplate::InstanceTemplate()", this))
|
|
|
|
return Local<ObjectTemplate>();
|
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-06-13 09:27:09 +00:00
|
|
|
ObjectTemplate::New(ToApiHandle<FunctionTemplate>(handle));
|
|
|
|
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();
|
|
|
|
if (IsDeadCheck(isolate, "v8::FunctionTemplate::SetLength()")) return;
|
|
|
|
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();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::FunctionTemplate::SetClassName()")) return;
|
2011-03-24 18:49:45 +00:00
|
|
|
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();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::FunctionTemplate::SetHiddenPrototype()")) {
|
|
|
|
return;
|
|
|
|
}
|
2011-03-24 18:49:45 +00:00
|
|
|
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();
|
2012-11-29 14:53:44 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::FunctionTemplate::ReadOnlyPrototype()")) {
|
2011-06-22 12:39:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
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();
|
|
|
|
if (IsDeadCheck(isolate, "v8::FunctionTemplate::RemovePrototype()")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
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 ---
|
|
|
|
|
|
|
|
|
|
|
|
Local<ObjectTemplate> ObjectTemplate::New() {
|
|
|
|
return New(Local<FunctionTemplate>());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<ObjectTemplate> ObjectTemplate::New(
|
|
|
|
v8::Handle<FunctionTemplate> constructor) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::ObjectTemplate::New()")) {
|
|
|
|
return Local<ObjectTemplate>();
|
|
|
|
}
|
|
|
|
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.
|
|
|
|
static void EnsureConstructor(ObjectTemplate* object_template) {
|
|
|
|
if (Utils::OpenHandle(object_template)->constructor()->IsUndefined()) {
|
|
|
|
Local<FunctionTemplate> templ = FunctionTemplate::New();
|
|
|
|
i::Handle<i::FunctionTemplateInfo> constructor = Utils::OpenHandle(*templ);
|
|
|
|
constructor->set_instance_template(*Utils::OpenHandle(object_template));
|
|
|
|
Utils::OpenHandle(object_template)->set_constructor(*constructor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-07 11:42:58 +00:00
|
|
|
static inline void AddPropertyToFunctionTemplate(
|
|
|
|
i::Handle<i::FunctionTemplateInfo> cons,
|
|
|
|
i::Handle<i::AccessorInfo> obj) {
|
|
|
|
i::Handle<i::Object> list(cons->property_accessors(), cons->GetIsolate());
|
|
|
|
if (list->IsUndefined()) {
|
|
|
|
list = NeanderArray().value();
|
|
|
|
cons->set_property_accessors(*list);
|
|
|
|
}
|
|
|
|
NeanderArray array(list);
|
|
|
|
array.add(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-21 06:36:24 +00:00
|
|
|
template<typename Setter, typename Getter, typename Data>
|
|
|
|
static bool ObjectTemplateSetAccessor(
|
|
|
|
ObjectTemplate* object_template,
|
|
|
|
v8::Handle<String> name,
|
|
|
|
Getter getter,
|
|
|
|
Setter setter,
|
|
|
|
Data data,
|
|
|
|
AccessControl settings,
|
|
|
|
PropertyAttribute attribute,
|
|
|
|
v8::Handle<AccessorSignature> signature) {
|
|
|
|
i::Isolate* isolate = Utils::OpenHandle(object_template)->GetIsolate();
|
|
|
|
if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetAccessor()")) return false;
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
i::HandleScope scope(isolate);
|
|
|
|
EnsureConstructor(object_template);
|
|
|
|
i::FunctionTemplateInfo* constructor = i::FunctionTemplateInfo::cast(
|
|
|
|
Utils::OpenHandle(object_template)->constructor());
|
|
|
|
i::Handle<i::FunctionTemplateInfo> cons(constructor);
|
|
|
|
i::Handle<i::AccessorInfo> obj = MakeAccessorInfo(
|
|
|
|
name, getter, setter, data, settings, attribute, signature);
|
|
|
|
if (obj.is_null()) return false;
|
|
|
|
AddPropertyToFunctionTemplate(cons, obj);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
ObjectTemplateSetAccessor(
|
|
|
|
this, name, getter, setter, data, settings, attribute, signature);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-21 06:36:24 +00:00
|
|
|
bool ObjectTemplate::SetAccessor(Handle<String> name,
|
|
|
|
Handle<DeclaredAccessorDescriptor> descriptor,
|
|
|
|
AccessControl settings,
|
|
|
|
PropertyAttribute attribute,
|
|
|
|
Handle<AccessorSignature> signature) {
|
|
|
|
void* null = NULL;
|
|
|
|
return ObjectTemplateSetAccessor(
|
|
|
|
this, name, descriptor, null, null, settings, attribute, signature);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetNamedPropertyHandler()")) {
|
|
|
|
return;
|
|
|
|
}
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
|
|
|
i::HandleScope scope(isolate);
|
2013-08-27 11:47:52 +00:00
|
|
|
EnsureConstructor(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-08-27 11:47:52 +00:00
|
|
|
if (data.IsEmpty()) data = v8::Undefined();
|
|
|
|
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();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::ObjectTemplate::MarkAsUndetectable()")) return;
|
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
|
|
|
EnsureConstructor(this);
|
|
|
|
i::FunctionTemplateInfo* constructor =
|
|
|
|
i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor());
|
|
|
|
i::Handle<i::FunctionTemplateInfo> cons(constructor);
|
|
|
|
cons->set_undetectable(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ObjectTemplate::SetAccessCheckCallbacks(
|
|
|
|
NamedSecurityCallback named_callback,
|
|
|
|
IndexedSecurityCallback indexed_callback,
|
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
|
|
|
Handle<Value> data,
|
|
|
|
bool turned_on_by_default) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetAccessCheckCallbacks()")) {
|
|
|
|
return;
|
|
|
|
}
|
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
|
|
|
EnsureConstructor(this);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
if (data.IsEmpty()) data = v8::Undefined();
|
|
|
|
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(
|
|
|
|
IndexedPropertyGetterCallback getter,
|
|
|
|
IndexedPropertySetterCallback setter,
|
|
|
|
IndexedPropertyQueryCallback query,
|
|
|
|
IndexedPropertyDeleterCallback remover,
|
|
|
|
IndexedPropertyEnumeratorCallback enumerator,
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<Value> data) {
|
2013-08-27 11:47:52 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetIndexedPropertyHandler()")) {
|
|
|
|
return;
|
|
|
|
}
|
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-27 11:47:52 +00:00
|
|
|
EnsureConstructor(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-08-27 11:47:52 +00:00
|
|
|
if (data.IsEmpty()) data = v8::Undefined();
|
|
|
|
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-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate,
|
|
|
|
"v8::ObjectTemplate::SetCallAsFunctionHandler()")) {
|
|
|
|
return;
|
|
|
|
}
|
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-27 11:47:52 +00:00
|
|
|
EnsureConstructor(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);
|
|
|
|
if (data.IsEmpty()) data = v8::Undefined();
|
|
|
|
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() {
|
2011-03-24 18:49:45 +00:00
|
|
|
if (IsDeadCheck(Utils::OpenHandle(this)->GetIsolate(),
|
2011-03-18 20:35:07 +00:00
|
|
|
"v8::ObjectTemplate::InternalFieldCount()")) {
|
2008-07-16 07:07:30 +00:00
|
|
|
return 0;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2008-07-16 07:07:30 +00:00
|
|
|
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();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetInternalFieldCount()")) {
|
|
|
|
return;
|
|
|
|
}
|
2008-07-16 07:07:30 +00:00
|
|
|
if (!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.
|
|
|
|
EnsureConstructor(this);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-16 07:07:30 +00:00
|
|
|
// --- S c r i p t D a t a ---
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
ScriptData* ScriptData::PreCompile(const char* input, int length) {
|
2012-03-12 12:35:28 +00:00
|
|
|
i::Utf8ToUtf16CharacterStream stream(
|
2010-12-07 14:03:59 +00:00
|
|
|
reinterpret_cast<const unsigned char*>(input), length);
|
Refactor parser mode configuration for correctness
This patch refactors the parser and preparser interface to be more
readable and type-safe. It has no behavior changes.
Previously, parsers and preparsers were configured via bitfield called
parser_flags in the Parser constructor, and flags in
PreParser::PreParseProgram, ParserApi::Parse, and ParserApi::PreParse.
This was error-prone in practice: six call sites passed incorrectly
typed values to this interface (a boolean FLAG value, a boolean false
and a boolean true value). None of these errors were caught by the
compiler because it's just an "int".
The parser flags interface was also awkward because it encoded a
language mode, but the language mode was only used to turn on harmony
scoping or not -- it wasn't used to actually set the parser's language
mode.
Fundamentally these errors came in because of the desire for a
procedural parser interface, in ParserApi. Because we need to be able
to configure the parser in various ways, the flags argument got added;
but no one understood how to use the flags properly. Also they were
only used by constructors: callers packed bits, and the constructors
unpacked them into booleans on the parser or preparser.
The solution is to allow parser construction, configuration, and
invocation to be separated. This patch does that.
It passes the existing tests.
BUG=
Review URL: https://codereview.chromium.org/13450007
Patch from Andy Wingo <wingo@igalia.com>.
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14151 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-04-05 13:01:06 +00:00
|
|
|
return i::PreParserApi::PreParse(&stream);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-08 06:20:49 +00:00
|
|
|
ScriptData* ScriptData::PreCompile(v8::Handle<String> source) {
|
|
|
|
i::Handle<i::String> str = Utils::OpenHandle(*source);
|
2010-12-07 14:03:59 +00:00
|
|
|
if (str->IsExternalTwoByteString()) {
|
2012-03-12 12:35:28 +00:00
|
|
|
i::ExternalTwoByteStringUtf16CharacterStream stream(
|
2010-12-07 14:03:59 +00:00
|
|
|
i::Handle<i::ExternalTwoByteString>::cast(str), 0, str->length());
|
Refactor parser mode configuration for correctness
This patch refactors the parser and preparser interface to be more
readable and type-safe. It has no behavior changes.
Previously, parsers and preparsers were configured via bitfield called
parser_flags in the Parser constructor, and flags in
PreParser::PreParseProgram, ParserApi::Parse, and ParserApi::PreParse.
This was error-prone in practice: six call sites passed incorrectly
typed values to this interface (a boolean FLAG value, a boolean false
and a boolean true value). None of these errors were caught by the
compiler because it's just an "int".
The parser flags interface was also awkward because it encoded a
language mode, but the language mode was only used to turn on harmony
scoping or not -- it wasn't used to actually set the parser's language
mode.
Fundamentally these errors came in because of the desire for a
procedural parser interface, in ParserApi. Because we need to be able
to configure the parser in various ways, the flags argument got added;
but no one understood how to use the flags properly. Also they were
only used by constructors: callers packed bits, and the constructors
unpacked them into booleans on the parser or preparser.
The solution is to allow parser construction, configuration, and
invocation to be separated. This patch does that.
It passes the existing tests.
BUG=
Review URL: https://codereview.chromium.org/13450007
Patch from Andy Wingo <wingo@igalia.com>.
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14151 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-04-05 13:01:06 +00:00
|
|
|
return i::PreParserApi::PreParse(&stream);
|
2010-12-07 14:03:59 +00:00
|
|
|
} else {
|
2012-03-12 12:35:28 +00:00
|
|
|
i::GenericStringUtf16CharacterStream stream(str, 0, str->length());
|
Refactor parser mode configuration for correctness
This patch refactors the parser and preparser interface to be more
readable and type-safe. It has no behavior changes.
Previously, parsers and preparsers were configured via bitfield called
parser_flags in the Parser constructor, and flags in
PreParser::PreParseProgram, ParserApi::Parse, and ParserApi::PreParse.
This was error-prone in practice: six call sites passed incorrectly
typed values to this interface (a boolean FLAG value, a boolean false
and a boolean true value). None of these errors were caught by the
compiler because it's just an "int".
The parser flags interface was also awkward because it encoded a
language mode, but the language mode was only used to turn on harmony
scoping or not -- it wasn't used to actually set the parser's language
mode.
Fundamentally these errors came in because of the desire for a
procedural parser interface, in ParserApi. Because we need to be able
to configure the parser in various ways, the flags argument got added;
but no one understood how to use the flags properly. Also they were
only used by constructors: callers packed bits, and the constructors
unpacked them into booleans on the parser or preparser.
The solution is to allow parser construction, configuration, and
invocation to be separated. This patch does that.
It passes the existing tests.
BUG=
Review URL: https://codereview.chromium.org/13450007
Patch from Andy Wingo <wingo@igalia.com>.
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14151 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-04-05 13:01:06 +00:00
|
|
|
return i::PreParserApi::PreParse(&stream);
|
2010-12-07 14:03:59 +00:00
|
|
|
}
|
2010-06-08 06:20:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-25 06:38:19 +00:00
|
|
|
ScriptData* ScriptData::New(const char* data, int length) {
|
|
|
|
// Return an empty ScriptData if the length is obviously invalid.
|
|
|
|
if (length % sizeof(unsigned) != 0) {
|
2010-09-07 12:52:16 +00:00
|
|
|
return new i::ScriptDataImpl();
|
2010-05-25 06:38:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the data to ensure it is properly aligned.
|
|
|
|
int deserialized_data_length = length / sizeof(unsigned);
|
2010-09-07 12:52:16 +00:00
|
|
|
// If aligned, don't create a copy of the data.
|
|
|
|
if (reinterpret_cast<intptr_t>(data) % sizeof(unsigned) == 0) {
|
|
|
|
return new i::ScriptDataImpl(data, length);
|
|
|
|
}
|
|
|
|
// Copy the data to align it.
|
2010-05-25 06:38:19 +00:00
|
|
|
unsigned* deserialized_data = i::NewArray<unsigned>(deserialized_data_length);
|
2013-04-16 12:30:51 +00:00
|
|
|
i::CopyBytes(reinterpret_cast<char*>(deserialized_data),
|
|
|
|
data, static_cast<size_t>(length));
|
2010-05-25 06:38:19 +00:00
|
|
|
|
|
|
|
return new i::ScriptDataImpl(
|
|
|
|
i::Vector<unsigned>(deserialized_data, deserialized_data_length));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// --- S c r i p t ---
|
|
|
|
|
|
|
|
|
2009-08-17 11:41:00 +00:00
|
|
|
Local<Script> Script::New(v8::Handle<String> source,
|
|
|
|
v8::ScriptOrigin* origin,
|
2010-02-16 15:15:31 +00:00
|
|
|
v8::ScriptData* pre_data,
|
|
|
|
v8::Handle<String> script_data) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
ON_BAILOUT(isolate, "v8::Script::New()", return Local<Script>());
|
|
|
|
LOG_API(isolate, "Script::New");
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2011-12-08 16:07:07 +00:00
|
|
|
i::SharedFunctionInfo* raw_result = NULL;
|
|
|
|
{ i::HandleScope scope(isolate);
|
|
|
|
i::Handle<i::String> str = Utils::OpenHandle(*source);
|
|
|
|
i::Handle<i::Object> name_obj;
|
|
|
|
int line_offset = 0;
|
|
|
|
int column_offset = 0;
|
2013-07-30 17:05:50 +00:00
|
|
|
bool is_shared_cross_origin = false;
|
2011-12-08 16:07:07 +00:00
|
|
|
if (origin != NULL) {
|
|
|
|
if (!origin->ResourceName().IsEmpty()) {
|
|
|
|
name_obj = Utils::OpenHandle(*origin->ResourceName());
|
|
|
|
}
|
|
|
|
if (!origin->ResourceLineOffset().IsEmpty()) {
|
|
|
|
line_offset = static_cast<int>(origin->ResourceLineOffset()->Value());
|
|
|
|
}
|
|
|
|
if (!origin->ResourceColumnOffset().IsEmpty()) {
|
|
|
|
column_offset =
|
|
|
|
static_cast<int>(origin->ResourceColumnOffset()->Value());
|
|
|
|
}
|
2013-07-30 17:05:50 +00:00
|
|
|
if (!origin->ResourceIsSharedCrossOrigin().IsEmpty()) {
|
|
|
|
is_shared_cross_origin =
|
|
|
|
origin->ResourceIsSharedCrossOrigin() == v8::True();
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2011-12-08 16:07:07 +00:00
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
|
|
|
i::ScriptDataImpl* pre_data_impl =
|
|
|
|
static_cast<i::ScriptDataImpl*>(pre_data);
|
|
|
|
// We assert that the pre-data is sane, even though we can actually
|
|
|
|
// handle it if it turns out not to be in release mode.
|
|
|
|
ASSERT(pre_data_impl == NULL || pre_data_impl->SanityCheck());
|
|
|
|
// If the pre-data isn't sane we simply ignore it
|
|
|
|
if (pre_data_impl != NULL && !pre_data_impl->SanityCheck()) {
|
|
|
|
pre_data_impl = NULL;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2011-12-08 16:07:07 +00:00
|
|
|
i::Handle<i::SharedFunctionInfo> result =
|
2010-03-17 08:14:59 +00:00
|
|
|
i::Compiler::Compile(str,
|
|
|
|
name_obj,
|
|
|
|
line_offset,
|
|
|
|
column_offset,
|
2013-07-30 17:05:50 +00:00
|
|
|
is_shared_cross_origin,
|
2012-08-28 11:25:08 +00:00
|
|
|
isolate->global_context(),
|
2010-03-17 08:14:59 +00:00
|
|
|
NULL,
|
|
|
|
pre_data_impl,
|
2012-09-05 16:06:53 +00:00
|
|
|
Utils::OpenHandle(*script_data, true),
|
2010-03-17 08:14:59 +00:00
|
|
|
i::NOT_NATIVES_CODE);
|
2011-12-08 16:07:07 +00:00
|
|
|
has_pending_exception = result.is_null();
|
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<Script>());
|
|
|
|
raw_result = *result;
|
|
|
|
}
|
|
|
|
i::Handle<i::SharedFunctionInfo> result(raw_result, isolate);
|
2013-06-13 09:27:09 +00:00
|
|
|
return ToApiHandle<Script>(result);
|
2009-08-17 11:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<Script> Script::New(v8::Handle<String> source,
|
|
|
|
v8::Handle<Value> file_name) {
|
|
|
|
ScriptOrigin origin(file_name);
|
|
|
|
return New(source, &origin);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<Script> Script::Compile(v8::Handle<String> source,
|
|
|
|
v8::ScriptOrigin* origin,
|
2010-02-16 15:15:31 +00:00
|
|
|
v8::ScriptData* pre_data,
|
|
|
|
v8::Handle<String> script_data) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
ON_BAILOUT(isolate, "v8::Script::Compile()", return Local<Script>());
|
|
|
|
LOG_API(isolate, "Script::Compile");
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2010-02-16 15:15:31 +00:00
|
|
|
Local<Script> generic = New(source, origin, pre_data, script_data);
|
2009-08-17 11:41:00 +00:00
|
|
|
if (generic.IsEmpty())
|
|
|
|
return generic;
|
2010-03-23 06:04:44 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(*generic);
|
|
|
|
i::Handle<i::SharedFunctionInfo> function =
|
|
|
|
i::Handle<i::SharedFunctionInfo>(i::SharedFunctionInfo::cast(*obj));
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::JSFunction> result =
|
2011-03-23 09:02:15 +00:00
|
|
|
isolate->factory()->NewFunctionFromSharedFunctionInfo(
|
2011-03-18 20:35:07 +00:00
|
|
|
function,
|
2012-08-28 11:25:08 +00:00
|
|
|
isolate->global_context());
|
2013-06-13 09:27:09 +00:00
|
|
|
return ToApiHandle<Script>(result);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-14 13:41:48 +00:00
|
|
|
Local<Script> Script::Compile(v8::Handle<String> source,
|
2010-02-16 15:15:31 +00:00
|
|
|
v8::Handle<Value> file_name,
|
|
|
|
v8::Handle<String> script_data) {
|
2008-08-14 13:41:48 +00:00
|
|
|
ScriptOrigin origin(file_name);
|
2010-02-16 15:15:31 +00:00
|
|
|
return Compile(source, &origin, 0, script_data);
|
2008-08-14 13:41:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Local<Value> Script::Run() {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
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);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Object* raw_result = NULL;
|
|
|
|
{
|
2011-03-24 18:49:45 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2010-03-23 06:04:44 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::JSFunction> fun;
|
|
|
|
if (obj->IsSharedFunctionInfo()) {
|
|
|
|
i::Handle<i::SharedFunctionInfo>
|
2011-03-24 18:49:45 +00:00
|
|
|
function_info(i::SharedFunctionInfo::cast(*obj), isolate);
|
2011-03-23 09:02:15 +00:00
|
|
|
fun = isolate->factory()->NewFunctionFromSharedFunctionInfo(
|
2012-08-28 11:25:08 +00:00
|
|
|
function_info, isolate->global_context());
|
2010-03-23 06:04:44 +00:00
|
|
|
} else {
|
2011-03-24 18:49:45 +00:00
|
|
|
fun = i::Handle<i::JSFunction>(i::JSFunction::cast(*obj), isolate);
|
2009-08-17 11:41:00 +00:00
|
|
|
}
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Handle<i::Object> receiver(
|
2011-03-24 18:49:45 +00:00
|
|
|
isolate->context()->global_proxy(), isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> result =
|
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::Execution::Call(fun, receiver, 0, NULL, &has_pending_exception);
|
2012-01-04 08:48:35 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Value>());
|
2008-07-03 15:10:15 +00:00
|
|
|
raw_result = *result;
|
|
|
|
}
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Handle<i::Object> result(raw_result, isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::ToLocal(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-23 06:04:44 +00:00
|
|
|
static i::Handle<i::SharedFunctionInfo> OpenScript(Script* script) {
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(script);
|
|
|
|
i::Handle<i::SharedFunctionInfo> result;
|
|
|
|
if (obj->IsSharedFunctionInfo()) {
|
|
|
|
result =
|
|
|
|
i::Handle<i::SharedFunctionInfo>(i::SharedFunctionInfo::cast(*obj));
|
|
|
|
} else {
|
|
|
|
result =
|
|
|
|
i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared());
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-10 08:10:50 +00:00
|
|
|
Local<Value> Script::Id() {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
ON_BAILOUT(isolate, "v8::Script::Id()", return Local<Value>());
|
|
|
|
LOG_API(isolate, "Script::Id");
|
2009-03-10 08:10:50 +00:00
|
|
|
i::Object* raw_id = NULL;
|
|
|
|
{
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2010-03-23 06:04:44 +00:00
|
|
|
i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this);
|
|
|
|
i::Handle<i::Script> script(i::Script::cast(function_info->script()));
|
2013-02-25 14:46:09 +00:00
|
|
|
i::Handle<i::Object> id(script->id(), isolate);
|
2009-03-10 08:10:50 +00:00
|
|
|
raw_id = *id;
|
|
|
|
}
|
2013-02-25 14:46:09 +00:00
|
|
|
i::Handle<i::Object> id(raw_id, isolate);
|
2009-03-10 08:10:50 +00:00
|
|
|
return Utils::ToLocal(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-25 14:57:47 +00:00
|
|
|
int Script::GetId() {
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
ON_BAILOUT(isolate, "v8::Script::Id()", return -1);
|
|
|
|
LOG_API(isolate, "Script::Id");
|
|
|
|
{
|
|
|
|
i::HandleScope scope(isolate);
|
|
|
|
i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this);
|
|
|
|
i::Handle<i::Script> script(i::Script::cast(function_info->script()));
|
|
|
|
return script->id()->value();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-12 12:48:27 +00:00
|
|
|
int Script::GetLineNumber(int code_pos) {
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
ON_BAILOUT(isolate, "v8::Script::GetLineNumber()", return -1);
|
|
|
|
LOG_API(isolate, "Script::GetLineNumber");
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
if (obj->IsScript()) {
|
|
|
|
i::Handle<i::Script> script = i::Handle<i::Script>(i::Script::cast(*obj));
|
|
|
|
return i::GetScriptLineNumber(script, code_pos);
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Value> Script::GetScriptName() {
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
ON_BAILOUT(isolate, "v8::Script::GetName()", return Handle<String>());
|
|
|
|
LOG_API(isolate, "Script::GetName");
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
if (obj->IsScript()) {
|
|
|
|
i::Object* name = i::Script::cast(*obj)->name();
|
|
|
|
return Utils::ToLocal(i::Handle<i::Object>(name, isolate));
|
|
|
|
} else {
|
|
|
|
return Handle<String>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-27 14:10:48 +00:00
|
|
|
void Script::SetData(v8::Handle<String> data) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
ON_BAILOUT(isolate, "v8::Script::SetData()", return);
|
|
|
|
LOG_API(isolate, "Script::SetData");
|
2009-04-21 07:22:06 +00:00
|
|
|
{
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2010-03-23 06:04:44 +00:00
|
|
|
i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this);
|
2009-04-21 07:22:06 +00:00
|
|
|
i::Handle<i::Object> raw_data = Utils::OpenHandle(*data);
|
2010-03-23 06:04:44 +00:00
|
|
|
i::Handle<i::Script> script(i::Script::cast(function_info->script()));
|
2009-04-21 07:22:06 +00:00
|
|
|
script->set_data(*raw_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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()),
|
|
|
|
next_(isolate_->try_catch_handler_address()),
|
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();
|
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-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(reinterpret_cast<Isolate*>(isolate_));
|
2009-11-03 08:53:34 +00:00
|
|
|
v8::Local<v8::Value> exc = v8::Local<v8::Value>::New(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);
|
2009-11-03 08:53:34 +00:00
|
|
|
v8::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);
|
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;
|
|
|
|
return v8::Undefined();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
2011-06-07 15:01:52 +00:00
|
|
|
if (!obj->HasProperty(*name)) return v8::Local<Value>();
|
2013-02-25 14:46:09 +00:00
|
|
|
i::Handle<i::Object> value = i::GetProperty(isolate_, obj, name);
|
2011-07-04 13:29:56 +00:00
|
|
|
if (value.is_null()) return v8::Local<Value>();
|
|
|
|
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-03-15 12:06:53 +00:00
|
|
|
HandleScope 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);
|
|
|
|
return scope.Close(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::Message::GetScriptResourceName()")) {
|
2008-07-03 15:10:15 +00:00
|
|
|
return Local<String>();
|
|
|
|
}
|
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));
|
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);
|
2008-10-23 08:25:23 +00:00
|
|
|
return scope.Close(Utils::ToLocal(resource_name));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-21 07:22:06 +00:00
|
|
|
v8::Handle<Value> Message::GetScriptData() const {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::Message::GetScriptResourceData()")) {
|
2009-04-21 07:22:06 +00:00
|
|
|
return Local<Value>();
|
|
|
|
}
|
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));
|
2011-02-02 13:31:52 +00:00
|
|
|
i::Handle<i::JSMessageObject> message =
|
|
|
|
i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
|
2009-04-21 07:22:06 +00:00
|
|
|
// Return this.script.data.
|
|
|
|
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> data(i::Script::cast(script->value())->data(), isolate);
|
2009-04-21 07:22:06 +00:00
|
|
|
return scope.Close(Utils::ToLocal(data));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::Message::GetStackTrace()")) {
|
2010-07-12 13:17:27 +00:00
|
|
|
return Local<v8::StackTrace>();
|
|
|
|
}
|
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));
|
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);
|
|
|
|
return scope.Close(Utils::StackTraceToLocal(stackTrace));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
static i::Handle<i::Object> CallV8HeapFunction(const char* name,
|
|
|
|
i::Handle<i::Object> recv,
|
|
|
|
int argc,
|
2011-10-06 09:31:38 +00:00
|
|
|
i::Handle<i::Object> argv[],
|
2008-07-03 15:10:15 +00:00
|
|
|
bool* has_pending_exception) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2013-02-28 17:03:34 +00:00
|
|
|
i::Handle<i::String> fmt_str =
|
|
|
|
isolate->factory()->InternalizeUtf8String(name);
|
2010-10-25 15:22:03 +00:00
|
|
|
i::Object* object_fun =
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->js_builtins_object()->GetPropertyNoExceptionThrown(*fmt_str);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::JSFunction> fun =
|
|
|
|
i::Handle<i::JSFunction>(i::JSFunction::cast(object_fun));
|
|
|
|
i::Handle<i::Object> value =
|
|
|
|
i::Execution::Call(fun, recv, argc, argv, has_pending_exception);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static i::Handle<i::Object> CallV8HeapFunction(const char* name,
|
|
|
|
i::Handle<i::Object> data,
|
|
|
|
bool* has_pending_exception) {
|
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),
|
2008-07-03 15:10:15 +00:00
|
|
|
argv,
|
|
|
|
has_pending_exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> result = CallV8HeapFunction("GetLineNumber",
|
|
|
|
Utils::OpenHandle(this),
|
|
|
|
&has_pending_exception);
|
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();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::Message::GetStartPosition()")) 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);
|
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();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::Message::GetEndPosition()")) 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);
|
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();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::Message::GetStartColumn()")) {
|
|
|
|
return kNoColumnInfo;
|
|
|
|
}
|
2011-03-24 18:49:45 +00:00
|
|
|
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);
|
2008-09-09 18:55:41 +00:00
|
|
|
i::Handle<i::Object> start_col_obj = CallV8HeapFunction(
|
|
|
|
"GetPositionInLine",
|
|
|
|
data_obj,
|
|
|
|
&has_pending_exception);
|
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();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::Message::GetEndColumn()")) return kNoColumnInfo;
|
2011-03-24 18:49:45 +00:00
|
|
|
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);
|
2008-09-09 18:55:41 +00:00
|
|
|
i::Handle<i::Object> start_col_obj = CallV8HeapFunction(
|
|
|
|
"GetPositionInLine",
|
|
|
|
data_obj,
|
|
|
|
&has_pending_exception);
|
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();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Message::IsSharedCrossOrigin()")) return 0;
|
|
|
|
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-03-15 12:06:53 +00:00
|
|
|
HandleScope scope(reinterpret_cast<Isolate*>(isolate));
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> result = CallV8HeapFunction("GetSourceLine",
|
|
|
|
Utils::OpenHandle(this),
|
|
|
|
&has_pending_exception);
|
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()) {
|
|
|
|
return scope.Close(Utils::ToLocal(i::Handle<i::String>::cast(result)));
|
|
|
|
} else {
|
|
|
|
return Local<String>();
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Message::PrintCurrentStackTrace(FILE* out) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Message::PrintCurrentStackTrace()")) return;
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->PrintCurrentStackTrace(out);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::StackTrace::GetFrame()")) {
|
|
|
|
return Local<StackFrame>();
|
|
|
|
}
|
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));
|
2010-05-06 07:32:44 +00:00
|
|
|
i::Handle<i::JSArray> self = Utils::OpenHandle(this);
|
2010-10-25 15:22:03 +00:00
|
|
|
i::Object* raw_object = self->GetElementNoExceptionThrown(index);
|
|
|
|
i::Handle<i::JSObject> obj(i::JSObject::cast(raw_object));
|
2010-05-06 07:32:44 +00:00
|
|
|
return scope.Close(Utils::StackFrameToLocal(obj));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int StackTrace::GetFrameCount() const {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::StackTrace::GetFrameCount()")) return -1;
|
2011-03-24 18:49:45 +00:00
|
|
|
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();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::StackTrace::AsArray()")) Local<Array>();
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2010-05-06 07:32:44 +00:00
|
|
|
return Utils::ToLocal(Utils::OpenHandle(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<StackTrace> StackTrace::CurrentStackTrace(int frame_limit,
|
|
|
|
StackTraceOptions options) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::StackTrace::CurrentStackTrace()")) {
|
|
|
|
Local<StackTrace>();
|
|
|
|
}
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2010-07-12 13:17:27 +00:00
|
|
|
i::Handle<i::JSArray> stackTrace =
|
2011-03-18 20:35:07 +00:00
|
|
|
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();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::StackFrame::GetLineNumber()")) {
|
2010-05-06 07:32:44 +00:00
|
|
|
return Message::kNoLineNumberInfo;
|
|
|
|
}
|
2011-03-24 18:49:45 +00:00
|
|
|
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);
|
|
|
|
i::Handle<i::Object> line = GetProperty(self, "lineNumber");
|
|
|
|
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();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::StackFrame::GetColumn()")) {
|
2010-05-06 07:32:44 +00:00
|
|
|
return Message::kNoColumnInfo;
|
|
|
|
}
|
2011-03-24 18:49:45 +00:00
|
|
|
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);
|
|
|
|
i::Handle<i::Object> column = GetProperty(self, "column");
|
|
|
|
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();
|
|
|
|
if (IsDeadCheck(isolate, "v8::StackFrame::GetScriptId()")) {
|
|
|
|
return Message::kNoScriptIdInfo;
|
|
|
|
}
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
i::HandleScope scope(isolate);
|
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> scriptId = GetProperty(self, "scriptId");
|
|
|
|
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();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::StackFrame::GetScriptName()")) {
|
|
|
|
return Local<String>();
|
|
|
|
}
|
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));
|
2010-05-06 07:32:44 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> name = GetProperty(self, "scriptName");
|
|
|
|
if (!name->IsString()) {
|
|
|
|
return Local<String>();
|
|
|
|
}
|
|
|
|
return scope.Close(Local<String>::Cast(Utils::ToLocal(name)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::StackFrame::GetScriptNameOrSourceURL()")) {
|
2010-10-05 08:53:51 +00:00
|
|
|
return Local<String>();
|
|
|
|
}
|
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));
|
2010-10-05 08:53:51 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> name = GetProperty(self, "scriptNameOrSourceURL");
|
|
|
|
if (!name->IsString()) {
|
|
|
|
return Local<String>();
|
|
|
|
}
|
|
|
|
return scope.Close(Local<String>::Cast(Utils::ToLocal(name)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::StackFrame::GetFunctionName()")) {
|
|
|
|
return Local<String>();
|
|
|
|
}
|
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));
|
2010-05-06 07:32:44 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> name = GetProperty(self, "functionName");
|
|
|
|
if (!name->IsString()) {
|
|
|
|
return Local<String>();
|
|
|
|
}
|
|
|
|
return scope.Close(Local<String>::Cast(Utils::ToLocal(name)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool StackFrame::IsEval() const {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::StackFrame::IsEval()")) 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-05-06 07:32:44 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> is_eval = GetProperty(self, "isEval");
|
|
|
|
return is_eval->IsTrue();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool StackFrame::IsConstructor() const {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::StackFrame::IsConstructor()")) 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-05-06 07:32:44 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> is_constructor = GetProperty(self, "isConstructor");
|
|
|
|
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) {
|
2013-08-05 11:14:46 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
EnsureInitializedForIsolate(isolate, "v8::JSON::Parse");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
i::HandleScope scope(isolate);
|
|
|
|
i::Handle<i::String> source = i::Handle<i::String>(
|
|
|
|
FlattenGetString(Utils::OpenHandle(*json_string)));
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
|
|
|
i::Handle<i::Object> result;
|
|
|
|
if (source->IsSeqOneByteString()) {
|
|
|
|
result = i::JsonParser<true>::Parse(source);
|
|
|
|
} else {
|
|
|
|
result = i::JsonParser<false>::Parse(source);
|
|
|
|
}
|
|
|
|
has_pending_exception = result.is_null();
|
|
|
|
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 {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsUndefined()")) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-04-18 15:51:34 +00:00
|
|
|
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 {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsNull()")) return false;
|
2012-04-18 15:51:34 +00:00
|
|
|
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 {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsTrue()")) return false;
|
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 {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsFalse()")) return false;
|
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 {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsFunction()")) {
|
|
|
|
return false;
|
|
|
|
}
|
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 {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsString()")) return false;
|
2009-08-26 10:33:11 +00:00
|
|
|
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 {
|
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsSymbol()")) return false;
|
|
|
|
return Utils::OpenHandle(this)->IsSymbol();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
bool Value::IsArray() const {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsArray()")) return false;
|
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 {
|
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsArrayBuffer()"))
|
|
|
|
return false;
|
|
|
|
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 {
|
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsArrayBuffer()"))
|
|
|
|
return false;
|
|
|
|
return Utils::OpenHandle(this)->IsJSTypedArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define TYPED_ARRAY_LIST(F) \
|
|
|
|
F(Uint8Array, kExternalUnsignedByteArray) \
|
|
|
|
F(Int8Array, kExternalByteArray) \
|
|
|
|
F(Uint16Array, kExternalUnsignedShortArray) \
|
|
|
|
F(Int16Array, kExternalShortArray) \
|
|
|
|
F(Uint32Array, kExternalUnsignedIntArray) \
|
|
|
|
F(Int32Array, kExternalIntArray) \
|
|
|
|
F(Float32Array, kExternalFloatArray) \
|
2013-05-02 11:36:48 +00:00
|
|
|
F(Float64Array, kExternalDoubleArray) \
|
|
|
|
F(Uint8ClampedArray, kExternalPixelArray)
|
2013-04-30 18:53:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define VALUE_IS_TYPED_ARRAY(TypedArray, type_const) \
|
|
|
|
bool Value::Is##TypedArray() const { \
|
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Value::Is" #TypedArray "()")) \
|
|
|
|
return false; \
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this); \
|
|
|
|
if (!obj->IsJSTypedArray()) return false; \
|
|
|
|
return i::JSTypedArray::cast(*obj)->type() == type_const; \
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_ARRAY_LIST(VALUE_IS_TYPED_ARRAY)
|
|
|
|
|
|
|
|
#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 {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsObject()")) return false;
|
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 {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsNumber()")) return false;
|
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 {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsBoolean()")) {
|
|
|
|
return false;
|
|
|
|
}
|
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 {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsExternal()")) {
|
|
|
|
return false;
|
|
|
|
}
|
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 {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsInt32()")) return false;
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
if (obj->IsSmi()) return true;
|
|
|
|
if (obj->IsNumber()) {
|
|
|
|
double value = obj->Number();
|
2012-01-10 10:05:45 +00:00
|
|
|
static const i::DoubleRepresentation minus_zero(-0.0);
|
|
|
|
i::DoubleRepresentation rep(value);
|
|
|
|
if (rep.bits == minus_zero.bits) {
|
|
|
|
return false;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
return i::FastI2D(i::FastD2I(value)) == value;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-03 13:44:20 +00:00
|
|
|
bool Value::IsUint32() const {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsUint32()")) return false;
|
2010-03-03 13:44:20 +00:00
|
|
|
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();
|
2012-01-10 10:05:45 +00:00
|
|
|
static const i::DoubleRepresentation minus_zero(-0.0);
|
|
|
|
i::DoubleRepresentation rep(value);
|
|
|
|
if (rep.bits == minus_zero.bits) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-03-03 13:44:20 +00:00
|
|
|
return i::FastUI2D(i::FastD2UI(value)) == value;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
bool Value::IsDate() const {
|
2011-03-28 09:11:14 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Value::IsDate()")) return false;
|
2008-10-23 08:25:23 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
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::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Value::IsStringObject()")) return false;
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
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 {
|
|
|
|
// TODO(svenpanne): these and other test functions should be written such
|
|
|
|
// that they do not use Isolate::Current().
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Value::IsSymbolObject()")) return false;
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
return obj->HasSpecificClassOf(isolate->heap()->Symbol_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-14 11:00:04 +00:00
|
|
|
bool Value::IsNumberObject() const {
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Value::IsNumberObject()")) return false;
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
2013-02-28 17:03:34 +00:00
|
|
|
return obj->HasSpecificClassOf(isolate->heap()->Number_string());
|
2011-07-14 11:00:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static i::Object* LookupBuiltin(i::Isolate* isolate,
|
|
|
|
const char* builtin_name) {
|
2013-02-28 17:03:34 +00:00
|
|
|
i::Handle<i::String> string =
|
|
|
|
isolate->factory()->InternalizeUtf8String(builtin_name);
|
2011-07-14 11:00:04 +00:00
|
|
|
i::Handle<i::JSBuiltinsObject> builtins = isolate->js_builtins_object();
|
2013-02-28 17:03:34 +00:00
|
|
|
return builtins->GetPropertyNoExceptionThrown(*string);
|
2011-07-14 11:00:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool CheckConstructor(i::Isolate* isolate,
|
|
|
|
i::Handle<i::JSObject> obj,
|
|
|
|
const char* class_name) {
|
2012-11-12 15:33:31 +00:00
|
|
|
i::Object* constr = obj->map()->constructor();
|
|
|
|
if (!constr->IsJSFunction()) return false;
|
|
|
|
i::JSFunction* func = i::JSFunction::cast(constr);
|
|
|
|
return func->shared()->native() &&
|
|
|
|
constr == LookupBuiltin(isolate, class_name);
|
2011-07-14 11:00:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Value::IsNativeError() const {
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Value::IsNativeError()")) return false;
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
if (obj->IsJSObject()) {
|
|
|
|
i::Handle<i::JSObject> js_obj(i::JSObject::cast(*obj));
|
|
|
|
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::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Value::IsBooleanObject()")) return false;
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
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 {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsRegExp()")) return false;
|
2010-08-10 09:53:56 +00:00
|
|
|
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();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Value::ToString()")) {
|
|
|
|
return Local<String>();
|
|
|
|
}
|
|
|
|
LOG_API(isolate, "ToString");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2013-09-03 06:59:01 +00:00
|
|
|
str = i::Execution::ToString(isolate, obj, &has_pending_exception);
|
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();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Value::ToDetailString()")) {
|
|
|
|
return Local<String>();
|
|
|
|
}
|
|
|
|
LOG_API(isolate, "ToDetailString");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2013-09-03 06:59:01 +00:00
|
|
|
str = i::Execution::ToDetailString(isolate, obj, &has_pending_exception);
|
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();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Value::ToObject()")) {
|
|
|
|
return Local<v8::Object>();
|
|
|
|
}
|
|
|
|
LOG_API(isolate, "ToObject");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2013-09-03 06:59:01 +00:00
|
|
|
val = i::Execution::ToObject(isolate, obj, &has_pending_exception);
|
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();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Value::ToBoolean()")) {
|
|
|
|
return Local<Boolean>();
|
|
|
|
}
|
|
|
|
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 {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Value::ToNumber()")) {
|
|
|
|
return Local<Number>();
|
|
|
|
}
|
|
|
|
LOG_API(isolate, "ToNumber");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2013-09-03 06:59:01 +00:00
|
|
|
num = i::Execution::ToNumber(isolate, obj, &has_pending_exception);
|
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 {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Value::ToInteger()")) return Local<Integer>();
|
|
|
|
LOG_API(isolate, "ToInteger");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2013-09-03 06:59:01 +00:00
|
|
|
num = i::Execution::ToInteger(isolate, obj, &has_pending_exception);
|
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);
|
2013-09-03 09:35:26 +00:00
|
|
|
ApiCheck(isolate != NULL && isolate->IsInitialized() && !isolate->IsDead(),
|
2013-06-25 08:11:50 +00:00
|
|
|
"v8::internal::Internals::CheckInitialized()",
|
|
|
|
"Isolate is not initialized or V8 has died");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-26 10:33:11 +00:00
|
|
|
void External::CheckCast(v8::Value* that) {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::External::Cast()")) return;
|
2012-11-13 12:27:03 +00:00
|
|
|
ApiCheck(Utils::OpenHandle(that)->IsExternal(),
|
2008-07-03 15:10:15 +00:00
|
|
|
"v8::External::Cast()",
|
|
|
|
"Could not convert to external");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-26 10:33:11 +00:00
|
|
|
void v8::Object::CheckCast(Value* that) {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Object::Cast()")) return;
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
|
|
|
ApiCheck(obj->IsJSObject(),
|
|
|
|
"v8::Object::Cast()",
|
|
|
|
"Could not convert to object");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-26 10:33:11 +00:00
|
|
|
void v8::Function::CheckCast(Value* that) {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Function::Cast()")) return;
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
|
|
|
ApiCheck(obj->IsJSFunction(),
|
|
|
|
"v8::Function::Cast()",
|
|
|
|
"Could not convert to function");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-26 10:33:11 +00:00
|
|
|
void v8::String::CheckCast(v8::Value* that) {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::String::Cast()")) return;
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
|
|
|
ApiCheck(obj->IsString(),
|
|
|
|
"v8::String::Cast()",
|
|
|
|
"Could not convert to string");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-10 12:16:29 +00:00
|
|
|
void v8::Symbol::CheckCast(v8::Value* that) {
|
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Symbol::Cast()")) return;
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
|
|
|
ApiCheck(obj->IsSymbol(),
|
|
|
|
"v8::Symbol::Cast()",
|
|
|
|
"Could not convert to symbol");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-26 10:33:11 +00:00
|
|
|
void v8::Number::CheckCast(v8::Value* that) {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Number::Cast()")) return;
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
|
|
|
ApiCheck(obj->IsNumber(),
|
|
|
|
"v8::Number::Cast()",
|
|
|
|
"Could not convert to number");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-26 10:33:11 +00:00
|
|
|
void v8::Integer::CheckCast(v8::Value* that) {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Integer::Cast()")) return;
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
|
|
|
ApiCheck(obj->IsNumber(),
|
|
|
|
"v8::Integer::Cast()",
|
|
|
|
"Could not convert to number");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-26 10:33:11 +00:00
|
|
|
void v8::Array::CheckCast(Value* that) {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Array::Cast()")) return;
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
|
|
|
ApiCheck(obj->IsJSArray(),
|
|
|
|
"v8::Array::Cast()",
|
|
|
|
"Could not convert to array");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-25 12:02:23 +00:00
|
|
|
void v8::ArrayBuffer::CheckCast(Value* that) {
|
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::ArrayBuffer::Cast()")) return;
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
|
|
|
ApiCheck(obj->IsJSArrayBuffer(),
|
|
|
|
"v8::ArrayBuffer::Cast()",
|
|
|
|
"Could not convert to ArrayBuffer");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-02 13:03:06 +00:00
|
|
|
void v8::ArrayBuffer::Allocator::Free(void* data) {
|
|
|
|
API_Fatal("v8::ArrayBuffer::Allocator::Free",
|
|
|
|
"Override Allocator::Free(void*, size_t)");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-24 11:23:50 +00:00
|
|
|
void v8::ArrayBufferView::CheckCast(Value* that) {
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
|
|
|
ApiCheck(obj->IsJSArrayBufferView(),
|
|
|
|
"v8::ArrayBufferView::Cast()",
|
|
|
|
"Could not convert to ArrayBufferView");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-29 11:09:03 +00:00
|
|
|
void v8::TypedArray::CheckCast(Value* that) {
|
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::TypedArray::Cast()")) return;
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
|
|
|
ApiCheck(obj->IsJSTypedArray(),
|
|
|
|
"v8::TypedArray::Cast()",
|
|
|
|
"Could not convert to TypedArray");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define CHECK_TYPED_ARRAY_CAST(ApiClass, typeConst) \
|
|
|
|
void v8::ApiClass::CheckCast(Value* that) { \
|
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::" #ApiClass "::Cast()")) \
|
|
|
|
return; \
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that); \
|
|
|
|
ApiCheck(obj->IsJSTypedArray() && \
|
|
|
|
i::JSTypedArray::cast(*obj)->type() == typeConst, \
|
|
|
|
"v8::" #ApiClass "::Cast()", \
|
|
|
|
"Could not convert to " #ApiClass); \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-30 18:53:27 +00:00
|
|
|
TYPED_ARRAY_LIST(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);
|
|
|
|
ApiCheck(obj->IsJSDataView(),
|
|
|
|
"v8::DataView::Cast()",
|
|
|
|
"Could not convert to DataView");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-26 10:33:11 +00:00
|
|
|
void v8::Date::CheckCast(v8::Value* that) {
|
2011-03-28 09:11:14 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Date::Cast()")) return;
|
2008-10-23 08:25:23 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
2013-02-28 17:03:34 +00:00
|
|
|
ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Date_string()),
|
2008-10-23 08:25:23 +00:00
|
|
|
"v8::Date::Cast()",
|
|
|
|
"Could not convert to date");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-14 11:00:04 +00:00
|
|
|
void v8::StringObject::CheckCast(v8::Value* that) {
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::StringObject::Cast()")) return;
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
2013-02-28 17:03:34 +00:00
|
|
|
ApiCheck(obj->HasSpecificClassOf(isolate->heap()->String_string()),
|
2011-07-14 11:00:04 +00:00
|
|
|
"v8::StringObject::Cast()",
|
|
|
|
"Could not convert to StringObject");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-10 12:16:29 +00:00
|
|
|
void v8::SymbolObject::CheckCast(v8::Value* that) {
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::SymbolObject::Cast()")) return;
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
|
|
|
ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Symbol_string()),
|
|
|
|
"v8::SymbolObject::Cast()",
|
|
|
|
"Could not convert to SymbolObject");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-14 11:00:04 +00:00
|
|
|
void v8::NumberObject::CheckCast(v8::Value* that) {
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::NumberObject::Cast()")) return;
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
2013-02-28 17:03:34 +00:00
|
|
|
ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Number_string()),
|
2011-07-14 11:00:04 +00:00
|
|
|
"v8::NumberObject::Cast()",
|
|
|
|
"Could not convert to NumberObject");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void v8::BooleanObject::CheckCast(v8::Value* that) {
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::BooleanObject::Cast()")) return;
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
2013-02-28 17:03:34 +00:00
|
|
|
ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Boolean_string()),
|
2011-07-14 11:00:04 +00:00
|
|
|
"v8::BooleanObject::Cast()",
|
|
|
|
"Could not convert to BooleanObject");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-04 15:04:16 +00:00
|
|
|
void v8::RegExp::CheckCast(v8::Value* that) {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::RegExp::Cast()")) return;
|
2010-10-04 15:04:16 +00:00
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
|
|
|
ApiCheck(obj->IsJSRegExp(),
|
|
|
|
"v8::RegExp::Cast()",
|
|
|
|
"Could not convert to regular expression");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Value::NumberValue()")) {
|
|
|
|
return i::OS::nan_value();
|
|
|
|
}
|
|
|
|
LOG_API(isolate, "NumberValue");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2013-09-03 06:59:01 +00:00
|
|
|
num = i::Execution::ToNumber(isolate, obj, &has_pending_exception);
|
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 {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Value::IntegerValue()")) return 0;
|
|
|
|
LOG_API(isolate, "IntegerValue");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2013-09-03 06:59:01 +00:00
|
|
|
num = i::Execution::ToInteger(isolate, obj, &has_pending_exception);
|
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 {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Value::ToInt32()")) return Local<Int32>();
|
|
|
|
LOG_API(isolate, "ToInt32");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2013-09-03 06:59:01 +00:00
|
|
|
num = i::Execution::ToInt32(isolate, obj, &has_pending_exception);
|
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 {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Value::ToUint32()")) return Local<Uint32>();
|
|
|
|
LOG_API(isolate, "ToUInt32");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2013-09-03 06:59:01 +00:00
|
|
|
num = i::Execution::ToUint32(isolate, obj, &has_pending_exception);
|
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>();
|
|
|
|
}
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Value::ToArrayIndex()")) return Local<Uint32>();
|
|
|
|
LOG_API(isolate, "ToArrayIndex");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> string_obj =
|
2013-09-03 06:59:01 +00:00
|
|
|
i::Execution::ToString(isolate, obj, &has_pending_exception);
|
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 {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Value::Int32Value()")) return 0;
|
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);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> num =
|
2013-09-03 06:59:01 +00:00
|
|
|
i::Execution::ToInt32(isolate, obj, &has_pending_exception);
|
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();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Value::Equals()")
|
2008-07-03 15:10:15 +00:00
|
|
|
|| EmptyCheck("v8::Value::Equals()", this)
|
2009-04-03 07:49:20 +00:00
|
|
|
|| EmptyCheck("v8::Value::Equals()", that)) {
|
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);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> result =
|
2011-10-06 09:31:38 +00:00
|
|
|
CallV8HeapFunction("EQUALS", obj, ARRAY_SIZE(args), args,
|
|
|
|
&has_pending_exception);
|
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();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Value::StrictEquals()")
|
2008-07-03 15:10:15 +00:00
|
|
|
|| EmptyCheck("v8::Value::StrictEquals()", this)
|
2009-04-03 07:49:20 +00:00
|
|
|
|| EmptyCheck("v8::Value::StrictEquals()", that)) {
|
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() &&
|
|
|
|
i::String::cast(*obj)->Equals(i::String::cast(*other));
|
|
|
|
} else if (obj->IsUndefined() || obj->IsUndetectableObject()) {
|
|
|
|
return other->IsUndefined() || other->IsUndetectableObject();
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Value::Uint32Value()")) return 0;
|
|
|
|
LOG_API(isolate, "Uint32Value");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> num =
|
2013-09-03 06:59:01 +00:00
|
|
|
i::Execution::ToUint32(isolate, obj, &has_pending_exception);
|
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);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj = i::SetProperty(
|
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),
|
|
|
|
i::kNonStrictMode);
|
2009-04-21 13:28:11 +00:00
|
|
|
has_pending_exception = obj.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);
|
2012-01-05 17:16:19 +00:00
|
|
|
i::Handle<i::Object> obj = i::JSObject::SetElement(
|
2010-03-02 18:47:03 +00:00
|
|
|
self,
|
|
|
|
index,
|
2011-03-04 00:21:52 +00:00
|
|
|
value_obj,
|
2012-02-23 11:43:07 +00:00
|
|
|
NONE,
|
2011-03-04 00:21:52 +00:00
|
|
|
i::kNonStrictMode);
|
2010-03-02 18:47:03 +00:00
|
|
|
has_pending_exception = obj.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);
|
2009-04-21 13:28:11 +00:00
|
|
|
i::Handle<i::Object> obj = i::ForceSetProperty(
|
|
|
|
self,
|
|
|
|
key_obj,
|
2008-07-03 15:10:15 +00:00
|
|
|
value_obj,
|
|
|
|
static_cast<PropertyAttributes>(attribs));
|
|
|
|
has_pending_exception = obj.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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
2009-06-08 09:46:09 +00:00
|
|
|
i::Handle<i::Object> obj = i::ForceDeleteProperty(self, key_obj);
|
|
|
|
has_pending_exception = obj.is_null();
|
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);
|
2013-02-25 14:46:09 +00:00
|
|
|
i::Handle<i::Object> result = i::GetProperty(isolate, self, key_obj);
|
2008-07-03 15:10:15 +00:00
|
|
|
has_pending_exception = result.is_null();
|
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);
|
2011-10-19 12:04:16 +00:00
|
|
|
i::Handle<i::Object> result = i::Object::GetElement(self, index);
|
2010-03-02 18:47:03 +00:00
|
|
|
has_pending_exception = result.is_null();
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
2013-09-03 06:59:01 +00:00
|
|
|
key_obj = i::Execution::ToString(isolate, key_obj, &has_pending_exception);
|
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);
|
|
|
|
PropertyAttributes result = self->GetPropertyAttribute(*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();
|
|
|
|
ON_BAILOUT(isolate, "v8::Object::GetPrototype()",
|
2011-03-18 20:35:07 +00:00
|
|
|
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);
|
2013-07-02 15:32:46 +00:00
|
|
|
i::Handle<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);
|
|
|
|
while (!object->IsInstanceOf(tmpl_info)) {
|
|
|
|
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);
|
2011-10-24 15:56:18 +00:00
|
|
|
bool threw = false;
|
2009-09-15 11:51:40 +00:00
|
|
|
i::Handle<i::FixedArray> value =
|
2011-10-24 15:56:18 +00:00
|
|
|
i::GetKeysInFixedArrayFor(self, i::INCLUDE_PROTOS, &threw);
|
|
|
|
if (threw) return 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);
|
2011-10-24 15:56:18 +00:00
|
|
|
bool threw = false;
|
2011-06-10 12:33:55 +00:00
|
|
|
i::Handle<i::FixedArray> value =
|
2011-10-24 15:56:18 +00:00
|
|
|
i::GetKeysInFixedArrayFor(self, i::LOCAL_ONLY, &threw);
|
|
|
|
if (threw) return 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() {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
ON_BAILOUT(isolate, "v8::Object::ObjectProtoToString()",
|
2011-03-18 20:35:07 +00:00
|
|
|
return Local<v8::String>());
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
|
|
|
|
2013-02-25 14:46:09 +00:00
|
|
|
i::Handle<i::Object> name(self->class_name(), 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()) {
|
|
|
|
return v8::String::New("[object ]");
|
|
|
|
|
|
|
|
} 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"))) {
|
2008-07-03 15:10:15 +00:00
|
|
|
return v8::String::New("[object Object]");
|
|
|
|
|
|
|
|
} 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();
|
2013-04-16 12:30:51 +00:00
|
|
|
i::OS::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.
|
2013-04-16 12:30:51 +00:00
|
|
|
i::OS::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.
|
2010-05-05 12:25:58 +00:00
|
|
|
Local<String> result = v8::String::New(buf.start(), 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);
|
|
|
|
i::Handle<i::Object> obj = i::DeleteProperty(self, key_obj);
|
|
|
|
has_pending_exception = obj.is_null();
|
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, false);
|
|
|
|
return obj->IsTrue();
|
2008-07-03 15:10:15 +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);
|
|
|
|
i::Handle<i::Object> obj = i::HasProperty(self, key_obj);
|
|
|
|
has_pending_exception = obj.is_null();
|
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, false);
|
|
|
|
return obj->IsTrue();
|
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);
|
2013-08-29 18:01:45 +00:00
|
|
|
return i::JSReceiver::DeleteElement(self, index)->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);
|
|
|
|
return self->HasElement(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
2013-08-30 14:08:15 +00:00
|
|
|
i::Handle<i::Object> result =
|
|
|
|
i::JSObject::SetAccessor(Utils::OpenHandle(obj), info);
|
2013-03-07 11:42:58 +00:00
|
|
|
if (result.is_null() || result->IsUndefined()) return false;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Object::SetAccessor(Handle<String> name,
|
|
|
|
Handle<DeclaredAccessorDescriptor> descriptor,
|
|
|
|
AccessControl settings,
|
|
|
|
PropertyAttribute attributes) {
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
return Utils::OpenHandle(this)->HasLocalProperty(
|
|
|
|
*Utils::OpenHandle(*key));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::OpenHandle(this)->HasRealNamedProperty(
|
2013-04-04 19:12:59 +00:00
|
|
|
isolate,
|
2008-07-03 15:10:15 +00:00
|
|
|
*Utils::OpenHandle(*key));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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-04-04 19:12:59 +00:00
|
|
|
return Utils::OpenHandle(this)->HasRealElementProperty(isolate, 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);
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::OpenHandle(this)->HasRealNamedCallbackProperty(
|
2013-04-04 19:12:59 +00:00
|
|
|
isolate,
|
2008-07-03 15:10:15 +00:00
|
|
|
*Utils::OpenHandle(*key));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
i::Handle<i::Object> result =
|
|
|
|
i::Object::GetProperty(receiver, receiver, lookup, name,
|
|
|
|
&ignored);
|
2011-04-07 19:52:24 +00:00
|
|
|
has_pending_exception = result.is_null();
|
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>());
|
|
|
|
|
|
|
|
return Utils::ToLocal(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-28 14:32:48 +00:00
|
|
|
Local<Value> v8::Object::GetRealNamedPropertyInPrototypeChain(
|
2008-07-03 15:10:15 +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);
|
2008-07-03 15:10:15 +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);
|
2009-09-25 12:29:24 +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);
|
|
|
|
|
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::Map> new_map =
|
2012-07-17 13:50:19 +00:00
|
|
|
isolate->factory()->CopyMap(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);
|
2009-03-18 19:24:15 +00:00
|
|
|
i::Handle<i::JSObject> result = i::Copy(self);
|
|
|
|
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
|
|
|
static i::Context* GetCreationContext(i::JSObject* object) {
|
|
|
|
i::Object* constructor = object->map()->constructor();
|
|
|
|
i::JSFunction* function;
|
|
|
|
if (!constructor->IsJSFunction()) {
|
2011-08-11 06:40:14 +00:00
|
|
|
// Functions have null as a constructor,
|
2011-04-01 12:17:20 +00:00
|
|
|
// but any JSFunction knows its context immediately.
|
2011-08-11 06:40:14 +00:00
|
|
|
ASSERT(object->IsJSFunction());
|
2011-04-01 12:17:20 +00:00
|
|
|
function = i::JSFunction::cast(object);
|
|
|
|
} else {
|
|
|
|
function = i::JSFunction::cast(constructor);
|
|
|
|
}
|
2012-08-17 09:03:08 +00:00
|
|
|
return function->context()->native_context();
|
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);
|
|
|
|
i::Context* context = GetCreationContext(*self);
|
|
|
|
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);
|
2012-01-05 17:16:19 +00:00
|
|
|
return i::JSObject::GetIdentityHash(self);
|
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);
|
2013-02-28 17:03:34 +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) {
|
|
|
|
case kExternalByteArray:
|
|
|
|
return i::EXTERNAL_BYTE_ELEMENTS;
|
|
|
|
break;
|
|
|
|
case kExternalUnsignedByteArray:
|
|
|
|
return i::EXTERNAL_UNSIGNED_BYTE_ELEMENTS;
|
|
|
|
break;
|
|
|
|
case kExternalShortArray:
|
|
|
|
return i::EXTERNAL_SHORT_ELEMENTS;
|
|
|
|
break;
|
|
|
|
case kExternalUnsignedShortArray:
|
|
|
|
return i::EXTERNAL_UNSIGNED_SHORT_ELEMENTS;
|
|
|
|
break;
|
|
|
|
case kExternalIntArray:
|
|
|
|
return i::EXTERNAL_INT_ELEMENTS;
|
|
|
|
break;
|
|
|
|
case kExternalUnsignedIntArray:
|
|
|
|
return i::EXTERNAL_UNSIGNED_INT_ELEMENTS;
|
|
|
|
break;
|
|
|
|
case kExternalFloatArray:
|
|
|
|
return i::EXTERNAL_FLOAT_ELEMENTS;
|
|
|
|
break;
|
|
|
|
case kExternalDoubleArray:
|
|
|
|
return i::EXTERNAL_DOUBLE_ELEMENTS;
|
|
|
|
break;
|
|
|
|
case kExternalPixelArray:
|
|
|
|
return i::EXTERNAL_PIXEL_ELEMENTS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
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 =
|
|
|
|
isolate->factory()->GetElementsTransitionMap(
|
|
|
|
object,
|
|
|
|
GetElementsKindFromExternalArrayType(array_type));
|
|
|
|
|
|
|
|
object->set_map(*external_array_map);
|
2011-03-09 15:01:16 +00:00
|
|
|
object->set_elements(*array);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // 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);
|
2012-09-13 09:36:56 +00:00
|
|
|
if (!ApiCheck(length >= 0 && length <= i::ExternalPixelArray::kMaxLength,
|
2009-07-28 08:43:51 +00:00
|
|
|
"v8::Object::SetIndexedPropertiesToPixelData()",
|
|
|
|
"length exceeds max acceptable value")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
|
|
|
if (!ApiCheck(!self->IsJSArray(),
|
|
|
|
"v8::Object::SetIndexedPropertiesToPixelData()",
|
|
|
|
"JSArray is not supported")) {
|
|
|
|
return;
|
|
|
|
}
|
2011-03-09 15:01:16 +00:00
|
|
|
PrepareExternalArrayElements(self, data, kExternalPixelArray, 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);
|
2011-03-09 15:01:16 +00:00
|
|
|
return self->HasExternalPixelElements();
|
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);
|
2011-03-09 15:01:16 +00:00
|
|
|
if (self->HasExternalPixelElements()) {
|
|
|
|
return i::ExternalPixelArray::cast(self->elements())->
|
|
|
|
external_pixel_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);
|
2011-03-09 15:01:16 +00:00
|
|
|
if (self->HasExternalPixelElements()) {
|
|
|
|
return i::ExternalPixelArray::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);
|
2012-09-13 09:36:56 +00:00
|
|
|
if (!ApiCheck(length >= 0 && length <= i::ExternalArray::kMaxLength,
|
2009-10-20 15:26:17 +00:00
|
|
|
"v8::Object::SetIndexedPropertiesToExternalArrayData()",
|
|
|
|
"length exceeds max acceptable value")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
|
|
|
|
if (!ApiCheck(!self->IsJSArray(),
|
|
|
|
"v8::Object::SetIndexedPropertiesToExternalArrayData()",
|
|
|
|
"JSArray is not supported")) {
|
|
|
|
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()) {
|
|
|
|
case i::EXTERNAL_BYTE_ARRAY_TYPE:
|
|
|
|
return kExternalByteArray;
|
|
|
|
case i::EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE:
|
|
|
|
return kExternalUnsignedByteArray;
|
|
|
|
case i::EXTERNAL_SHORT_ARRAY_TYPE:
|
|
|
|
return kExternalShortArray;
|
|
|
|
case i::EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE:
|
|
|
|
return kExternalUnsignedShortArray;
|
|
|
|
case i::EXTERNAL_INT_ARRAY_TYPE:
|
|
|
|
return kExternalIntArray;
|
|
|
|
case i::EXTERNAL_UNSIGNED_INT_ARRAY_TYPE:
|
|
|
|
return kExternalUnsignedIntArray;
|
|
|
|
case i::EXTERNAL_FLOAT_ARRAY_TYPE:
|
|
|
|
return kExternalFloatArray;
|
2011-04-21 07:15:43 +00:00
|
|
|
case i::EXTERNAL_DOUBLE_ARRAY_TYPE:
|
|
|
|
return kExternalDoubleArray;
|
2011-03-09 15:01:16 +00:00
|
|
|
case i::EXTERNAL_PIXEL_ARRAY_TYPE:
|
|
|
|
return kExternalPixelArray;
|
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);
|
|
|
|
if (obj->IsJSFunction()) return true;
|
2013-09-03 06:59:01 +00:00
|
|
|
return i::Execution::GetFunctionDelegate(isolate, obj)->IsJSFunction();
|
2011-05-09 15:24:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-06 09:31:38 +00:00
|
|
|
Local<v8::Value> Object::CallAsFunction(v8::Handle<v8::Object> recv,
|
|
|
|
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);
|
2013-09-03 06:59:01 +00:00
|
|
|
i::Handle<i::Object> delegate = i::Execution::TryGetFunctionDelegate(
|
|
|
|
isolate, obj, &has_pending_exception);
|
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);
|
|
|
|
i::Handle<i::Object> returned =
|
|
|
|
i::Execution::Call(fun, recv_obj, argc, args, &has_pending_exception);
|
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);
|
|
|
|
i::Handle<i::Object> returned =
|
|
|
|
i::Execution::New(fun, argc, args, &has_pending_exception);
|
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);
|
2013-09-03 06:59:01 +00:00
|
|
|
i::Handle<i::Object> delegate = i::Execution::TryGetConstructorDelegate(
|
|
|
|
isolate, obj, &has_pending_exception);
|
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);
|
|
|
|
i::Handle<i::Object> returned =
|
|
|
|
i::Execution::Call(fun, obj, argc, args, &has_pending_exception);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
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-03-15 12:06:53 +00:00
|
|
|
HandleScope 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);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> returned =
|
|
|
|
i::Execution::New(function, argc, args, &has_pending_exception);
|
2012-01-04 08:48:35 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<v8::Object>());
|
2008-07-03 15:10:15 +00:00
|
|
|
return scope.Close(Utils::ToLocal(i::Handle<i::JSObject>::cast(returned)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<v8::Value> Function::Call(v8::Handle<v8::Object> recv, int argc,
|
|
|
|
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);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Object* raw_result = NULL;
|
|
|
|
{
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
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**));
|
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);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> returned =
|
|
|
|
i::Execution::Call(fun, recv_obj, argc, args, &has_pending_exception);
|
2012-01-04 08:48:35 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Object>());
|
2008-07-03 15:10:15 +00:00
|
|
|
raw_result = *returned;
|
|
|
|
}
|
2013-02-25 14:46:09 +00:00
|
|
|
i::Handle<i::Object> result(raw_result, isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::ToLocal(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
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()));
|
2012-11-12 12:34:18 +00:00
|
|
|
i::Handle<i::Object> scriptName = GetScriptNameOrSourceURL(script);
|
2010-02-15 14:19:15 +00:00
|
|
|
v8::ScriptOrigin origin(
|
2012-11-12 12:34:18 +00:00
|
|
|
Utils::ToLocal(scriptName),
|
2010-02-15 14:19:15 +00:00
|
|
|
v8::Integer::New(script->line_offset()->value()),
|
|
|
|
v8::Integer::New(script->column_offset()->value()));
|
|
|
|
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()));
|
|
|
|
return i::GetScriptLineNumber(script, func->shared()->start_position());
|
|
|
|
}
|
|
|
|
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()));
|
|
|
|
return i::GetScriptColumnNumber(script, func->shared()->start_position());
|
|
|
|
}
|
|
|
|
return kLineOffsetNotFound;
|
|
|
|
}
|
|
|
|
|
2013-06-25 14:57:47 +00:00
|
|
|
|
2011-11-09 14:18:30 +00:00
|
|
|
Handle<Value> Function::GetScriptId() const {
|
|
|
|
i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
|
|
|
|
if (!func->shared()->script()->IsScript())
|
|
|
|
return v8::Undefined();
|
|
|
|
i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
|
2013-02-25 14:46:09 +00:00
|
|
|
return Utils::ToLocal(i::Handle<i::Object>(script->id(), func->GetIsolate()));
|
2011-11-09 14:18:30 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 14:57:47 +00:00
|
|
|
|
|
|
|
int Function::ScriptId() const {
|
|
|
|
i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
|
|
|
|
if (!func->shared()->script()->IsScript()) return v8::Script::kNoScriptId;
|
|
|
|
i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
|
|
|
|
return script->id()->value();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
if (IsDeadCheck(str->GetIsolate(), "v8::String::Length()")) return 0;
|
|
|
|
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);
|
|
|
|
if (IsDeadCheck(str->GetIsolate(), "v8::String::IsOneByte()")) {
|
|
|
|
return false;
|
|
|
|
}
|
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*>(
|
|
|
|
reinterpret_cast<uintptr_t>(chars) & ~kAlignmentMask);
|
|
|
|
}
|
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) {
|
|
|
|
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 (IsDeadCheck(str->GetIsolate(),
|
|
|
|
"v8::String::ContainsOnlyOneByte()")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
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()
|
2013-03-06 15:39:57 +00:00
|
|
|
: utf8_length_(0),
|
|
|
|
state_(kInitialState) {}
|
|
|
|
|
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
|
|
|
|
| (edge_surrogate ? kRightmostEdgeIsSurrogate : 0));
|
|
|
|
} 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();
|
|
|
|
if (IsDeadCheck(isolate, "v8::String::Utf8Length()")) return 0;
|
|
|
|
return v8::Utf8Length(*str, isolate);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class Utf8WriterVisitor {
|
|
|
|
public:
|
2013-03-06 15:39:57 +00:00
|
|
|
Utf8WriterVisitor(
|
|
|
|
char* buffer, int capacity, bool skip_capacity_check)
|
2013-01-03 12:59:54 +00:00
|
|
|
: early_termination_(false),
|
|
|
|
last_character_(unibrow::Utf16::kNoPreviousCharacter),
|
|
|
|
buffer_(buffer),
|
|
|
|
start_(buffer),
|
|
|
|
capacity_(capacity),
|
2013-03-06 15:39:57 +00:00
|
|
|
skip_capacity_check_(capacity == -1 || skip_capacity_check),
|
2013-01-03 12:59:54 +00:00
|
|
|
utf16_chars_read_(0) {
|
|
|
|
}
|
|
|
|
|
|
|
|
static int WriteEndCharacter(uint16_t character,
|
|
|
|
int last_character,
|
|
|
|
int remaining,
|
|
|
|
char* const buffer) {
|
|
|
|
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.
|
|
|
|
if (Utf16::IsTrailSurrogate(character) &&
|
|
|
|
Utf16::IsLeadSurrogate(last_character)) {
|
|
|
|
int written = Utf8::Encode(buffer, character, last_character);
|
|
|
|
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,
|
2013-03-06 15:39:57 +00:00
|
|
|
Utf16::kNoPreviousCharacter);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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++;
|
|
|
|
buffer += Utf8::Encode(buffer, character, last_character);
|
|
|
|
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++;
|
|
|
|
int written = WriteEndCharacter(character,
|
|
|
|
last_character,
|
|
|
|
remaining_capacity,
|
|
|
|
buffer);
|
|
|
|
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_;
|
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,
|
|
|
|
Utf8WriterVisitor* writer,
|
|
|
|
int recursion_budget) {
|
|
|
|
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
|
|
|
if (IsDeadCheck(isolate, "v8::String::WriteUtf8()")) return 0;
|
|
|
|
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) {
|
|
|
|
FlattenString(str); // Flatten the string for efficiency.
|
|
|
|
}
|
2013-03-06 15:39:57 +00:00
|
|
|
const int string_length = str->length();
|
|
|
|
bool write_null = !(options & NO_NULL_TERMINATION);
|
|
|
|
// First check if we can just write the string without checking capacity.
|
|
|
|
if (capacity == -1 || capacity / 3 >= string_length) {
|
|
|
|
Utf8WriterVisitor writer(buffer, capacity, true);
|
|
|
|
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.
|
|
|
|
str = FlattenGetString(str);
|
|
|
|
Utf8WriterVisitor writer(buffer, capacity, false);
|
|
|
|
i::String::VisitFlat(&writer, *str);
|
|
|
|
return writer.CompleteWrite(write_null, nchars_ref);
|
2008-09-05 13:39:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-13 17:00:33 +00:00
|
|
|
int String::WriteAscii(char* buffer,
|
|
|
|
int start,
|
|
|
|
int length,
|
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
|
|
|
if (IsDeadCheck(isolate, "v8::String::WriteAscii()")) return 0;
|
|
|
|
LOG_API(isolate, "String::WriteAscii");
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2012-09-04 12:23:22 +00:00
|
|
|
ASSERT(start >= 0 && length >= -1);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::String> str = Utils::OpenHandle(this);
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->string_tracker()->RecordWrite(str);
|
2011-08-23 11:11:12 +00:00
|
|
|
if (options & HINT_MANY_WRITES_EXPECTED) {
|
2012-07-23 14:22:46 +00:00
|
|
|
FlattenString(str); // Flatten the string for efficiency.
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
int end = length;
|
2012-09-04 12:23:22 +00:00
|
|
|
if ((length == -1) || (length > str->length() - start)) {
|
2008-07-03 15:10:15 +00:00
|
|
|
end = str->length() - start;
|
2012-07-23 14:22:46 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
if (end < 0) return 0;
|
2012-12-31 11:13:50 +00:00
|
|
|
i::StringCharacterStream write_stream(*str, isolate->write_iterator(), start);
|
2008-07-03 15:10:15 +00:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < end; i++) {
|
2012-12-31 11:13:50 +00:00
|
|
|
char c = static_cast<char>(write_stream.GetNext());
|
2012-07-23 14:22:46 +00:00
|
|
|
if (c == '\0' && !(options & PRESERVE_ASCII_NULL)) c = ' ';
|
2008-07-03 15:10:15 +00:00
|
|
|
buffer[i] = c;
|
|
|
|
}
|
2012-07-23 14:22:46 +00:00
|
|
|
if (!(options & NO_NULL_TERMINATION) && (length == -1 || i < length)) {
|
2008-07-03 15:10:15 +00:00
|
|
|
buffer[i] = '\0';
|
2012-07-23 14:22:46 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
if (IsDeadCheck(isolate, "v8::String::Write()")) return 0;
|
|
|
|
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.
|
|
|
|
FlattenString(str);
|
|
|
|
}
|
|
|
|
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
|
|
|
if (IsDeadCheck(str->GetIsolate(), "v8::String::IsExternal()")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
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);
|
2011-03-24 18:49:45 +00:00
|
|
|
if (IsDeadCheck(str->GetIsolate(), "v8::String::IsExternalAscii()")) {
|
|
|
|
return false;
|
|
|
|
}
|
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
|
2012-09-12 11:29:50 +00:00
|
|
|
: TWO_BYTE_ENCODING;
|
|
|
|
}
|
|
|
|
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*
|
2009-01-08 11:35:34 +00:00
|
|
|
v8::String::GetExternalAsciiStringResource() 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
|
|
|
if (IsDeadCheck(str->GetIsolate(),
|
|
|
|
"v8::String::GetExternalAsciiStringResource()")) {
|
|
|
|
return NULL;
|
|
|
|
}
|
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 {
|
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Symbol::Name()"))
|
|
|
|
return Local<Value>();
|
|
|
|
i::Handle<i::Symbol> sym = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::Object> name(sym->name(), sym->GetIsolate());
|
|
|
|
return Utils::ToLocal(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 11:35:34 +00:00
|
|
|
double Number::Value() const {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Number::Value()")) return 0;
|
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 {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Boolean::Value()")) return false;
|
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 {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Integer::Value()")) return 0;
|
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 {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Int32::Value()")) return 0;
|
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 {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::Uint32::Value()")) return 0;
|
2010-03-03 13:44:20 +00:00
|
|
|
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);
|
|
|
|
if (IsDeadCheck(obj->GetIsolate(), "v8::Object::InternalFieldCount()")) {
|
2011-03-18 20:35:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
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) {
|
|
|
|
return !IsDeadCheck(obj->GetIsolate(), location) &&
|
|
|
|
ApiCheck(index < obj->GetInternalFieldCount(),
|
|
|
|
location,
|
|
|
|
"Internal field out of bounds");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-17 09:16:28 +00:00
|
|
|
void v8::V8::SetEntropySource(EntropySource source) {
|
|
|
|
i::V8::SetEntropySource(source);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-27 15:15:53 +00:00
|
|
|
void v8::V8::SetReturnAddressLocationResolver(
|
|
|
|
ReturnAddressLocationResolver return_address_resolver) {
|
|
|
|
i::V8::SetReturnAddressLocationResolver(return_address_resolver);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-17 15:18:15 +00:00
|
|
|
bool v8::V8::SetFunctionEntryHook(FunctionEntryHook entry_hook) {
|
2013-06-28 13:40:41 +00:00
|
|
|
return SetFunctionEntryHook(Isolate::GetCurrent(), entry_hook);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
if (!ApiCheck(i::V8::ArrayBufferAllocator() == NULL,
|
|
|
|
"v8::V8::SetArrayBufferAllocator",
|
|
|
|
"ArrayBufferAllocator might only be set once"))
|
|
|
|
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() {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (!ApiCheck(isolate != NULL && isolate->IsDefaultIsolate(),
|
|
|
|
"v8::V8::Dispose()",
|
|
|
|
"Use v8::Isolate::Dispose() for a non-default isolate.")) {
|
|
|
|
return false;
|
|
|
|
}
|
2009-03-27 00:24:49 +00:00
|
|
|
i::V8::TearDown();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
void v8::V8::GetHeapStatistics(HeapStatistics* heap_statistics) {
|
2013-02-08 12:41:55 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::UncheckedCurrent();
|
|
|
|
if (isolate == NULL || !isolate->IsInitialized()) {
|
2011-10-13 16:11:18 +00:00
|
|
|
// Isolate is unitialized thus heap is not configured yet.
|
2013-02-08 12:41:55 +00:00
|
|
|
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;
|
2011-10-13 16:11:18 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-02-08 12:41:55 +00:00
|
|
|
Isolate* ext_isolate = reinterpret_cast<Isolate*>(isolate);
|
|
|
|
return ext_isolate->GetHeapStatistics(heap_statistics);
|
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();
|
|
|
|
IsDeadCheck(isolate, "v8::V8::VisitExternalResources");
|
|
|
|
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();
|
|
|
|
IsDeadCheck(isolate, "v8::V8::VisitHandlesWithClassId");
|
|
|
|
|
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());
|
|
|
|
IsDeadCheck(isolate, "v8::V8::VisitHandlesForPartialDependence");
|
|
|
|
|
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;
|
2011-11-30 11:13:36 +00:00
|
|
|
return i::V8::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
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-11 09:58:54 +00:00
|
|
|
bool v8::V8::InitializeICU() {
|
|
|
|
return i::InitializeICU();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
static i::Handle<i::FunctionTemplateInfo>
|
|
|
|
EnsureConstructor(i::Handle<i::ObjectTemplateInfo> templ) {
|
|
|
|
if (templ->constructor()->IsUndefined()) {
|
|
|
|
Local<FunctionTemplate> constructor = FunctionTemplate::New();
|
|
|
|
Utils::OpenHandle(*constructor)->set_instance_template(*templ);
|
|
|
|
templ->set_constructor(*Utils::OpenHandle(*constructor));
|
|
|
|
}
|
|
|
|
return i::Handle<i::FunctionTemplateInfo>(
|
|
|
|
i::FunctionTemplateInfo::cast(templ->constructor()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
global_constructor =
|
|
|
|
EnsureConstructor(Utils::OpenHandle(*global_template));
|
|
|
|
|
|
|
|
// Create a fresh template for the global proxy object.
|
|
|
|
proxy_template = ObjectTemplate::New();
|
|
|
|
proxy_constructor =
|
|
|
|
EnsureConstructor(Utils::OpenHandle(*proxy_template));
|
|
|
|
|
|
|
|
// 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());
|
|
|
|
}
|
2011-03-23 14:07:52 +00:00
|
|
|
isolate->runtime_profiler()->Reset();
|
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;
|
|
|
|
}
|
|
|
|
|
2013-06-13 09:27:09 +00:00
|
|
|
#ifdef V8_USE_UNSAFE_HANDLES
|
2013-04-10 09:34:37 +00:00
|
|
|
Persistent<Context> v8::Context::New(
|
|
|
|
v8::ExtensionConfiguration* extensions,
|
|
|
|
v8::Handle<ObjectTemplate> global_template,
|
|
|
|
v8::Handle<Value> global_object) {
|
|
|
|
i::Isolate::EnsureDefaultIsolate();
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
Isolate* external_isolate = reinterpret_cast<Isolate*>(isolate);
|
|
|
|
EnsureInitializedForIsolate(isolate, "v8::Context::New()");
|
|
|
|
LOG_API(isolate, "Context::New");
|
|
|
|
ON_BAILOUT(isolate, "v8::Context::New()", return Persistent<Context>());
|
|
|
|
i::HandleScope scope(isolate);
|
|
|
|
i::Handle<i::Context> env =
|
|
|
|
CreateEnvironment(isolate, extensions, global_template, global_object);
|
|
|
|
if (env.is_null()) return Persistent<Context>();
|
|
|
|
return Persistent<Context>::New(external_isolate, Utils::ToLocal(env));
|
|
|
|
}
|
2013-06-13 09:27:09 +00:00
|
|
|
#endif
|
2013-04-10 09:34:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
Local<Context> v8::Context::New(
|
|
|
|
v8::Isolate* external_isolate,
|
|
|
|
v8::ExtensionConfiguration* extensions,
|
|
|
|
v8::Handle<ObjectTemplate> global_template,
|
|
|
|
v8::Handle<Value> global_object) {
|
|
|
|
i::Isolate::EnsureDefaultIsolate();
|
|
|
|
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);
|
|
|
|
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();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Context::SetSecurityToken()")) {
|
2011-03-18 20:35:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-03-24 18:49:45 +00:00
|
|
|
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();
|
|
|
|
if (IsDeadCheck(isolate,
|
2011-03-18 20:35:07 +00:00
|
|
|
"v8::Context::UseDefaultSecurityToken()")) {
|
|
|
|
return;
|
|
|
|
}
|
2011-03-24 18:49:45 +00:00
|
|
|
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();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Context::GetSecurityToken()")) {
|
2011-03-18 20:35:07 +00:00
|
|
|
return Handle<Value>();
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Context::HasOutOfMemoryException() {
|
|
|
|
i::Handle<i::Context> env = Utils::OpenHandle(this);
|
|
|
|
return env->has_out_of_memory();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Context::InContext() {
|
2011-03-18 20:35:07 +00:00
|
|
|
return i::Isolate::Current()->context() != NULL;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-25 07:37:58 +00:00
|
|
|
v8::Local<v8::Context> Context::GetEntered() {
|
2011-03-23 14:07:52 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2011-08-22 13:04:14 +00:00
|
|
|
if (!EnsureInitializedForIsolate(isolate, "v8::Context::GetEntered()")) {
|
2011-03-18 20:35:07 +00:00
|
|
|
return Local<Context>();
|
|
|
|
}
|
|
|
|
i::Handle<i::Object> last =
|
2011-03-23 14:07:52 +00:00
|
|
|
isolate->handle_scope_implementer()->LastEnteredContext();
|
2008-07-25 07:37:58 +00:00
|
|
|
if (last.is_null()) return Local<Context>();
|
|
|
|
i::Handle<i::Context> context = i::Handle<i::Context>::cast(last);
|
|
|
|
return Utils::ToLocal(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
v8::Local<v8::Context> Context::GetCurrent() {
|
2011-03-23 14:07:52 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Context::GetCurrent()")) {
|
2011-03-18 20:35:07 +00:00
|
|
|
return Local<Context>();
|
|
|
|
}
|
2013-04-09 07:34:32 +00:00
|
|
|
return reinterpret_cast<Isolate*>(isolate)->GetCurrentContext();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-20 07:44:59 +00:00
|
|
|
v8::Local<v8::Context> Context::GetCalling() {
|
2011-03-23 14:07:52 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Context::GetCalling()")) {
|
2011-03-18 20:35:07 +00:00
|
|
|
return Local<Context>();
|
|
|
|
}
|
|
|
|
i::Handle<i::Object> calling =
|
2012-08-17 09:03:08 +00:00
|
|
|
isolate->GetCallingNativeContext();
|
2009-09-28 10:21:08 +00:00
|
|
|
if (calling.is_null()) return Local<Context>();
|
|
|
|
i::Handle<i::Context> context = i::Handle<i::Context>::cast(calling);
|
2009-05-20 07:44:59 +00:00
|
|
|
return Utils::ToLocal(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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() {
|
2012-11-16 08:38:11 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Context::Global()")) {
|
2011-03-18 20:35:07 +00:00
|
|
|
return Local<v8::Object>();
|
|
|
|
}
|
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** ctx = reinterpret_cast<i::Object**>(this);
|
|
|
|
i::Handle<i::Context> context =
|
|
|
|
i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx));
|
2012-11-16 08:38:11 +00:00
|
|
|
i::Handle<i::Object> global(context->global_proxy(), 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
|
|
|
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() {
|
2011-03-23 14:07:52 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Context::DetachGlobal()")) return;
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Object** ctx = reinterpret_cast<i::Object**>(this);
|
|
|
|
i::Handle<i::Context> context =
|
|
|
|
i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx));
|
2011-03-23 14:07:52 +00:00
|
|
|
isolate->bootstrapper()->DetachGlobal(context);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-24 13:24:46 +00:00
|
|
|
void Context::ReattachGlobal(Handle<Object> global_object) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Context::ReattachGlobal()")) return;
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2010-03-24 13:24:46 +00:00
|
|
|
i::Object** ctx = reinterpret_cast<i::Object**>(this);
|
|
|
|
i::Handle<i::Context> context =
|
|
|
|
i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx));
|
2012-08-28 11:25:08 +00:00
|
|
|
i::Handle<i::JSGlobalProxy> global_proxy =
|
|
|
|
i::Handle<i::JSGlobalProxy>::cast(Utils::OpenHandle(*global_object));
|
|
|
|
isolate->bootstrapper()->ReattachGlobal(context, global_proxy);
|
2010-03-24 13:24:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-03 05:40:47 +00:00
|
|
|
void Context::AllowCodeGenerationFromStrings(bool allow) {
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Context::AllowCodeGenerationFromStrings()")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
i::Object** ctx = reinterpret_cast<i::Object**>(this);
|
|
|
|
i::Handle<i::Context> context =
|
|
|
|
i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx));
|
|
|
|
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() {
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate,
|
|
|
|
"v8::Context::IsCodeGenerationFromStringsAllowed()")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
i::Object** ctx = reinterpret_cast<i::Object**>(this);
|
|
|
|
i::Handle<i::Context> context =
|
|
|
|
i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx));
|
|
|
|
return !context->allow_code_gen_from_strings()->IsFalse();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-17 09:58:22 +00:00
|
|
|
void Context::SetErrorMessageForCodeGenerationFromStrings(
|
|
|
|
Handle<String> error) {
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate,
|
|
|
|
"v8::Context::SetErrorMessageForCodeGenerationFromStrings()")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
i::Object** ctx = reinterpret_cast<i::Object**>(this);
|
|
|
|
i::Handle<i::Context> context =
|
|
|
|
i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx));
|
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);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj =
|
|
|
|
i::Execution::InstantiateObject(Utils::OpenHandle(this),
|
|
|
|
&has_pending_exception);
|
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);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj =
|
|
|
|
i::Execution::InstantiateFunction(Utils::OpenHandle(this),
|
|
|
|
&has_pending_exception);
|
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);
|
|
|
|
return obj->IsInstanceOf(*Utils::OpenHandle(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-13 12:27:03 +00:00
|
|
|
Local<External> v8::External::New(void* value) {
|
|
|
|
STATIC_ASSERT(sizeof(value) == sizeof(i::Address));
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
EnsureInitializedForIsolate(isolate, "v8::External::New()");
|
2011-08-04 15:18:18 +00:00
|
|
|
LOG_API(isolate, "External::New");
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2012-11-13 12:27:03 +00:00
|
|
|
i::Handle<i::JSObject> external = isolate->factory()->NewExternal(value);
|
|
|
|
return Utils::ExternalToLocal(external);
|
2009-03-23 19:51:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void* External::Value() const {
|
2012-11-13 12:27:03 +00:00
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::External::Value()")) return NULL;
|
|
|
|
return ExternalValue(*Utils::OpenHandle(this));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-19 23:35:09 +00:00
|
|
|
Local<String> v8::String::Empty() {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2012-04-25 08:45:45 +00:00
|
|
|
if (!EnsureInitializedForIsolate(isolate, "v8::String::Empty()")) {
|
|
|
|
return v8::Local<String>();
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
LOG_API(isolate, "String::Empty()");
|
2013-02-28 17:03:34 +00:00
|
|
|
return Utils::ToLocal(isolate->factory()->empty_string());
|
2009-03-19 23:35:09 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-22 15:20:28 +00:00
|
|
|
inline i::Handle<i::String> NewString(i::Factory* factory,
|
|
|
|
String::NewStringType type,
|
|
|
|
i::Vector<const char> string) {
|
|
|
|
if (type ==String::kInternalizedString) {
|
|
|
|
return factory->InternalizeUtf8String(string);
|
|
|
|
}
|
|
|
|
return factory->NewStringFromUtf8(string);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline i::Handle<i::String> NewString(i::Factory* factory,
|
|
|
|
String::NewStringType type,
|
|
|
|
i::Vector<const uint8_t> string) {
|
|
|
|
if (type == String::kInternalizedString) {
|
|
|
|
return factory->InternalizeOneByteString(string);
|
|
|
|
}
|
|
|
|
return factory->NewStringFromOneByte(string);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline i::Handle<i::String> NewString(i::Factory* factory,
|
|
|
|
String::NewStringType type,
|
|
|
|
i::Vector<const uint16_t> string) {
|
|
|
|
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) {
|
|
|
|
return String::Empty();
|
|
|
|
}
|
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);
|
|
|
|
i::Handle<i::String> result = NewString(
|
|
|
|
isolate->factory(), type, i::Vector<const Char>(data, length));
|
|
|
|
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);
|
|
|
|
i::Handle<i::String> result = isolate->factory()->NewConsString(left_string,
|
|
|
|
right_string);
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::ToLocal(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Handle<i::String> NewExternalStringHandle(i::Isolate* isolate,
|
2008-07-03 15:10:15 +00:00
|
|
|
v8::String::ExternalStringResource* resource) {
|
|
|
|
i::Handle<i::String> result =
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->factory()->NewExternalStringFromTwoByte(resource);
|
2008-07-03 15:10:15 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Handle<i::String> NewExternalAsciiStringHandle(i::Isolate* isolate,
|
2008-07-03 15:10:15 +00:00
|
|
|
v8::String::ExternalAsciiStringResource* resource) {
|
|
|
|
i::Handle<i::String> result =
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->factory()->NewExternalStringFromAscii(resource);
|
2008-07-03 15:10:15 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-26 12:32:06 +00:00
|
|
|
bool RedirectToExternalString(i::Isolate* isolate,
|
|
|
|
i::Handle<i::String> parent,
|
|
|
|
i::Handle<i::String> external) {
|
|
|
|
if (parent->IsConsString()) {
|
|
|
|
i::Handle<i::ConsString> cons = i::Handle<i::ConsString>::cast(parent);
|
|
|
|
cons->set_first(*external);
|
|
|
|
cons->set_second(isolate->heap()->empty_string());
|
|
|
|
} else {
|
|
|
|
ASSERT(parent->IsSlicedString());
|
|
|
|
i::Handle<i::SlicedString> slice = i::Handle<i::SlicedString>::cast(parent);
|
|
|
|
slice->set_parent(*external);
|
|
|
|
slice->set_offset(0);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Local<String> v8::String::NewExternal(
|
|
|
|
v8::String::ExternalStringResource* resource) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()");
|
|
|
|
LOG_API(isolate, "String::NewExternal");
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2012-08-14 12:16:38 +00:00
|
|
|
CHECK(resource && resource->data());
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Handle<i::String> result = NewExternalStringHandle(isolate, resource);
|
|
|
|
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();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false;
|
2012-09-04 12:23:22 +00:00
|
|
|
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
|
|
|
|
|
|
|
bool result;
|
|
|
|
i::Handle<i::String> external;
|
|
|
|
if (isolate->heap()->old_pointer_space()->Contains(*obj)) {
|
|
|
|
// We do not allow external strings in the old pointer space. Instead of
|
|
|
|
// converting the string in-place, we keep the cons/sliced string and
|
|
|
|
// point it to a newly-allocated external string.
|
|
|
|
external = NewExternalStringHandle(isolate, resource);
|
|
|
|
result = RedirectToExternalString(isolate, obj, external);
|
|
|
|
} else {
|
|
|
|
result = obj->MakeExternal(resource);
|
|
|
|
external = obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT(external->IsExternalString());
|
|
|
|
if (result && !external->IsInternalizedString()) {
|
|
|
|
isolate->heap()->external_string_table()->AddString(*external);
|
2009-02-11 23:52:52 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Local<String> v8::String::NewExternal(
|
|
|
|
v8::String::ExternalAsciiStringResource* resource) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()");
|
|
|
|
LOG_API(isolate, "String::NewExternal");
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2012-08-14 12:16:38 +00:00
|
|
|
CHECK(resource && resource->data());
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Handle<i::String> result = NewExternalAsciiStringHandle(isolate, resource);
|
|
|
|
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 (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false;
|
|
|
|
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
|
|
|
|
|
|
|
bool result;
|
|
|
|
i::Handle<i::String> external;
|
|
|
|
if (isolate->heap()->old_pointer_space()->Contains(*obj)) {
|
|
|
|
// We do not allow external strings in the old pointer space. Instead of
|
|
|
|
// converting the string in-place, we keep the cons/sliced string and
|
|
|
|
// point it to a newly-allocated external string.
|
|
|
|
external = NewExternalAsciiStringHandle(isolate, resource);
|
|
|
|
result = RedirectToExternalString(isolate, obj, external);
|
|
|
|
} else {
|
|
|
|
result = obj->MakeExternal(resource);
|
|
|
|
external = obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT(external->IsExternalString());
|
|
|
|
if (result && !external->IsInternalizedString()) {
|
|
|
|
isolate->heap()->external_string_table()->AddString(*external);
|
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();
|
|
|
|
if (IsDeadCheck(isolate, "v8::String::CanMakeExternal()")) 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Local<v8::Object> v8::Object::New() {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
EnsureInitializedForIsolate(isolate, "v8::Object::New()");
|
|
|
|
LOG_API(isolate, "Object::New");
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::JSObject> obj =
|
2011-03-23 14:07:52 +00:00
|
|
|
isolate->factory()->NewJSObject(isolate->object_function());
|
2008-07-03 15:10:15 +00:00
|
|
|
return Utils::ToLocal(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-14 11:00:04 +00:00
|
|
|
Local<v8::Value> v8::NumberObject::New(double value) {
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
EnsureInitializedForIsolate(isolate, "v8::NumberObject::New()");
|
|
|
|
LOG_API(isolate, "NumberObject::New");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
i::Handle<i::Object> number = isolate->factory()->NewNumber(value);
|
|
|
|
i::Handle<i::Object> obj = isolate->factory()->ToObject(number);
|
|
|
|
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::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::NumberObject::NumberValue()")) return 0;
|
|
|
|
LOG_API(isolate, "NumberObject::NumberValue");
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj);
|
|
|
|
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);
|
2011-07-14 11:00:04 +00:00
|
|
|
i::Handle<i::Object> obj = isolate->factory()->ToObject(boolean);
|
|
|
|
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::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::BooleanObject::BooleanValue()")) return 0;
|
|
|
|
LOG_API(isolate, "BooleanObject::BooleanValue");
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj);
|
|
|
|
return jsvalue->value()->IsTrue();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<v8::Value> v8::StringObject::New(Handle<String> value) {
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
EnsureInitializedForIsolate(isolate, "v8::StringObject::New()");
|
|
|
|
LOG_API(isolate, "StringObject::New");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
i::Handle<i::Object> obj =
|
|
|
|
isolate->factory()->ToObject(Utils::OpenHandle(*value));
|
|
|
|
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::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::StringObject::StringValue()")) {
|
|
|
|
return Local<v8::String>();
|
|
|
|
}
|
|
|
|
LOG_API(isolate, "StringObject::StringValue");
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj);
|
|
|
|
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);
|
|
|
|
i::Handle<i::Object> obj =
|
|
|
|
i_isolate->factory()->ToObject(Utils::OpenHandle(*value));
|
|
|
|
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::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::SymbolObject::SymbolValue()"))
|
|
|
|
return Local<v8::Symbol>();
|
|
|
|
LOG_API(isolate, "SymbolObject::SymbolValue");
|
|
|
|
i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj);
|
|
|
|
return Utils::ToLocal(
|
|
|
|
i::Handle<i::Symbol>(i::Symbol::cast(jsvalue->value())));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Local<v8::Value> v8::Date::New(double time) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
EnsureInitializedForIsolate(isolate, "v8::Date::New()");
|
|
|
|
LOG_API(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();
|
|
|
|
}
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
i::Handle<i::Object> obj =
|
2013-09-03 06:59:01 +00:00
|
|
|
i::Execution::NewDate(isolate, time, &has_pending_exception);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(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 {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::Date::NumberValue()")) return 0;
|
|
|
|
LOG_API(isolate, "Date::NumberValue");
|
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);
|
|
|
|
return jsdate->value()->Number();
|
2008-10-23 08:25:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-17 12:45:27 +00:00
|
|
|
void v8::Date::DateTimeConfigurationChangeNotification() {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
ON_BAILOUT(isolate, "v8::Date::DateTimeConfigurationChangeNotification()",
|
|
|
|
return);
|
|
|
|
LOG_API(isolate, "Date::DateTimeConfigurationChangeNotification");
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2010-12-17 12:45:27 +00:00
|
|
|
|
2012-03-09 12:07:29 +00:00
|
|
|
isolate->date_cache()->ResetDateCache();
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2012-03-09 11:19:55 +00:00
|
|
|
// Get the function ResetDateCache (defined in date.js).
|
2013-02-28 17:03:34 +00:00
|
|
|
i::Handle<i::String> func_name_str =
|
|
|
|
isolate->factory()->InternalizeOneByteString(
|
|
|
|
STATIC_ASCII_VECTOR("ResetDateCache"));
|
2011-03-18 20:35:07 +00:00
|
|
|
i::MaybeObject* result =
|
|
|
|
isolate->js_builtins_object()->GetProperty(*func_name_str);
|
2010-12-17 12:45:27 +00:00
|
|
|
i::Object* object_func;
|
|
|
|
if (!result->ToObject(&object_func)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (object_func->IsJSFunction()) {
|
|
|
|
i::Handle<i::JSFunction> func =
|
|
|
|
i::Handle<i::JSFunction>(i::JSFunction::cast(object_func));
|
|
|
|
|
|
|
|
// Call ResetDateCache(0 but expect no exceptions:
|
|
|
|
bool caught_exception = false;
|
2011-03-30 20:14:55 +00:00
|
|
|
i::Execution::TryCall(func,
|
|
|
|
isolate->js_builtins_object(),
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
&caught_exception);
|
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);
|
2010-10-05 11:51:41 +00:00
|
|
|
i::Handle<i::JSRegExp> obj = i::Execution::NewJSRegExp(
|
|
|
|
Utils::OpenHandle(*pattern),
|
|
|
|
RegExpFlagsToString(flags),
|
2010-10-04 15:04:16 +00:00
|
|
|
&has_pending_exception);
|
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 {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::RegExp::GetSource()")) {
|
|
|
|
return Local<v8::String>();
|
|
|
|
}
|
2010-10-04 15:04:16 +00:00
|
|
|
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.
|
|
|
|
#define REGEXP_FLAG_ASSERT_EQ(api_flag, internal_flag) \
|
|
|
|
STATIC_ASSERT(static_cast<int>(v8::RegExp::api_flag) == \
|
|
|
|
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 {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(i::Isolate::Current(), "v8::RegExp::GetFlags()")) {
|
|
|
|
return v8::RegExp::kNone;
|
|
|
|
}
|
2010-10-04 15:04:16 +00:00
|
|
|
i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this);
|
|
|
|
return static_cast<RegExp::Flags>(obj->GetFlags().value());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Local<v8::Array> v8::Array::New(int length) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
EnsureInitializedForIsolate(isolate, "v8::Array::New()");
|
|
|
|
LOG_API(isolate, "Array::New");
|
2011-03-24 18:49:45 +00:00
|
|
|
ENTER_V8(isolate);
|
2011-03-16 19:55:31 +00:00
|
|
|
int real_length = length > 0 ? length : 0;
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Handle<i::JSArray> obj = isolate->factory()->NewJSArray(real_length);
|
2011-03-30 10:46:55 +00:00
|
|
|
i::Handle<i::Object> length_obj =
|
|
|
|
isolate->factory()->NewNumberFromInt(real_length);
|
|
|
|
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 {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::Array::Length()")) return 0;
|
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);
|
2009-06-24 11:52:52 +00:00
|
|
|
i::Handle<i::JSObject> result = i::Copy(paragon_handle);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
2013-05-23 10:01:42 +00:00
|
|
|
ApiCheck(!obj->is_external(),
|
|
|
|
"v8::ArrayBuffer::Externalize",
|
|
|
|
"ArrayBuffer already externalized");
|
|
|
|
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();
|
|
|
|
ApiCheck(obj->is_external(),
|
|
|
|
"v8::ArrayBuffer::Neuter",
|
|
|
|
"Only externalized ArrayBuffers can be neutered");
|
|
|
|
LOG_API(obj->GetIsolate(), "v8::ArrayBuffer::Neuter()");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
|
2013-06-21 13:02:38 +00:00
|
|
|
for (i::Handle<i::Object> view_obj(obj->weak_first_view(), isolate);
|
|
|
|
!view_obj->IsUndefined();) {
|
|
|
|
i::Handle<i::JSArrayBufferView> view(i::JSArrayBufferView::cast(*view_obj));
|
|
|
|
if (view->IsJSTypedArray()) {
|
|
|
|
i::JSTypedArray::cast(*view)->Neuter();
|
|
|
|
} else if (view->IsJSDataView()) {
|
|
|
|
i::JSDataView::cast(*view)->Neuter();
|
|
|
|
} else {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
view_obj = i::handle(view->weak_next(), isolate);
|
2013-06-07 15:02:20 +00:00
|
|
|
}
|
|
|
|
obj->Neuter();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-23 10:01:42 +00:00
|
|
|
size_t v8::ArrayBuffer::ByteLength() const {
|
2013-04-25 12:02:23 +00:00
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
2013-05-23 10:01:42 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::ArrayBuffer::ByteLength()")) return 0;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<ArrayBuffer> v8::ArrayBuffer::New(size_t byte_length) {
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
EnsureInitializedForIsolate(isolate, "v8::ArrayBuffer::New(size_t)");
|
|
|
|
LOG_API(isolate, "v8::ArrayBuffer::New(size_t)");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
i::Handle<i::JSArrayBuffer> obj =
|
|
|
|
isolate->factory()->NewJSArrayBuffer();
|
|
|
|
i::Runtime::SetupArrayBufferAllocatingData(isolate, obj, byte_length);
|
|
|
|
return Utils::ToLocal(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<ArrayBuffer> v8::ArrayBuffer::New(void* data, size_t byte_length) {
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
EnsureInitializedForIsolate(isolate, "v8::ArrayBuffer::New(void*, size_t)");
|
|
|
|
LOG_API(isolate, "v8::ArrayBuffer::New(void*, size_t)");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
i::Handle<i::JSArrayBuffer> obj =
|
|
|
|
isolate->factory()->NewJSArrayBuffer();
|
2013-05-23 10:01:42 +00:00
|
|
|
i::Runtime::SetupArrayBuffer(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);
|
2013-04-29 11:09:03 +00:00
|
|
|
ASSERT(obj->buffer()->IsJSArrayBuffer());
|
|
|
|
i::Handle<i::JSArrayBuffer> buffer(i::JSArrayBuffer::cast(obj->buffer()));
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-24 11:23:50 +00:00
|
|
|
void* v8::ArrayBufferView::BaseAddress() {
|
|
|
|
i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this);
|
|
|
|
i::Handle<i::JSArrayBuffer> buffer(i::JSArrayBuffer::cast(obj->buffer()));
|
|
|
|
void* buffer_data = buffer->backing_store();
|
|
|
|
size_t byte_offset = static_cast<size_t>(obj->byte_offset()->Number());
|
|
|
|
return static_cast<uint8_t*>(buffer_data) + byte_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-29 11:09:03 +00:00
|
|
|
size_t v8::TypedArray::Length() {
|
|
|
|
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
|
|
|
if (IsDeadCheck(isolate, "v8::TypedArray::Length()")) return 0;
|
|
|
|
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 <=
|
|
|
|
static_cast<size_t>(buffer->byte_length()->Number()));
|
|
|
|
|
|
|
|
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 =
|
|
|
|
isolate->factory()->NewNumberFromSize(byte_offset);
|
|
|
|
obj->set_byte_offset(*byte_offset_object);
|
|
|
|
|
|
|
|
i::Handle<i::Object> byte_length_object =
|
|
|
|
isolate->factory()->NewNumberFromSize(byte_length);
|
|
|
|
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-06-24 11:23:50 +00:00
|
|
|
SetupArrayBufferView(
|
|
|
|
isolate, obj, buffer, byte_offset, length * sizeof(ElementType));
|
2013-04-29 11:09:03 +00:00
|
|
|
|
2013-06-24 11:23:50 +00:00
|
|
|
i::Handle<i::Object> length_object =
|
|
|
|
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);
|
|
|
|
obj->set_elements(*elements);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define TYPED_ARRAY_NEW(TypedArray, element_type, array_type, elements_kind) \
|
|
|
|
Local<TypedArray> TypedArray::New(Handle<ArrayBuffer> array_buffer, \
|
|
|
|
size_t byte_offset, size_t length) { \
|
|
|
|
i::Isolate* isolate = i::Isolate::Current(); \
|
|
|
|
EnsureInitializedForIsolate(isolate, \
|
|
|
|
"v8::" #TypedArray "::New(Handle<ArrayBuffer>, size_t, size_t)"); \
|
|
|
|
LOG_API(isolate, \
|
|
|
|
"v8::" #TypedArray "::New(Handle<ArrayBuffer>, size_t, size_t)"); \
|
|
|
|
ENTER_V8(isolate); \
|
|
|
|
i::Handle<i::JSTypedArray> obj = \
|
|
|
|
NewTypedArray<element_type, array_type, elements_kind>( \
|
|
|
|
isolate, array_buffer, byte_offset, length); \
|
|
|
|
return Utils::ToLocal##TypedArray(obj); \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TYPED_ARRAY_NEW(Uint8Array, uint8_t, kExternalUnsignedByteArray,
|
|
|
|
i::EXTERNAL_UNSIGNED_BYTE_ELEMENTS)
|
2013-05-02 11:36:48 +00:00
|
|
|
TYPED_ARRAY_NEW(Uint8ClampedArray, uint8_t, kExternalPixelArray,
|
|
|
|
i::EXTERNAL_PIXEL_ELEMENTS)
|
2013-04-29 11:09:03 +00:00
|
|
|
TYPED_ARRAY_NEW(Int8Array, int8_t, kExternalByteArray,
|
|
|
|
i::EXTERNAL_BYTE_ELEMENTS)
|
|
|
|
TYPED_ARRAY_NEW(Uint16Array, uint16_t, kExternalUnsignedShortArray,
|
|
|
|
i::EXTERNAL_UNSIGNED_SHORT_ELEMENTS)
|
|
|
|
TYPED_ARRAY_NEW(Int16Array, int16_t, kExternalShortArray,
|
|
|
|
i::EXTERNAL_SHORT_ELEMENTS)
|
|
|
|
TYPED_ARRAY_NEW(Uint32Array, uint32_t, kExternalUnsignedIntArray,
|
|
|
|
i::EXTERNAL_UNSIGNED_INT_ELEMENTS)
|
|
|
|
TYPED_ARRAY_NEW(Int32Array, int32_t, kExternalIntArray,
|
|
|
|
i::EXTERNAL_INT_ELEMENTS)
|
|
|
|
TYPED_ARRAY_NEW(Float32Array, float, kExternalFloatArray,
|
|
|
|
i::EXTERNAL_FLOAT_ELEMENTS)
|
|
|
|
TYPED_ARRAY_NEW(Float64Array, double, kExternalDoubleArray,
|
|
|
|
i::EXTERNAL_DOUBLE_ELEMENTS)
|
|
|
|
|
|
|
|
#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) {
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
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();
|
|
|
|
i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer);
|
|
|
|
SetupArrayBufferView(
|
|
|
|
isolate, obj, buffer, byte_offset, byte_length);
|
|
|
|
return Utils::ToLocal(obj);
|
|
|
|
}
|
|
|
|
|
2013-04-29 11:09:03 +00:00
|
|
|
|
2013-04-10 12:16:29 +00:00
|
|
|
Local<Symbol> v8::Symbol::New(Isolate* isolate) {
|
|
|
|
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();
|
|
|
|
return Utils::ToLocal(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<Symbol> v8::Symbol::New(Isolate* isolate, const char* data, int length) {
|
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
EnsureInitializedForIsolate(i_isolate, "v8::Symbol::New()");
|
|
|
|
LOG_API(i_isolate, "Symbol::New(char)");
|
|
|
|
ENTER_V8(i_isolate);
|
|
|
|
if (length == -1) length = i::StrLength(data);
|
|
|
|
i::Handle<i::String> name = i_isolate->factory()->NewStringFromUtf8(
|
|
|
|
i::Vector<const char>(data, length));
|
|
|
|
i::Handle<i::Symbol> result = i_isolate->factory()->NewSymbol();
|
|
|
|
result->set_name(*name);
|
|
|
|
return Utils::ToLocal(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Local<Number> v8::Number::New(double value) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
EnsureInitializedForIsolate(isolate, "v8::Number::New()");
|
2013-05-22 06:35:38 +00:00
|
|
|
return Number::New(reinterpret_cast<Isolate*>(isolate), value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<Integer> v8::Integer::New(int32_t value) {
|
2012-03-30 14:30:46 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::UncheckedCurrent();
|
2011-03-18 20:35:07 +00:00
|
|
|
EnsureInitializedForIsolate(isolate, "v8::Integer::New()");
|
2012-10-19 11:15:04 +00:00
|
|
|
return v8::Integer::New(value, reinterpret_cast<Isolate*>(isolate));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<Integer> Integer::NewFromUnsigned(uint32_t value) {
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
EnsureInitializedForIsolate(isolate, "v8::Integer::NewFromUnsigned()");
|
|
|
|
return Integer::NewFromUnsigned(value, reinterpret_cast<Isolate*>(isolate));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Local<Integer> v8::Integer::New(int32_t value, Isolate* isolate) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-19 11:15:04 +00:00
|
|
|
Local<Integer> v8::Integer::NewFromUnsigned(uint32_t value, Isolate* isolate) {
|
|
|
|
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) {
|
2012-10-19 11:15:04 +00:00
|
|
|
return Integer::New(static_cast<int32_t>(value), isolate);
|
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-05-02 20:28:02 +00:00
|
|
|
#ifdef DEBUG
|
2013-06-03 15:32:22 +00:00
|
|
|
v8::AssertNoGCScope::AssertNoGCScope(v8::Isolate* isolate) {
|
|
|
|
disallow_heap_allocation_ = new i::DisallowHeapAllocation();
|
2013-05-02 20:28:02 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2013-05-02 20:28:02 +00:00
|
|
|
v8::AssertNoGCScope::~AssertNoGCScope() {
|
2013-06-03 15:32:22 +00:00
|
|
|
delete static_cast<i::DisallowHeapAllocation*>(disallow_heap_allocation_);
|
2013-05-02 20:28:02 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void V8::IgnoreOutOfMemoryException() {
|
2011-08-04 15:18:18 +00:00
|
|
|
EnterIsolateIfNeeded()->set_ignore_out_of_memory(true);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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());
|
2013-02-27 14:35:39 +00:00
|
|
|
NeanderObject obj(2);
|
|
|
|
obj.set(0, *isolate->factory()->NewForeign(FUNCTION_ADDR(that)));
|
|
|
|
obj.set(1, data.IsEmpty() ? isolate->heap()->undefined_value()
|
|
|
|
: *Utils::OpenHandle(*data));
|
|
|
|
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(
|
|
|
|
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) {
|
2011-03-24 19:05:49 +00:00
|
|
|
i::Isolate* isolate = EnterIsolateIfNeeded();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::V8::SetCounterFunction()")) return;
|
|
|
|
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) {
|
2011-03-24 19:05:49 +00:00
|
|
|
i::Isolate* isolate = EnterIsolateIfNeeded();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::V8::SetCreateHistogramFunction()")) return;
|
|
|
|
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) {
|
2011-03-24 19:05:49 +00:00
|
|
|
i::Isolate* isolate = EnterIsolateIfNeeded();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (IsDeadCheck(isolate, "v8::V8::SetAddHistogramSampleFunction()")) return;
|
|
|
|
isolate->stats_table()->
|
|
|
|
SetAddHistogramSampleFunction(callback);
|
2009-03-13 16:06:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
void V8::SetFailedAccessCheckCallbackFunction(
|
|
|
|
FailedAccessCheckCallback callback) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::V8::SetFailedAccessCheckCallbackFunction()")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
isolate->SetFailedAccessCheckCallback(callback);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 10:14:10 +00:00
|
|
|
|
2013-03-13 13:15:09 +00:00
|
|
|
intptr_t Isolate::AdjustAmountOfExternalAllocatedMemory(
|
|
|
|
intptr_t change_in_bytes) {
|
|
|
|
i::Heap* heap = reinterpret_cast<i::Isolate*>(this)->heap();
|
|
|
|
return heap->AdjustAmountOfExternalAllocatedMemory(change_in_bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-11 09:23:57 +00:00
|
|
|
intptr_t V8::AdjustAmountOfExternalAllocatedMemory(intptr_t change_in_bytes) {
|
2012-08-06 13:49:13 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::UncheckedCurrent();
|
|
|
|
if (isolate == NULL || !isolate->IsInitialized() ||
|
|
|
|
IsDeadCheck(isolate, "v8::V8::AdjustAmountOfExternalAllocatedMemory()")) {
|
2011-03-18 20:35:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2013-03-13 13:15:09 +00:00
|
|
|
Isolate* isolate_ext = reinterpret_cast<Isolate*>(isolate);
|
|
|
|
return isolate_ext->AdjustAmountOfExternalAllocatedMemory(change_in_bytes);
|
2008-07-30 08:49:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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-04-09 07:34:32 +00:00
|
|
|
v8::Local<v8::Context> Isolate::GetCurrentContext() {
|
|
|
|
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this);
|
2013-06-21 12:34:47 +00:00
|
|
|
i::Context* context = internal_isolate->context();
|
|
|
|
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-04-24 15:59:23 +00:00
|
|
|
void Isolate::SetObjectGroupId(const Persistent<Value>& object,
|
|
|
|
UniqueId id) {
|
|
|
|
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this);
|
|
|
|
internal_isolate->global_handles()->SetObjectGroupId(
|
2013-06-13 09:27:09 +00:00
|
|
|
Utils::OpenPersistent(object).location(),
|
|
|
|
id);
|
2013-04-24 15:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::SetReferenceFromGroup(UniqueId id,
|
|
|
|
const Persistent<Value>& object) {
|
|
|
|
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this);
|
2013-06-13 09:27:09 +00:00
|
|
|
internal_isolate->global_handles()->SetReferenceFromGroup(
|
|
|
|
id,
|
|
|
|
Utils::OpenPersistent(object).location());
|
2013-04-24 15:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::SetReference(const Persistent<Object>& parent,
|
|
|
|
const Persistent<Value>& child) {
|
|
|
|
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this);
|
2013-06-13 09:27:09 +00:00
|
|
|
i::Object** parent_location = Utils::OpenPersistent(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),
|
|
|
|
Utils::OpenPersistent(child).location());
|
2013-04-24 15:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void V8::SetGlobalGCPrologueCallback(GCCallback callback) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::V8::SetGlobalGCPrologueCallback()")) return;
|
|
|
|
isolate->heap()->SetGlobalGCPrologueCallback(callback);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void V8::SetGlobalGCEpilogueCallback(GCCallback callback) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::V8::SetGlobalGCEpilogueCallback()")) return;
|
|
|
|
isolate->heap()->SetGlobalGCEpilogueCallback(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();
|
|
|
|
if (IsDeadCheck(isolate, "v8::V8::AddGCPrologueCallback()")) return;
|
|
|
|
isolate->heap()->AddGCPrologueCallback(callback, gc_type);
|
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();
|
|
|
|
if (IsDeadCheck(isolate, "v8::V8::RemoveGCPrologueCallback()")) return;
|
|
|
|
isolate->heap()->RemoveGCPrologueCallback(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();
|
|
|
|
if (IsDeadCheck(isolate, "v8::V8::AddGCEpilogueCallback()")) return;
|
|
|
|
isolate->heap()->AddGCEpilogueCallback(callback, gc_type);
|
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();
|
|
|
|
if (IsDeadCheck(isolate, "v8::V8::RemoveGCEpilogueCallback()")) return;
|
|
|
|
isolate->heap()->RemoveGCEpilogueCallback(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();
|
|
|
|
if (IsDeadCheck(isolate, "v8::V8::AddMemoryAllocationCallback()")) return;
|
|
|
|
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();
|
|
|
|
if (IsDeadCheck(isolate, "v8::V8::RemoveMemoryAllocationCallback()")) return;
|
|
|
|
isolate->memory_allocator()->RemoveMemoryAllocationCallback(
|
|
|
|
callback);
|
2010-09-03 11:31:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-04 08:48:35 +00:00
|
|
|
void V8::AddCallCompletedCallback(CallCompletedCallback callback) {
|
|
|
|
if (callback == NULL) return;
|
2012-04-04 14:28:00 +00:00
|
|
|
i::Isolate::EnsureDefaultIsolate();
|
2012-01-04 08:48:35 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::V8::AddLeaveScriptCallback()")) return;
|
|
|
|
i::V8::AddCallCompletedCallback(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void V8::RemoveCallCompletedCallback(CallCompletedCallback callback) {
|
2012-04-04 14:28:00 +00:00
|
|
|
i::Isolate::EnsureDefaultIsolate();
|
2012-01-04 08:48:35 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::V8::RemoveLeaveScriptCallback()")) return;
|
|
|
|
i::V8::RemoveCallCompletedCallback(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-19 15:14:11 +00:00
|
|
|
int V8::GetCurrentThreadId() {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
EnsureInitializedForIsolate(isolate, "V8::GetCurrentThreadId()");
|
2011-04-11 23:46:22 +00:00
|
|
|
return isolate->thread_id().ToInteger();
|
2009-08-19 15:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void V8::TerminateExecution(int thread_id) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
2011-03-23 14:07:52 +00:00
|
|
|
if (!isolate->IsInitialized()) return;
|
2011-06-07 13:09:01 +00:00
|
|
|
API_ENTRY_CHECK(isolate, "V8::TerminateExecution()");
|
2009-08-19 15:14:11 +00:00
|
|
|
// If the thread_id identifies the current thread just terminate
|
|
|
|
// execution right away. Otherwise, ask the thread manager to
|
|
|
|
// terminate the thread with the given id if any.
|
2011-04-11 23:46:22 +00:00
|
|
|
i::ThreadId internal_tid = i::ThreadId::FromInteger(thread_id);
|
|
|
|
if (isolate->thread_id().Equals(internal_tid)) {
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->stack_guard()->TerminateExecution();
|
2009-08-19 15:14:11 +00:00
|
|
|
} else {
|
2011-04-11 23:46:22 +00:00
|
|
|
isolate->thread_manager()->TerminateExecution(internal_tid);
|
2009-08-19 15:14:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
void V8::TerminateExecution(Isolate* isolate) {
|
|
|
|
// If no isolate is supplied, use the default isolate.
|
|
|
|
if (isolate != NULL) {
|
|
|
|
reinterpret_cast<i::Isolate*>(isolate)->stack_guard()->TerminateExecution();
|
|
|
|
} else {
|
|
|
|
i::Isolate::GetDefaultIsolateStackGuard()->TerminateExecution();
|
|
|
|
}
|
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);
|
|
|
|
i_isolate->stack_guard()->CancelTerminateExecution();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
if (!ApiCheck(!isolate->IsInUse(),
|
|
|
|
"v8::Isolate::Dispose()",
|
|
|
|
"Disposing the isolate that is entered by a thread.")) {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
if (IsDeadCheck(isolate, "v8::String::Utf8Value::Utf8Value()")) return;
|
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::AsciiValue::AsciiValue(v8::Handle<v8::Value> obj)
|
|
|
|
: str_(NULL), length_(0) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
if (IsDeadCheck(isolate, "v8::String::AsciiValue::AsciiValue()")) return;
|
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;
|
2013-05-03 06:47:24 +00:00
|
|
|
length_ = str->Utf8Length();
|
2011-05-09 10:39:02 +00:00
|
|
|
str_ = i::NewArray<char>(length_ + 1);
|
2013-05-03 06:47:24 +00:00
|
|
|
str->WriteUtf8(str_);
|
|
|
|
ASSERT(i::String::NonAsciiStart(str_, length_) >= length_);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String::AsciiValue::~AsciiValue() {
|
|
|
|
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();
|
|
|
|
if (IsDeadCheck(isolate, "v8::String::Value::Value()")) return;
|
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 ---
|
|
|
|
|
2009-04-20 16:36:13 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
2010-05-20 17:15:46 +00:00
|
|
|
|
|
|
|
bool Debug::SetDebugEventListener2(EventCallback2 that, Handle<Value> data) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
EnsureInitializedForIsolate(isolate, "v8::Debug::SetDebugEventListener2()");
|
|
|
|
ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener2()", 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
|
|
|
}
|
2012-09-05 16:06:53 +00:00
|
|
|
isolate->debugger()->SetEventListener(foreign,
|
|
|
|
Utils::OpenHandle(*data, true));
|
2008-07-03 15:10:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-03 07:59:12 +00:00
|
|
|
bool Debug::SetDebugEventListener(v8::Handle<v8::Object> that,
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<Value> data) {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
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
|
|
|
isolate->debugger()->SetEventListener(Utils::OpenHandle(*that),
|
2012-09-05 16:06:53 +00:00
|
|
|
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) {
|
|
|
|
// If no isolate is supplied, use the default isolate.
|
|
|
|
if (isolate != NULL) {
|
|
|
|
reinterpret_cast<i::Isolate*>(isolate)->stack_guard()->DebugBreak();
|
|
|
|
} else {
|
|
|
|
i::Isolate::GetDefaultIsolateStackGuard()->DebugBreak();
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
void Debug::CancelDebugBreak(Isolate* isolate) {
|
|
|
|
// If no isolate is supplied, use the default isolate.
|
|
|
|
if (isolate != NULL) {
|
|
|
|
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
internal_isolate->stack_guard()->Continue(i::DEBUGBREAK);
|
|
|
|
} else {
|
|
|
|
i::Isolate::GetDefaultIsolateStackGuard()->Continue(i::DEBUGBREAK);
|
|
|
|
}
|
2010-09-27 15:09:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
void Debug::DebugBreakForCommand(ClientData* data, Isolate* isolate) {
|
|
|
|
// If no isolate is supplied, use the default isolate.
|
|
|
|
if (isolate != NULL) {
|
|
|
|
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
internal_isolate->debugger()->EnqueueDebugCommand(data);
|
|
|
|
} else {
|
|
|
|
i::Isolate::GetDefaultIsolateDebugger()->EnqueueDebugCommand(data);
|
|
|
|
}
|
2010-07-14 08:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-29 12:54:07 +00:00
|
|
|
void Debug::SetMessageHandler2(v8::Debug::MessageHandler2 handler) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
EnsureInitializedForIsolate(isolate, "v8::Debug::SetMessageHandler");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
isolate->debugger()->SetMessageHandler(handler);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-21 14:06:48 +00:00
|
|
|
void Debug::SendCommand(const uint16_t* command, int length,
|
2011-03-22 18:02:23 +00:00
|
|
|
ClientData* client_data,
|
|
|
|
Isolate* isolate) {
|
|
|
|
// If no isolate is supplied, use the default isolate.
|
|
|
|
if (isolate != NULL) {
|
|
|
|
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
internal_isolate->debugger()->ProcessCommand(
|
|
|
|
i::Vector<const uint16_t>(command, length), client_data);
|
|
|
|
} else {
|
|
|
|
i::Isolate::GetDefaultIsolateDebugger()->ProcessCommand(
|
|
|
|
i::Vector<const uint16_t>(command, length), client_data);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-22 14:16:50 +00:00
|
|
|
void Debug::SetHostDispatchHandler(HostDispatchHandler handler,
|
|
|
|
int period) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
EnsureInitializedForIsolate(isolate, "v8::Debug::SetHostDispatchHandler");
|
|
|
|
ENTER_V8(isolate);
|
2013-09-02 12:26:06 +00:00
|
|
|
isolate->debugger()->SetHostDispatchHandler(
|
|
|
|
handler, i::TimeDelta::FromMilliseconds(period));
|
2009-02-19 14:02:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-18 08:59:28 +00:00
|
|
|
void Debug::SetDebugMessageDispatchHandler(
|
2010-01-18 15:48:41 +00:00
|
|
|
DebugMessageDispatchHandler handler, bool provide_locker) {
|
2011-03-24 18:49:45 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
EnsureInitializedForIsolate(isolate,
|
|
|
|
"v8::Debug::SetDebugMessageDispatchHandler");
|
|
|
|
ENTER_V8(isolate);
|
|
|
|
isolate->debugger()->SetDebugMessageDispatchHandler(
|
2011-03-18 20:35:07 +00:00
|
|
|
handler, provide_locker);
|
2009-11-18 08:59:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
2008-11-27 08:01:27 +00:00
|
|
|
i::Handle<i::Object> result;
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2008-11-27 08:01:27 +00:00
|
|
|
if (data.IsEmpty()) {
|
2011-03-24 18:49:45 +00:00
|
|
|
result = isolate->debugger()->Call(Utils::OpenHandle(*fun),
|
|
|
|
isolate->factory()->undefined_value(),
|
|
|
|
&has_pending_exception);
|
2008-11-27 08:01:27 +00:00
|
|
|
} else {
|
2011-03-23 14:07:52 +00:00
|
|
|
result = isolate->debugger()->Call(Utils::OpenHandle(*fun),
|
2011-03-24 18:49:45 +00:00
|
|
|
Utils::OpenHandle(*data),
|
|
|
|
&has_pending_exception);
|
2008-11-27 08:01:27 +00:00
|
|
|
}
|
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-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(reinterpret_cast<Isolate*>(isolate));
|
2011-03-23 14:07:52 +00:00
|
|
|
i::Debug* isolate_debug = isolate->debug();
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate_debug->Load();
|
2012-08-17 12:59:00 +00:00
|
|
|
i::Handle<i::JSObject> debug(isolate_debug->debug_context()->global_object());
|
2013-02-28 17:03:34 +00:00
|
|
|
i::Handle<i::String> name = isolate->factory()->InternalizeOneByteString(
|
2012-12-17 15:56:16 +00:00
|
|
|
STATIC_ASCII_VECTOR("MakeMirror"));
|
2013-02-25 14:46:09 +00:00
|
|
|
i::Handle<i::Object> fun_obj = i::GetProperty(isolate, debug, name);
|
2009-08-17 14:26:48 +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 };
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_PREAMBLE(isolate);
|
2009-08-17 14:26:48 +00:00
|
|
|
v8::Handle<v8::Value> result = v8_fun->Call(Utils::ToLocal(debug),
|
|
|
|
kArgc,
|
|
|
|
argv);
|
2011-03-24 18:49:45 +00:00
|
|
|
EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>());
|
2009-08-17 14:26:48 +00:00
|
|
|
return scope.Close(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-18 20:30:29 +00:00
|
|
|
bool Debug::EnableAgent(const char* name, int port, bool wait_for_connection) {
|
2011-03-18 20:35:07 +00:00
|
|
|
return i::Isolate::Current()->debugger()->StartAgent(name, port,
|
|
|
|
wait_for_connection);
|
2009-03-03 12:23:45 +00:00
|
|
|
}
|
2011-09-21 11:34:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
void Debug::DisableAgent() {
|
|
|
|
return i::Isolate::Current()->debugger()->StopAgent();
|
|
|
|
}
|
|
|
|
|
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);
|
2011-03-18 20:35:07 +00:00
|
|
|
return Utils::ToLocal(i::Isolate::Current()->debugger()->GetDebugContext());
|
2010-03-24 13:09:02 +00:00
|
|
|
}
|
|
|
|
|
2012-09-10 09:24:17 +00:00
|
|
|
|
|
|
|
void Debug::SetLiveEditEnabled(bool enable, Isolate* isolate) {
|
|
|
|
// If no isolate is supplied, use the default isolate.
|
|
|
|
i::Debugger* debugger;
|
|
|
|
if (isolate != NULL) {
|
|
|
|
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
debugger = internal_isolate->debugger();
|
|
|
|
} else {
|
|
|
|
debugger = i::Isolate::GetDefaultIsolateDebugger();
|
|
|
|
}
|
|
|
|
debugger->set_live_edit_enabled(enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-20 17:44:39 +00:00
|
|
|
#endif // ENABLE_DEBUGGER_SUPPORT
|
2009-03-03 12:23:45 +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();
|
|
|
|
IsDeadCheck(isolate, "v8::CpuProfileNode::GetFunctionName");
|
2010-04-06 14:54:20 +00:00
|
|
|
const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
|
|
|
|
const i::CodeEntry* entry = node->entry();
|
|
|
|
if (!entry->has_name_prefix()) {
|
2013-06-13 09:27:09 +00:00
|
|
|
return ToApiHandle<String>(
|
|
|
|
isolate->factory()->InternalizeUtf8String(entry->name()));
|
2010-04-06 14:54:20 +00:00
|
|
|
} else {
|
2013-06-13 09:27:09 +00:00
|
|
|
return ToApiHandle<String>(isolate->factory()->NewConsString(
|
2013-02-28 17:03:34 +00:00
|
|
|
isolate->factory()->InternalizeUtf8String(entry->name_prefix()),
|
2013-06-13 09:27:09 +00:00
|
|
|
isolate->factory()->InternalizeUtf8String(entry->name())));
|
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();
|
|
|
|
IsDeadCheck(isolate, "v8::CpuProfileNode::GetScriptResourceName");
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double CpuProfileNode::GetSelfSamplesCount() const {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
IsDeadCheck(isolate, "v8::CpuProfileNode::GetSelfSamplesCount");
|
2010-04-06 14:54:20 +00:00
|
|
|
return reinterpret_cast<const i::ProfileNode*>(this)->self_ticks();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
IsDeadCheck(isolate, "v8::CpuProfile::Delete");
|
2013-04-02 07:53:50 +00:00
|
|
|
i::CpuProfiler* profiler = isolate->cpu_profiler();
|
|
|
|
ASSERT(profiler != NULL);
|
|
|
|
profiler->DeleteProfile(reinterpret_cast<i::CpuProfile*>(this));
|
2013-07-06 09:12:09 +00:00
|
|
|
if (profiler->GetProfilesCount() == 0) {
|
2011-03-22 16:10:01 +00:00
|
|
|
// If this was the last profile, clean up all accessory data as well.
|
2013-04-02 07:53:50 +00:00
|
|
|
profiler->DeleteAllProfiles();
|
2011-03-22 16:10:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-06 14:54:20 +00:00
|
|
|
unsigned CpuProfile::GetUid() const {
|
|
|
|
return reinterpret_cast<const i::CpuProfile*>(this)->uid();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<String> CpuProfile::GetTitle() const {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
IsDeadCheck(isolate, "v8::CpuProfile::GetTitle");
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
2013-08-29 09:15:13 +00:00
|
|
|
return (profile->start_time() - i::Time::UnixEpoch()).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);
|
2013-08-29 09:15:13 +00:00
|
|
|
return (profile->end_time() - i::Time::UnixEpoch()).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-04-02 08:16:53 +00:00
|
|
|
int CpuProfiler::GetProfileCount() {
|
|
|
|
return reinterpret_cast<i::CpuProfiler*>(this)->GetProfilesCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-28 08:00:16 +00:00
|
|
|
const CpuProfile* CpuProfiler::GetCpuProfile(int index) {
|
|
|
|
return reinterpret_cast<const CpuProfile*>(
|
2013-07-06 09:12:09 +00:00
|
|
|
reinterpret_cast<i::CpuProfiler*>(this)->GetProfile(index));
|
2013-04-02 08:16:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CpuProfiler::StartCpuProfiling(Handle<String> title, bool record_samples) {
|
|
|
|
reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling(
|
|
|
|
*Utils::OpenHandle(*title), record_samples);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-28 08:00:16 +00:00
|
|
|
const CpuProfile* CpuProfiler::StopCpuProfiling(Handle<String> title) {
|
|
|
|
return reinterpret_cast<const CpuProfile*>(
|
|
|
|
reinterpret_cast<i::CpuProfiler*>(this)->StopProfiling(
|
|
|
|
*Utils::OpenHandle(*title)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-02 08:16:53 +00:00
|
|
|
void CpuProfiler::DeleteAllCpuProfiles() {
|
|
|
|
reinterpret_cast<i::CpuProfiler*>(this)->DeleteAllProfiles();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
IsDeadCheck(isolate, "v8::HeapGraphEdge::GetType");
|
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();
|
|
|
|
IsDeadCheck(isolate, "v8::HeapGraphEdge::GetName");
|
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:
|
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-07-17 13:12:48 +00:00
|
|
|
case i::HeapGraphEdge::kWeak:
|
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();
|
|
|
|
}
|
2011-03-25 14:09:14 +00:00
|
|
|
return v8::Undefined();
|
2010-06-15 11:44:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const HeapGraphNode* HeapGraphEdge::GetFromNode() const {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
IsDeadCheck(isolate, "v8::HeapGraphEdge::GetFromNode");
|
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 {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
IsDeadCheck(isolate, "v8::HeapGraphEdge::GetToNode");
|
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 {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
IsDeadCheck(isolate, "v8::HeapGraphNode::GetType");
|
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();
|
|
|
|
IsDeadCheck(isolate, "v8::HeapGraphNode::GetName");
|
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 {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
IsDeadCheck(isolate, "v8::HeapGraphNode::GetId");
|
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 {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
IsDeadCheck(isolate, "v8::HeapGraphNode::GetSelfSize");
|
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 {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
IsDeadCheck(isolate, "v8::HeapSnapshot::GetChildrenCount");
|
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 {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
IsDeadCheck(isolate, "v8::HeapSnapshot::GetChild");
|
2010-06-15 11:44:07 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-26 14:38:29 +00:00
|
|
|
v8::Handle<v8::Value> HeapGraphNode::GetHeapValue() const {
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
IsDeadCheck(isolate, "v8::HeapGraphNode::GetHeapValue");
|
|
|
|
i::Handle<i::HeapObject> object = ToInternal(this)->GetHeapObject();
|
2013-06-13 09:27:09 +00:00
|
|
|
return !object.is_null() ?
|
|
|
|
ToApiHandle<Value>(object) :
|
|
|
|
ToApiHandle<Value>(isolate->factory()->undefined_value());
|
2011-09-26 14:38:29 +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();
|
|
|
|
IsDeadCheck(isolate, "v8::HeapSnapshot::Delete");
|
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 {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
IsDeadCheck(isolate, "v8::HeapSnapshot::GetUid");
|
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();
|
|
|
|
IsDeadCheck(isolate, "v8::HeapSnapshot::GetTitle");
|
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 {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
IsDeadCheck(isolate, "v8::HeapSnapshot::GetHead");
|
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 {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
IsDeadCheck(isolate, "v8::HeapSnapshot::GetNodeById");
|
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 {
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
IsDeadCheck(isolate, "v8::HeapSnapshot::GetNodesCount");
|
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 {
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
IsDeadCheck(isolate, "v8::HeapSnapshot::GetNode");
|
|
|
|
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 {
|
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
IsDeadCheck(isolate, "v8::HeapSnapshot::GetMaxSnapshotJSObjectId");
|
|
|
|
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 {
|
2011-03-18 20:35:07 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
IsDeadCheck(isolate, "v8::HeapSnapshot::Serialize");
|
2010-09-14 11:49:06 +00:00
|
|
|
ApiCheck(format == kJSON,
|
|
|
|
"v8::HeapSnapshot::Serialize",
|
|
|
|
"Unknown serialization format");
|
|
|
|
ApiCheck(stream->GetOutputEncoding() == OutputStream::kAscii,
|
|
|
|
"v8::HeapSnapshot::Serialize",
|
|
|
|
"Unsupported output encoding");
|
|
|
|
ApiCheck(stream->GetChunkSize() > 0,
|
|
|
|
"v8::HeapSnapshot::Serialize",
|
|
|
|
"Invalid stream chunk size");
|
|
|
|
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-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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HeapProfiler::StartTrackingHeapObjects() {
|
|
|
|
reinterpret_cast<i::HeapProfiler*>(this)->StartHeapObjectsTracking();
|
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) {
|
2009-01-23 17:22:23 +00:00
|
|
|
v8::ImplementationUtilities::HandleScopeData* current =
|
2011-05-05 18:55:31 +00:00
|
|
|
isolate_->handle_scope_data();
|
2008-07-03 15:10:15 +00:00
|
|
|
handle_scope_data_ = *current;
|
2013-04-16 12:30:51 +00:00
|
|
|
OS::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) {
|
2013-04-16 12:30:51 +00:00
|
|
|
OS::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
|
|
|
}
|
|
|
|
|
|
|
|
if (!saved_contexts_.is_empty()) {
|
|
|
|
Object** start = reinterpret_cast<Object**>(&saved_contexts_.first());
|
|
|
|
v->VisitPointers(start, start + saved_contexts_.length());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HandleScopeImplementer::Iterate(ObjectVisitor* v) {
|
2009-01-23 17:22:23 +00:00
|
|
|
v8::ImplementationUtilities::HandleScopeData* current =
|
2011-05-05 18:55:31 +00:00
|
|
|
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-07-08 15:28:25 +00:00
|
|
|
#ifdef ENABLE_EXTRA_CHECKS
|
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);
|
|
|
|
return getter(property, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
return callback(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|