*/
void SetRetainedObjectInfo(UniqueId id, RetainedObjectInfo* info);
- /**
- * Starts recording JS allocations immediately as they arrive and tracking of
- * heap objects population statistics.
- */
- V8_DEPRECATED("Use StartTrackingHeapObjects instead",
- void StartRecordingHeapAllocations());
-
- /**
- * Stops recording JS allocations and tracking of heap objects population
- * statistics, cleans all collected heap objects population statistics data.
- */
- V8_DEPRECATED("Use StopTrackingHeapObjects instead",
- void StopRecordingHeapAllocations());
-
-
private:
HeapProfiler();
~HeapProfiler();
};
-// TODO(dcarney): Remove this class.
-template<typename T,
- typename P,
- typename M = NonCopyablePersistentTraits<T> >
-class WeakReferenceCallbacks {
- public:
- typedef void (*Revivable)(Isolate* isolate,
- Persistent<T, M>* object,
- P* parameter);
-};
-
-
/**
* An object reference that is independent of any handle scope. Where
* a Local handle only lives as long as the HandleScope in which it was
if (M::kResetInDestructor) this->Reset();
}
- V8_DEPRECATED("Use Reset instead",
- V8_INLINE void Dispose()) { this->Reset(); }
-
// TODO(dcarney): this is pretty useless, fix or remove
template <class S>
V8_INLINE static Persistent<T>& Cast(Persistent<S>& that) { // NOLINT
return Persistent<S>::Cast(*this);
}
- template<typename S, typename P>
- V8_DEPRECATED(
- "Use SetWeak instead",
- V8_INLINE void MakeWeak(
- P* parameter,
- typename WeakReferenceCallbacks<S, P>::Revivable callback));
-
- template<typename P>
- V8_DEPRECATED(
- "Use SetWeak instead",
- V8_INLINE void MakeWeak(
- P* parameter,
- typename WeakReferenceCallbacks<T, P>::Revivable callback));
-
// This will be removed.
V8_INLINE T* ClearAndLeak();
- V8_DEPRECATED("This will be removed",
- V8_INLINE void Clear()) { this->val_ = 0; }
-
// TODO(dcarney): remove
#ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR
~HandleScope();
- template <class T>
- V8_DEPRECATED("Use EscapableHandleScope::Escape instead",
- Local<T> Close(Handle<T> value));
-
/**
* Counts the number of allocated handles.
*/
}
};
- void Leave();
-
internal::Isolate* isolate_;
internal::Object** prev_next_;
internal::Object** prev_limit_;
- // TODO(dcarney): remove this field
- // Allow for the active closing of HandleScopes which allows to pass a handle
- // from the HandleScope being closed to the next top most HandleScope.
- bool is_closed_;
- internal::Object** RawClose(internal::Object** value);
-
friend class ImplementationUtilities;
friend class EscapableHandleScope;
template<class F> friend class Handle;
*/
Local<Value> Run();
- /**
- * Returns the script id value.
- */
- V8_DEPRECATED("Use GetId instead", Local<Value> Id());
-
/**
* Returns the script id.
*/
// TODO(1245381): Print to a string instead of on a FILE.
static void PrintCurrentStackTrace(Isolate* isolate, FILE* out);
- V8_DEPRECATED("Will be removed",
- static void PrintCurrentStackTrace(FILE* out));
static const int kNoLineNumberInfo = 0;
static const int kNoColumnInfo = 0;
Isolate* isolate,
int frame_limit,
StackTraceOptions options = kOverview);
- V8_DEPRECATED("Will be removed",
- static Local<StackTrace> CurrentStackTrace(
- int frame_limit, StackTraceOptions options = kOverview));
};
public:
bool Value() const;
V8_INLINE static Handle<Boolean> New(Isolate* isolate, bool value);
- V8_DEPRECATED("Will be removed",
- V8_INLINE static Handle<Boolean> New(bool value));
};
V8_INLINE static String* Cast(v8::Value* obj);
- /**
- * Allocates a new string from either UTF-8 encoded or ASCII data.
- * The second parameter 'length' gives the buffer length. If omitted,
- * the function calls 'strlen' to determine the buffer length.
- */
- V8_DEPRECATED(
- "Use NewFromUtf8 instead",
- V8_INLINE static Local<String> New(const char* data, int length = -1));
-
- /** Allocates a new string from 16-bit character codes.*/
- V8_DEPRECATED(
- "Use NewFromTwoByte instead",
- V8_INLINE static Local<String> New(
- const uint16_t* data, int length = -1));
-
- /**
- * Creates an internalized string (historically called a "symbol",
- * not to be confused with ES6 symbols). Returns one if it exists already.
- */
- V8_DEPRECATED(
- "Use NewFromUtf8 instead",
- V8_INLINE static Local<String> NewSymbol(
- const char* data, int length = -1));
-
enum NewStringType {
kNormalString, kInternalizedString, kUndetectableString
};
*/
static Local<String> NewExternal(Isolate* isolate,
ExternalStringResource* resource);
- V8_DEPRECATED("Will be removed", static Local<String> NewExternal(
- ExternalStringResource* resource));
/**
* Associate an external string resource with this string by transforming it
*/
static Local<String> NewExternal(Isolate* isolate,
ExternalAsciiStringResource* resource);
- V8_DEPRECATED("Will be removed", static Local<String> NewExternal(
- ExternalAsciiStringResource* resource));
/**
* Associate an external string resource with this string by transforming it
*/
bool CanMakeExternal();
- /** Creates an undetectable string from the supplied ASCII or UTF-8 data.*/
- V8_DEPRECATED(
- "Use NewFromUtf8 instead",
- V8_INLINE static Local<String> NewUndetectable(const char* data,
- int length = -1));
-
- /** Creates an undetectable string from the supplied 16-bit character codes.*/
- V8_DEPRECATED(
- "Use NewFromTwoByte instead",
- V8_INLINE static Local<String> NewUndetectable(const uint16_t* data,
- int length = -1));
-
/**
* Converts an object to a UTF-8-encoded character array. Useful if
* you want to print the object. If conversion to a string fails
void operator=(const Utf8Value&);
};
- /**
- * Converts an object to an ASCII string.
- * Useful if you want to print the object.
- * If conversion to a string fails (eg. due to an exception in the toString()
- * method of the object) then the length() method returns 0 and the * operator
- * returns NULL.
- */
- class V8_EXPORT AsciiValue {
- public:
- V8_DEPRECATED("Use Utf8Value instead",
- explicit AsciiValue(Handle<v8::Value> obj));
- ~AsciiValue();
- char* operator*() { return str_; }
- const char* operator*() const { return str_; }
- int length() const { return length_; }
- private:
- char* str_;
- int length_;
-
- // Disallow copying and assigning.
- AsciiValue(const AsciiValue&);
- void operator=(const AsciiValue&);
- };
-
/**
* Converts an object to a two-byte string.
* If conversion to a string fails (eg. due to an exception in the toString()
* is negative the returned array will have length 0.
*/
static Local<Array> New(Isolate* isolate, int length = 0);
- V8_DEPRECATED("Will be removed", static Local<Array> New(int length = 0));
V8_INLINE static Array* Cast(Value* obj);
private:
*/
bool IsBuiltin() const;
- /**
- * Returns scriptId object.
- */
- V8_DEPRECATED("Use ScriptId instead", Handle<Value> GetScriptId() const);
-
/**
* Returns scriptId.
*/
* unless the object is externalized.
*/
static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length);
- V8_DEPRECATED("Will be removed",
- static Local<ArrayBuffer> New(size_t byte_length));
/**
* Create a new ArrayBuffer over an existing memory block.
*/
static Local<ArrayBuffer> New(Isolate* isolate, void* data,
size_t byte_length);
- V8_DEPRECATED("Will be removed",
- static Local<ArrayBuffer> New(void* data, size_t byte_length));
/**
* Returns true if ArrayBuffer is extrenalized, that is, does not
class V8_EXPORT Date : public Object {
public:
static Local<Value> New(Isolate* isolate, double time);
- V8_DEPRECATED("Will be removed", static Local<Value> New(double time));
-
- V8_DEPRECATED(
- "Use ValueOf instead",
- double NumberValue() const) { return ValueOf(); }
/**
* A specialization of Value::NumberValue that is more efficient
* negatively impact the performance of date operations.
*/
static void DateTimeConfigurationChangeNotification(Isolate* isolate);
- V8_DEPRECATED("Will be removed",
- static void DateTimeConfigurationChangeNotification());
private:
static void CheckCast(v8::Value* obj);
class V8_EXPORT NumberObject : public Object {
public:
static Local<Value> New(Isolate* isolate, double value);
- V8_DEPRECATED("Will be removed", static Local<Value> New(double value));
-
- V8_DEPRECATED(
- "Use ValueOf instead",
- double NumberValue() const) { return ValueOf(); }
- /**
- * Returns the Number held by the object.
- */
double ValueOf() const;
V8_INLINE static NumberObject* Cast(v8::Value* obj);
public:
static Local<Value> New(bool value);
- V8_DEPRECATED(
- "Use ValueOf instead",
- bool BooleanValue() const) { return ValueOf(); }
-
- /**
- * Returns the Boolean held by the object.
- */
bool ValueOf() const;
V8_INLINE static BooleanObject* Cast(v8::Value* obj);
public:
static Local<Value> New(Handle<String> value);
- V8_DEPRECATED(
- "Use ValueOf instead",
- Local<String> StringValue() const) { return ValueOf(); }
-
- /**
- * Returns the String held by the object.
- */
Local<String> ValueOf() const;
V8_INLINE static StringObject* Cast(v8::Value* obj);
public:
static Local<Value> New(Isolate* isolate, Handle<Symbol> value);
- V8_DEPRECATED(
- "Use ValueOf instead",
- Local<Symbol> SymbolValue() const) { return ValueOf(); }
-
- /**
- * Returns the Symbol held by the object.
- */
Local<Symbol> ValueOf() const;
V8_INLINE static SymbolObject* Cast(v8::Value* obj);
class V8_EXPORT External : public Value {
public:
static Local<External> New(Isolate* isolate, void* value);
- V8_DEPRECATED("Will be removed", static Local<External> New(void *value));
V8_INLINE static External* Cast(Value* obj);
void* Value() const;
private:
void Set(Handle<String> name, Handle<Data> value,
PropertyAttribute attributes = None);
V8_INLINE void Set(Isolate* isolate, const char* name, Handle<Data> value);
- V8_DEPRECATED("Will be removed",
- V8_INLINE void Set(const char* name, Handle<Data> value));
void SetAccessorProperty(
Local<String> name,
Handle<FunctionTemplate>(),
int argc = 0,
Handle<FunctionTemplate> argv[] = 0);
- V8_DEPRECATED("Will be removed",
- static Local<Signature> New(Handle<FunctionTemplate> receiver =
- Handle<FunctionTemplate>(),
- int argc = 0,
- Handle<FunctionTemplate> argv[] =
- 0));
private:
Signature();
static Local<AccessorSignature> New(Isolate* isolate,
Handle<FunctionTemplate> receiver =
Handle<FunctionTemplate>());
- V8_DEPRECATED("Will be removed", static Local<AccessorSignature> New(
- Handle<FunctionTemplate> receiver =
- Handle<FunctionTemplate>()));
private:
AccessorSignature();
virtual ~Extension() { }
virtual v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate(
v8::Isolate* isolate, v8::Handle<v8::String> name) {
-#if defined(V8_DEPRECATION_WARNINGS)
- return v8::Handle<v8::FunctionTemplate>();
-#else
- return GetNativeFunction(name);
-#endif
- }
-
- V8_DEPRECATED("Will be removed",
- virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
- v8::Handle<v8::String> name)) {
return v8::Handle<v8::FunctionTemplate>();
}
V8_INLINE Handle<Boolean> True(Isolate* isolate);
V8_INLINE Handle<Boolean> False(Isolate* isolate);
-V8_DEPRECATED("Will be removed", Handle<Primitive> V8_EXPORT Undefined());
-V8_DEPRECATED("Will be removed", Handle<Primitive> V8_EXPORT Null());
-V8_DEPRECATED("Will be removed", Handle<Boolean> V8_EXPORT True());
-V8_DEPRECATED("Will be removed", Handle<Boolean> V8_EXPORT False());
-
/**
* A set of constraints that specifies the limits of the runtime's memory use.
*/
void ConfigureDefaults(uint64_t physical_memory,
uint32_t number_of_processors);
- V8_DEPRECATED("Will be removed",
- void ConfigureDefaults(uint64_t physical_memory));
int max_young_space_size() const { return max_young_space_size_; }
void set_max_young_space_size(int value) { max_young_space_size_ = value; }
typedef void (*MessageCallback)(Handle<Message> message, Handle<Value> error);
-V8_DEPRECATED(
- "Use Isolate::ThrowException instead",
- Handle<Value> V8_EXPORT ThrowException(Handle<Value> exception));
-
/**
* Create new error objects by calling the corresponding error object
* constructor with the message.
*/
void Dispose();
- V8_DEPRECATED("Use SetData(0, data) instead.",
- V8_INLINE void SetData(void* data));
- V8_DEPRECATED("Use GetData(0) instead.", V8_INLINE void* GetData());
-
/**
* Associate embedder-specific data with the isolate. |slot| has to be
* between 0 and GetNumberOfDataSlots() - 1.
static void SetJitCodeEventHandler(JitCodeEventOptions options,
JitCodeEventHandler event_handler);
- V8_DEPRECATED(
- "Use Isolate::AdjustAmountOfExternalAllocatedMemory instead",
- static int64_t AdjustAmountOfExternalAllocatedMemory(
- int64_t change_in_bytes));
-
/**
* Forcefully terminate the current thread of JavaScript execution
* in the given isolate. If no isolate is provided, the default
internal::Object** handle);
static internal::Object** CopyPersistent(internal::Object** handle);
static void DisposeGlobal(internal::Object** global_handle);
- typedef WeakReferenceCallbacks<Value, void>::Revivable RevivableCallback;
typedef WeakCallbackData<Value, void>::Callback WeakCallback;
static void MakeWeak(internal::Object** global_handle,
void* data,
- WeakCallback weak_callback,
- RevivableCallback weak_reference_callback);
+ WeakCallback weak_callback);
static void ClearWeak(internal::Object** global_handle);
static void Eternalize(Isolate* isolate,
Value* handle,
Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(),
Handle<Value> global_object = Handle<Value>());
- V8_DEPRECATED("Use Isolate::GetEnteredContext instead",
- static Local<Context> GetEntered());
-
- V8_DEPRECATED("Use Isolate::GetCurrentContext instead",
- static Local<Context> GetCurrent());
-
- V8_DEPRECATED("Use Isolate::GetCallingContext instead",
- static Local<Context> GetCalling());
-
/**
* Sets the security token for the context. To access an object in
* another context, the security tokens must match.
/** Returns true if the context has experienced an out of memory situation. */
bool HasOutOfMemoryException();
- V8_DEPRECATED("Use Isolate::InContext instead",
- static bool InContext());
-
/** Returns an isolate associated with a current context. */
v8::Isolate* GetIsolate();
explicit V8_INLINE Scope(Handle<Context> context) : context_(context) {
context_->Enter();
}
- V8_DEPRECATED(
- "Use Handle version instead",
- V8_INLINE Scope(Isolate* isolate, Persistent<Context>& context)) // NOLINT
- : context_(Handle<Context>::New(isolate, context)) {
- context_->Enter();
- }
V8_INLINE ~Scope() { context_->Exit(); }
private:
typedef typename WeakCallbackData<Value, void>::Callback Callback;
V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_),
parameter,
- reinterpret_cast<Callback>(callback),
- NULL);
+ reinterpret_cast<Callback>(callback));
}
}
-template <class T, class M>
-template <typename S, typename P>
-void Persistent<T, M>::MakeWeak(
- P* parameters,
- typename WeakReferenceCallbacks<S, P>::Revivable callback) {
- TYPE_CHECK(S, T);
- typedef typename WeakReferenceCallbacks<Value, void>::Revivable Revivable;
- V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_),
- parameters,
- NULL,
- reinterpret_cast<Revivable>(callback));
-}
-
-
-template <class T, class M>
-template <typename P>
-void Persistent<T, M>::MakeWeak(
- P* parameters,
- typename WeakReferenceCallbacks<T, P>::Revivable callback) {
- MakeWeak<T, P>(parameters, callback);
-}
-
-
template <class T>
void PersistentBase<T>::ClearWeak() {
V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_));
}
-template <class T>
-Local<T> HandleScope::Close(Handle<T> value) {
- internal::Object** before = reinterpret_cast<internal::Object**>(*value);
- internal::Object** after = RawClose(before);
- return Local<T>(reinterpret_cast<T*>(after));
-}
-
Handle<Value> ScriptOrigin::ResourceName() const {
return resource_name_;
}
}
-Handle<Boolean> Boolean::New(bool value) {
- return Boolean::New(Isolate::GetCurrent(), value);
-}
-
-
void Template::Set(Isolate* isolate, const char* name, v8::Handle<Data> value) {
Set(v8::String::NewFromUtf8(isolate, name), value);
}
-void Template::Set(const char* name, v8::Handle<Data> value) {
- Set(Isolate::GetCurrent(), name, value);
-}
-
-
Local<Value> Object::GetInternalField(int index) {
#ifndef V8_ENABLE_CHECKS
typedef internal::Object O;
}
-Local<String> String::New(const char* data, int length) {
- return NewFromUtf8(Isolate::GetCurrent(), data, kNormalString, length);
-}
-
-
-Local<String> String::New(const uint16_t* data, int length) {
- return NewFromTwoByte(Isolate::GetCurrent(), data, kNormalString, length);
-}
-
-
-Local<String> String::NewSymbol(const char* data, int length) {
- return NewFromUtf8(Isolate::GetCurrent(), data, kInternalizedString, length);
-}
-
-
-Local<String> String::NewUndetectable(const char* data, int length) {
- return NewFromUtf8(Isolate::GetCurrent(), data, kUndetectableString, length);
-}
-
-
-Local<String> String::NewUndetectable(const uint16_t* data, int length) {
- return NewFromTwoByte(
- Isolate::GetCurrent(), data, kUndetectableString, length);
-}
-
-
String::ExternalStringResource* String::GetExternalStringResource() const {
typedef internal::Object O;
typedef internal::Internals I;
}
-void Isolate::SetData(void* data) {
- typedef internal::Internals I;
- I::SetEmbedderData(this, 0, data);
-}
-
-
-void* Isolate::GetData() {
- typedef internal::Internals I;
- return I::GetEmbedderData(this, 0);
-}
-
-
void Isolate::SetData(uint32_t slot, void* data) {
typedef internal::Internals I;
I::SetEmbedderData(this, slot, data);
info_(info) {
script_ = Handle<Script>::cast(
script->GetIsolate()->global_handles()->Create(script));
- GlobalHandles::MakeWeak(
- reinterpret_cast<Object**>(script_.location()),
- this, &HandleWeakScript);
+ GlobalHandles::MakeWeak(reinterpret_cast<Object**>(script_.location()),
+ this,
+ &HandleWeakScript);
}
AllocationTracker::UnresolvedLocation::~UnresolvedLocation() {
if (!script_.is_null()) {
- script_->GetIsolate()->global_handles()->Destroy(
- reinterpret_cast<Object**>(script_.location()));
+ GlobalHandles::Destroy(reinterpret_cast<Object**>(script_.location()));
}
}
void AllocationTracker::UnresolvedLocation::HandleWeakScript(
- v8::Isolate* isolate,
- v8::Persistent<v8::Value>* obj,
- void* data) {
- UnresolvedLocation* location = reinterpret_cast<UnresolvedLocation*>(data);
- location->script_ = Handle<Script>::null();
- obj->Reset();
+ const v8::WeakCallbackData<v8::Value, void>& data) {
+ UnresolvedLocation* loc =
+ reinterpret_cast<UnresolvedLocation*>(data.GetParameter());
+ GlobalHandles::Destroy(reinterpret_cast<Object**>(loc->script_.location()));
+ loc->script_ = Handle<Script>::null();
}
void Resolve();
private:
- static void HandleWeakScript(v8::Isolate* isolate,
- v8::Persistent<v8::Value>* obj,
- void* data);
+ static void HandleWeakScript(
+ const v8::WeakCallbackData<v8::Value, void>& data);
+
Handle<Script> script_;
int start_position_;
FunctionInfo* info_;
}
-v8::Handle<Value> ThrowException(v8::Handle<v8::Value> value) {
- return v8::Isolate::GetCurrent()->ThrowException(value);
-}
-
-
RegisteredExtension* RegisteredExtension::first_extension_ = NULL;
}
-v8::Handle<Primitive> Undefined() {
- i::Isolate* isolate = i::Isolate::Current();
- if (!EnsureInitializedForIsolate(isolate, "v8::Undefined()")) {
- return v8::Handle<v8::Primitive>();
- }
- return ToApiHandle<Primitive>(isolate->factory()->undefined_value());
-}
-
-
-v8::Handle<Primitive> Null() {
- i::Isolate* isolate = i::Isolate::Current();
- if (!EnsureInitializedForIsolate(isolate, "v8::Null()")) {
- return v8::Handle<v8::Primitive>();
- }
- return ToApiHandle<Primitive>(isolate->factory()->null_value());
-}
-
-
-v8::Handle<Boolean> True() {
- i::Isolate* isolate = i::Isolate::Current();
- if (!EnsureInitializedForIsolate(isolate, "v8::True()")) {
- return v8::Handle<Boolean>();
- }
- return ToApiHandle<Boolean>(isolate->factory()->true_value());
-}
-
-
-v8::Handle<Boolean> False() {
- i::Isolate* isolate = i::Isolate::Current();
- if (!EnsureInitializedForIsolate(isolate, "v8::False()")) {
- return v8::Handle<Boolean>();
- }
- return ToApiHandle<Boolean>(isolate->factory()->false_value());
-}
-
-
ResourceConstraints::ResourceConstraints()
: max_young_space_size_(0),
max_old_space_size_(0),
}
-void ResourceConstraints::ConfigureDefaults(uint64_t physical_memory) {
- ConfigureDefaults(physical_memory, i::CPU::NumberOfProcessorsOnline());
-}
-
-
bool SetResourceConstraints(Isolate* v8_isolate,
ResourceConstraints* constraints) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
void V8::MakeWeak(i::Object** object,
void* parameters,
- WeakCallback weak_callback,
- RevivableCallback weak_reference_callback) {
- i::GlobalHandles::MakeWeak(object,
- parameters,
- weak_callback,
- weak_reference_callback);
+ WeakCallback weak_callback) {
+ i::GlobalHandles::MakeWeak(object, parameters, weak_callback);
}
isolate_ = internal_isolate;
prev_next_ = current->next;
prev_limit_ = current->limit;
- is_closed_ = false;
current->level++;
}
HandleScope::~HandleScope() {
- if (!is_closed_) {
- Leave();
- }
-}
-
-
-void HandleScope::Leave() {
- return i::HandleScope::CloseScope(isolate_, prev_next_, prev_limit_);
+ i::HandleScope::CloseScope(isolate_, prev_next_, prev_limit_);
}
}
-i::Object** v8::HandleScope::RawClose(i::Object** value) {
- if (!ApiCheck(!is_closed_,
- "v8::HandleScope::Close()",
- "Local scope has already been closed")) {
- return 0;
- }
- LOG_API(isolate_, "CloseHandleScope");
-
- // Read the result before popping the handle block.
- i::Object* result = NULL;
- if (value != NULL) {
- result = *value;
- }
- is_closed_ = true;
- Leave();
-
- if (value == NULL) {
- return NULL;
- }
-
- // Allocate a new handle on the previous handle block.
- i::Handle<i::Object> handle(result, isolate_);
- return handle.location();
-}
-
-
// --- N e a n d e r ---
}
-Local<Signature> Signature::New(Handle<FunctionTemplate> receiver,
- int argc, Handle<FunctionTemplate> argv[]) {
- return New(Isolate::GetCurrent(), receiver, argc, argv);
-}
-
-
Local<AccessorSignature> AccessorSignature::New(
Isolate* isolate,
Handle<FunctionTemplate> receiver) {
}
-// While this is just a cast, it's lame not to use an Isolate parameter.
-Local<AccessorSignature> AccessorSignature::New(
- Handle<FunctionTemplate> receiver) {
- return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver));
-}
-
-
template<typename Operation>
static Local<Operation> NewDescriptor(
Isolate* isolate,
}
-Local<Value> Script::Id() {
- i::Handle<i::HeapObject> obj =
- i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this));
- i::Isolate* isolate = obj->GetIsolate();
- ON_BAILOUT(isolate, "v8::Script::Id()", return Local<Value>());
- LOG_API(isolate, "Script::Id");
- i::Object* raw_id = NULL;
- {
- i::HandleScope scope(isolate);
- i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this);
- i::Handle<i::Script> script(i::Script::cast(function_info->script()));
- i::Handle<i::Object> id(script->id(), isolate);
- raw_id = *id;
- }
- i::Handle<i::Object> id(raw_id, isolate);
- return Utils::ToLocal(id);
-}
-
-
int Script::GetId() {
i::Handle<i::HeapObject> obj =
i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this));
}
-void Message::PrintCurrentStackTrace(FILE* out) {
- PrintCurrentStackTrace(Isolate::GetCurrent(), out);
-}
-
-
// --- S t a c k T r a c e ---
Local<StackFrame> StackTrace::GetFrame(uint32_t index) const {
}
-Local<StackTrace> StackTrace::CurrentStackTrace(int frame_limit,
- StackTraceOptions options) {
- return CurrentStackTrace(Isolate::GetCurrent(), frame_limit, options);
-}
-
-
// --- S t a c k F r a m e ---
int StackFrame::GetLineNumber() const {
}
-Handle<Value> Function::GetScriptId() const {
- i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
- i::Isolate* isolate = func->GetIsolate();
- if (!func->shared()->script()->IsScript()) {
- return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
- }
- i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
- return Utils::ToLocal(i::Handle<i::Object>(script->id(), isolate));
-}
-
-
int Function::ScriptId() const {
i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
if (!func->shared()->script()->IsScript()) return v8::Script::kNoScriptId;
}
-bool Context::InContext() {
- return i::Isolate::Current()->context() != NULL;
-}
-
-
v8::Isolate* Context::GetIsolate() {
i::Handle<i::Context> env = Utils::OpenHandle(this);
return reinterpret_cast<Isolate*>(env->GetIsolate());
}
-v8::Local<v8::Context> Context::GetEntered() {
- i::Isolate* isolate = i::Isolate::Current();
- if (!EnsureInitializedForIsolate(isolate, "v8::Context::GetEntered()")) {
- return Local<Context>();
- }
- return reinterpret_cast<Isolate*>(isolate)->GetEnteredContext();
-}
-
-
-v8::Local<v8::Context> Context::GetCurrent() {
- i::Isolate* isolate = i::Isolate::Current();
- return reinterpret_cast<Isolate*>(isolate)->GetCurrentContext();
-}
-
-
-v8::Local<v8::Context> Context::GetCalling() {
- i::Isolate* isolate = i::Isolate::Current();
- return reinterpret_cast<Isolate*>(isolate)->GetCallingContext();
-}
-
-
v8::Local<v8::Object> Context::Global() {
i::Handle<i::Context> context = Utils::OpenHandle(this);
i::Isolate* isolate = context->GetIsolate();
}
-Local<External> v8::External::New(void* value) {
- return v8::External::New(Isolate::GetCurrent(), value);
-}
-
-
void* External::Value() const {
return ExternalValue(*Utils::OpenHandle(this));
}
}
-Local<String> v8::String::NewExternal(
- v8::String::ExternalStringResource* resource) {
- return NewExternal(Isolate::GetCurrent(), resource);
-}
-
-
bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) {
i::Handle<i::String> obj = Utils::OpenHandle(this);
i::Isolate* isolate = obj->GetIsolate();
}
-Local<String> v8::String::NewExternal(
- v8::String::ExternalAsciiStringResource* resource) {
- return NewExternal(Isolate::GetCurrent(), resource);
-}
-
-
bool v8::String::MakeExternal(
v8::String::ExternalAsciiStringResource* resource) {
i::Handle<i::String> obj = Utils::OpenHandle(this);
}
-Local<v8::Value> v8::NumberObject::New(double value) {
- return New(Isolate::GetCurrent(), value);
-}
-
-
double v8::NumberObject::ValueOf() const {
i::Isolate* isolate = i::Isolate::Current();
LOG_API(isolate, "NumberObject::NumberValue");
}
-Local<v8::Value> v8::Date::New(double time) {
- return New(Isolate::GetCurrent(), time);
-}
-
-
double v8::Date::ValueOf() const {
i::Isolate* isolate = i::Isolate::Current();
LOG_API(isolate, "Date::NumberValue");
}
-void v8::Date::DateTimeConfigurationChangeNotification() {
- DateTimeConfigurationChangeNotification(Isolate::GetCurrent());
-}
-
-
static i::Handle<i::String> RegExpFlagsToString(RegExp::Flags flags) {
i::Isolate* isolate = i::Isolate::Current();
uint8_t flags_buf[3];
}
-Local<v8::Array> v8::Array::New(int length) {
- return New(Isolate::GetCurrent(), length);
-}
-
-
uint32_t v8::Array::Length() const {
i::Handle<i::JSArray> obj = Utils::OpenHandle(this);
i::Object* length = obj->length();
}
-Local<ArrayBuffer> v8::ArrayBuffer::New(size_t byte_length) {
- return New(Isolate::GetCurrent(), byte_length);
-}
-
-
Local<ArrayBuffer> v8::ArrayBuffer::New(Isolate* isolate, void* data,
size_t byte_length) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
}
-Local<ArrayBuffer> v8::ArrayBuffer::New(void* data, size_t byte_length) {
- return New(Isolate::GetCurrent(), data, byte_length);
-}
-
-
Local<ArrayBuffer> v8::ArrayBufferView::Buffer() {
i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this);
ASSERT(obj->buffer()->IsJSArrayBuffer());
}
-int64_t V8::AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes) {
- i::Isolate* isolate = i::Isolate::UncheckedCurrent();
- if (isolate == NULL || !isolate->IsInitialized()) {
- return 0;
- }
- Isolate* isolate_ext = reinterpret_cast<Isolate*>(isolate);
- return isolate_ext->AdjustAmountOfExternalAllocatedMemory(change_in_bytes);
-}
-
-
HeapProfiler* Isolate::GetHeapProfiler() {
i::HeapProfiler* heap_profiler =
reinterpret_cast<i::Isolate*>(this)->heap_profiler();
}
-String::AsciiValue::AsciiValue(v8::Handle<v8::Value> obj)
- : str_(NULL), length_(0) {
- i::Isolate* isolate = i::Isolate::Current();
- if (obj.IsEmpty()) return;
- ENTER_V8(isolate);
- i::HandleScope scope(isolate);
- TryCatch try_catch;
- Handle<String> str = obj->ToString();
- if (str.IsEmpty()) return;
- length_ = str->Utf8Length();
- str_ = i::NewArray<char>(length_ + 1);
- str->WriteUtf8(str_);
- ASSERT(i::String::NonAsciiStart(str_, length_) >= length_);
-}
-
-
-String::AsciiValue::~AsciiValue() {
- i::DeleteArray(str_);
-}
-
-
String::Value::Value(v8::Handle<v8::Value> obj)
: str_(NULL), length_(0) {
i::Isolate* isolate = i::Isolate::Current();
}
-void HeapProfiler::StartRecordingHeapAllocations() {
- reinterpret_cast<i::HeapProfiler*>(this)->StartHeapObjectsTracking(true);
-}
-
-
-void HeapProfiler::StopRecordingHeapAllocations() {
- reinterpret_cast<i::HeapProfiler*>(this)->StopHeapObjectsTracking();
-}
-
-
v8::Testing::StressType internal::Testing::stress_type_ =
v8::Testing::kStressTypeOpt;
// Globalize the script object, make it weak and use the location of the
// global handle as the value in the hash map.
Handle<Script> script_ =
- Handle<Script>::cast(
- (global_handles->Create(*script)));
- global_handles->MakeWeak(reinterpret_cast<Object**>(script_.location()),
- this,
- ScriptCache::HandleWeakScript);
+ Handle<Script>::cast(global_handles->Create(*script));
+ GlobalHandles::MakeWeak(reinterpret_cast<Object**>(script_.location()),
+ this,
+ ScriptCache::HandleWeakScript);
entry->value = script_.location();
}
void ScriptCache::Clear() {
- GlobalHandles* global_handles = isolate_->global_handles();
// Iterate the script cache to get rid of all the weak handles.
for (HashMap::Entry* entry = Start(); entry != NULL; entry = Next(entry)) {
ASSERT(entry != NULL);
Object** location = reinterpret_cast<Object**>(entry->value);
ASSERT((*location)->IsScript());
- global_handles->ClearWeakness(location);
- global_handles->Destroy(location);
+ GlobalHandles::ClearWeakness(location);
+ GlobalHandles::Destroy(location);
}
// Clear the content of the hash map.
HashMap::Clear();
}
-void ScriptCache::HandleWeakScript(v8::Isolate* isolate,
- v8::Persistent<v8::Value>* obj,
- void* data) {
- ScriptCache* script_cache = reinterpret_cast<ScriptCache*>(data);
- // Find the location of the global handle.
- Script** location =
- reinterpret_cast<Script**>(Utils::OpenPersistent(*obj).location());
- ASSERT((*location)->IsScript());
+void ScriptCache::HandleWeakScript(
+ const v8::WeakCallbackData<v8::Value, void>& data) {
+ // Retrieve the script identifier.
+ Handle<Object> object = Utils::OpenHandle(*data.GetValue());
+ int id = Handle<Script>::cast(object)->id()->value();
+ void* key = reinterpret_cast<void*>(id);
+ uint32_t hash = Hash(id);
- // Remove the entry from the cache.
- int id = (*location)->id()->value();
- script_cache->Remove(reinterpret_cast<void*>(id), Hash(id));
+ // Remove the corresponding entry from the cache.
+ ScriptCache* script_cache =
+ reinterpret_cast<ScriptCache*>(data.GetParameter());
+ HashMap::Entry* entry = script_cache->Lookup(key, hash, false);
+ Object** location = reinterpret_cast<Object**>(entry->value);
+ script_cache->Remove(key, hash);
script_cache->collected_scripts_.Add(id);
// Clear the weak handle.
- obj->Reset();
+ GlobalHandles::Destroy(location);
}
}
-void Debug::HandleWeakDebugInfo(v8::Isolate* isolate,
- v8::Persistent<v8::Value>* obj,
- void* data) {
- Debug* debug = reinterpret_cast<Isolate*>(isolate)->debug();
- DebugInfoListNode* node = reinterpret_cast<DebugInfoListNode*>(data);
+void Debug::HandleWeakDebugInfo(
+ const v8::WeakCallbackData<v8::Value, void>& data) {
+ Debug* debug = reinterpret_cast<Isolate*>(data.GetIsolate())->debug();
+ DebugInfoListNode* node =
+ reinterpret_cast<DebugInfoListNode*>(data.GetParameter());
// We need to clear all breakpoints associated with the function to restore
// original code and avoid patching the code twice later because
// the function will live in the heap until next gc, and can be found by
it.ClearAllDebugBreak();
debug->RemoveDebugInfo(node->debug_info());
#ifdef DEBUG
- node = debug->debug_info_list_;
- while (node != NULL) {
- ASSERT(node != reinterpret_cast<DebugInfoListNode*>(data));
- node = node->next();
+ for (DebugInfoListNode* n = debug->debug_info_list_;
+ n != NULL;
+ n = n->next()) {
+ ASSERT(n != node);
}
#endif
}
DebugInfoListNode::DebugInfoListNode(DebugInfo* debug_info): next_(NULL) {
- GlobalHandles* global_handles = debug_info->GetIsolate()->global_handles();
// Globalize the request debug info object and make it weak.
- debug_info_ = Handle<DebugInfo>::cast(
- (global_handles->Create(debug_info)));
- global_handles->MakeWeak(reinterpret_cast<Object**>(debug_info_.location()),
- this,
- Debug::HandleWeakDebugInfo);
+ GlobalHandles* global_handles = debug_info->GetIsolate()->global_handles();
+ debug_info_ = Handle<DebugInfo>::cast(global_handles->Create(debug_info));
+ GlobalHandles::MakeWeak(reinterpret_cast<Object**>(debug_info_.location()),
+ this,
+ Debug::HandleWeakDebugInfo);
}
DebugInfoListNode::~DebugInfoListNode() {
- debug_info_->GetIsolate()->global_handles()->Destroy(
- reinterpret_cast<Object**>(debug_info_.location()));
+ GlobalHandles::Destroy(reinterpret_cast<Object**>(debug_info_.location()));
}
DestroyScriptCache();
// Clear debugger context global handle.
- isolate_->global_handles()->Destroy(
- reinterpret_cast<Object**>(debug_context_.location()));
+ GlobalHandles::Destroy(reinterpret_cast<Object**>(debug_context_.location()));
debug_context_ = Handle<Context>();
}
// Clear the global handles for the event listener and the event listener data
// object.
if (!event_listener_.is_null()) {
- global_handles->Destroy(
+ GlobalHandles::Destroy(
reinterpret_cast<Object**>(event_listener_.location()));
event_listener_ = Handle<Object>();
}
if (!event_listener_data_.is_null()) {
- global_handles->Destroy(
+ GlobalHandles::Destroy(
reinterpret_cast<Object**>(event_listener_data_.location()));
event_listener_data_ = Handle<Object>();
}
void Clear();
// Weak handle callback for scripts in the cache.
- static void HandleWeakScript(v8::Isolate* isolate,
- v8::Persistent<v8::Value>* obj,
- void* data);
+ static void HandleWeakScript(
+ const v8::WeakCallbackData<v8::Value, void>& data);
Isolate* isolate_;
// List used during GC to temporarily store id's of collected scripts.
static const int kEstimatedNofBreakPointsInFunction = 16;
// Passed to MakeWeak.
- static void HandleWeakDebugInfo(v8::Isolate* isolate,
- v8::Persistent<v8::Value>* obj,
- void* data);
+ static void HandleWeakDebugInfo(
+ const v8::WeakCallbackData<v8::Value, void>& data);
friend class Debugger;
friend Handle<FixedArray> GetDebuggedFunctions(); // In test-debug.cc
flags_ = IsInNewSpaceList::update(flags_, v);
}
- bool is_revivable_callback() {
- return IsRevivableCallback::decode(flags_);
- }
- void set_revivable_callback(bool v) {
- flags_ = IsRevivableCallback::update(flags_, v);
- }
-
bool IsNearDeath() const {
// Check for PENDING to ensure correct answer when processing callbacks.
return state() == PENDING || state() == NEAR_DEATH;
parameter_or_next_free_.next_free = value;
}
- void MakeWeak(void* parameter,
- WeakCallback weak_callback,
- RevivableCallback revivable_callback) {
- ASSERT((weak_callback == NULL) != (revivable_callback == NULL));
+ void MakeWeak(void* parameter, WeakCallback weak_callback) {
+ ASSERT(weak_callback != NULL);
ASSERT(state() != FREE);
set_state(WEAK);
set_parameter(parameter);
- if (weak_callback != NULL) {
- weak_callback_ = weak_callback;
- set_revivable_callback(false);
- } else {
- weak_callback_ =
- reinterpret_cast<WeakCallback>(revivable_callback);
- set_revivable_callback(true);
- }
+ weak_callback_ = weak_callback;
}
void ClearWeakness() {
// Leaving V8.
VMState<EXTERNAL> state(isolate);
HandleScope handle_scope(isolate);
- if (is_revivable_callback()) {
- RevivableCallback revivable =
- reinterpret_cast<RevivableCallback>(weak_callback_);
- revivable(reinterpret_cast<v8::Isolate*>(isolate),
- reinterpret_cast<Persistent<Value>*>(&object),
- par);
- } else {
- Handle<Object> handle(*object, isolate);
- v8::WeakCallbackData<v8::Value, void> data(
- reinterpret_cast<v8::Isolate*>(isolate),
- v8::Utils::ToLocal(handle),
- par);
- weak_callback_(data);
- }
+ Handle<Object> handle(*object, isolate);
+ v8::WeakCallbackData<v8::Value, void> data(
+ reinterpret_cast<v8::Isolate*>(isolate),
+ v8::Utils::ToLocal(handle),
+ par);
+ weak_callback_(data);
}
// Absence of explicit cleanup or revival of weak handle
// in most of the cases would lead to memory leak.
class IsIndependent: public BitField<bool, 4, 1> {};
class IsPartiallyDependent: public BitField<bool, 5, 1> {};
class IsInNewSpaceList: public BitField<bool, 6, 1> {};
- class IsRevivableCallback: public BitField<bool, 7, 1> {};
uint8_t flags_;
void GlobalHandles::MakeWeak(Object** location,
void* parameter,
- WeakCallback weak_callback,
- RevivableCallback revivable_callback) {
- Node::FromLocation(location)->MakeWeak(
- parameter, weak_callback, revivable_callback);
+ WeakCallback weak_callback) {
+ Node::FromLocation(location)->MakeWeak(parameter, weak_callback);
}
static void Destroy(Object** location);
typedef WeakCallbackData<v8::Value, void>::Callback WeakCallback;
- typedef WeakReferenceCallbacks<v8::Value, void>::Revivable RevivableCallback;
// Make the global handle weak and set the callback parameter for the
// handle. When the garbage collector recognizes that only weak global
// reason is that Smi::FromInt(0) does not change during garage collection.
static void MakeWeak(Object** location,
void* parameter,
- WeakCallback weak_callback,
- RevivableCallback revivable_callback);
-
- static inline void MakeWeak(Object** location,
- void* parameter,
- RevivableCallback revivable_callback) {
- MakeWeak(location, parameter, NULL, revivable_callback);
- }
+ WeakCallback weak_callback);
void RecordStats(HeapStats* stats);
// collector will call the weak callback on the global handle
// associated with the wrapper and get rid of both the wrapper and the
// handle.
-static void ClearWrapperCache(v8::Isolate* v8_isolate,
- Persistent<v8::Value>* handle,
- void*) {
- Handle<Object> cache = Utils::OpenPersistent(handle);
- JSValue* wrapper = JSValue::cast(*cache);
+static void ClearWrapperCache(
+ const v8::WeakCallbackData<v8::Value, void>& data) {
+ Object** location = reinterpret_cast<Object**>(data.GetParameter());
+ JSValue* wrapper = JSValue::cast(*location);
Foreign* foreign = Script::cast(wrapper->value())->wrapper();
- ASSERT(foreign->foreign_address() ==
- reinterpret_cast<Address>(cache.location()));
+ ASSERT_EQ(foreign->foreign_address(), reinterpret_cast<Address>(location));
foreign->set_foreign_address(0);
- Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate);
- isolate->global_handles()->Destroy(cache.location());
+ GlobalHandles::Destroy(location);
+ Isolate* isolate = reinterpret_cast<Isolate*>(data.GetIsolate());
isolate->counters()->script_wrappers()->Decrement();
}
// for future use. The cache will automatically be cleared by the
// garbage collector when it is not used anymore.
Handle<Object> handle = isolate->global_handles()->Create(*result);
- isolate->global_handles()->MakeWeak(handle.location(),
- NULL,
- &ClearWrapperCache);
+ GlobalHandles::MakeWeak(handle.location(),
+ reinterpret_cast<void*>(handle.location()),
+ &ClearWrapperCache);
script->wrapper()->set_foreign_address(
reinterpret_cast<Address>(handle.location()));
return result;
}
-void DateFormat::DeleteDateFormat(v8::Isolate* isolate,
- Persistent<v8::Value>* object,
- void* param) {
- // First delete the hidden C++ object.
- delete reinterpret_cast<icu::SimpleDateFormat*>(Handle<JSObject>::cast(
- v8::Utils::OpenPersistent(object))->GetInternalField(0));
-
- // Then dispose of the persistent handle to JS object.
- object->Reset();
+template<class T>
+void DeleteNativeObjectAt(const v8::WeakCallbackData<v8::Value, void>& data,
+ int index) {
+ v8::Local<v8::Object> obj = v8::Handle<v8::Object>::Cast(data.GetValue());
+ delete reinterpret_cast<T*>(obj->GetAlignedPointerFromInternalField(index));
+}
+
+
+static void DestroyGlobalHandle(
+ const v8::WeakCallbackData<v8::Value, void>& data) {
+ GlobalHandles::Destroy(reinterpret_cast<Object**>(data.GetParameter()));
+}
+
+
+void DateFormat::DeleteDateFormat(
+ const v8::WeakCallbackData<v8::Value, void>& data) {
+ DeleteNativeObjectAt<icu::SimpleDateFormat>(data, 0);
+ DestroyGlobalHandle(data);
}
}
-void NumberFormat::DeleteNumberFormat(v8::Isolate* isolate,
- Persistent<v8::Value>* object,
- void* param) {
- // First delete the hidden C++ object.
- delete reinterpret_cast<icu::DecimalFormat*>(Handle<JSObject>::cast(
- v8::Utils::OpenPersistent(object))->GetInternalField(0));
-
- // Then dispose of the persistent handle to JS object.
- object->Reset();
+void NumberFormat::DeleteNumberFormat(
+ const v8::WeakCallbackData<v8::Value, void>& data) {
+ DeleteNativeObjectAt<icu::DecimalFormat>(data, 0);
+ DestroyGlobalHandle(data);
}
}
-void Collator::DeleteCollator(v8::Isolate* isolate,
- Persistent<v8::Value>* object,
- void* param) {
- // First delete the hidden C++ object.
- delete reinterpret_cast<icu::Collator*>(Handle<JSObject>::cast(
- v8::Utils::OpenPersistent(object))->GetInternalField(0));
-
- // Then dispose of the persistent handle to JS object.
- object->Reset();
+void Collator::DeleteCollator(
+ const v8::WeakCallbackData<v8::Value, void>& data) {
+ DeleteNativeObjectAt<icu::Collator>(data, 0);
+ DestroyGlobalHandle(data);
}
}
-void BreakIterator::DeleteBreakIterator(v8::Isolate* isolate,
- Persistent<v8::Value>* object,
- void* param) {
- // First delete the hidden C++ object.
- delete reinterpret_cast<icu::BreakIterator*>(Handle<JSObject>::cast(
- v8::Utils::OpenPersistent(object))->GetInternalField(0));
-
- delete reinterpret_cast<icu::UnicodeString*>(Handle<JSObject>::cast(
- v8::Utils::OpenPersistent(object))->GetInternalField(1));
-
- // Then dispose of the persistent handle to JS object.
- object->Reset();
+void BreakIterator::DeleteBreakIterator(
+ const v8::WeakCallbackData<v8::Value, void>& data) {
+ DeleteNativeObjectAt<icu::BreakIterator>(data, 0);
+ DeleteNativeObjectAt<icu::UnicodeString>(data, 1);
+ DestroyGlobalHandle(data);
}
} } // namespace v8::internal
// Release memory we allocated for the DateFormat once the JS object that
// holds the pointer gets garbage collected.
- static void DeleteDateFormat(v8::Isolate* isolate,
- Persistent<v8::Value>* object,
- void* param);
+ static void DeleteDateFormat(
+ const v8::WeakCallbackData<v8::Value, void>& data);
+
private:
DateFormat();
};
// Release memory we allocated for the NumberFormat once the JS object that
// holds the pointer gets garbage collected.
- static void DeleteNumberFormat(v8::Isolate* isolate,
- Persistent<v8::Value>* object,
- void* param);
+ static void DeleteNumberFormat(
+ const v8::WeakCallbackData<v8::Value, void>& data);
+
private:
NumberFormat();
};
// Release memory we allocated for the Collator once the JS object that holds
// the pointer gets garbage collected.
- static void DeleteCollator(v8::Isolate* isolate,
- Persistent<v8::Value>* object,
- void* param);
+ static void DeleteCollator(
+ const v8::WeakCallbackData<v8::Value, void>& data);
+
private:
Collator();
};
// Release memory we allocated for the BreakIterator once the JS object that
// holds the pointer gets garbage collected.
- static void DeleteBreakIterator(v8::Isolate* isolate,
- Persistent<v8::Value>* object,
- void* param);
+ static void DeleteBreakIterator(
+ const v8::WeakCallbackData<v8::Value, void>& data);
private:
BreakIterator();
}
inline void clear_storage() {
- isolate_->global_handles()->Destroy(
- Handle<Object>::cast(storage_).location());
+ GlobalHandles::Destroy(Handle<Object>::cast(storage_).location());
}
inline void set_storage(FixedArray* storage) {
// Make object handle weak so we can delete the data format once GC kicks in.
Handle<Object> wrapper = isolate->global_handles()->Create(*local_object);
- GlobalHandles::MakeWeak(reinterpret_cast<Object**>(wrapper.location()),
- NULL,
+ GlobalHandles::MakeWeak(wrapper.location(),
+ reinterpret_cast<void*>(wrapper.location()),
DateFormat::DeleteDateFormat);
return *local_object;
}
NONE));
Handle<Object> wrapper = isolate->global_handles()->Create(*local_object);
- GlobalHandles::MakeWeak(reinterpret_cast<Object**>(wrapper.location()),
- NULL,
+ GlobalHandles::MakeWeak(wrapper.location(),
+ reinterpret_cast<void*>(wrapper.location()),
NumberFormat::DeleteNumberFormat);
return *local_object;
}
NONE));
Handle<Object> wrapper = isolate->global_handles()->Create(*local_object);
- GlobalHandles::MakeWeak(reinterpret_cast<Object**>(wrapper.location()),
- NULL,
+ GlobalHandles::MakeWeak(wrapper.location(),
+ reinterpret_cast<void*>(wrapper.location()),
Collator::DeleteCollator);
return *local_object;
}
// Make object handle weak so we can delete the break iterator once GC kicks
// in.
Handle<Object> wrapper = isolate->global_handles()->Create(*local_object);
- GlobalHandles::MakeWeak(reinterpret_cast<Object**>(wrapper.location()),
- NULL,
+ GlobalHandles::MakeWeak(wrapper.location(),
+ reinterpret_cast<void*>(wrapper.location()),
BreakIterator::DeleteBreakIterator);
return *local_object;
}
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdlib.h>
+#include <utility>
#include "v8.h"
CHECK((*h4)->IsHeapNumber());
CHECK_EQ(*h3, *h1);
- global_handles->Destroy(h1.location());
- global_handles->Destroy(h3.location());
+ GlobalHandles::Destroy(h1.location());
+ GlobalHandles::Destroy(h3.location());
CHECK_EQ(*h4, *h2);
- global_handles->Destroy(h2.location());
- global_handles->Destroy(h4.location());
+ GlobalHandles::Destroy(h2.location());
+ GlobalHandles::Destroy(h4.location());
}
static bool WeakPointerCleared = false;
-static void TestWeakGlobalHandleCallback(v8::Isolate* isolate,
- v8::Persistent<v8::Value>* handle,
- void* id) {
- if (1234 == reinterpret_cast<intptr_t>(id)) WeakPointerCleared = true;
- handle->Reset();
+static void TestWeakGlobalHandleCallback(
+ const v8::WeakCallbackData<v8::Value, void>& data) {
+ std::pair<v8::Persistent<v8::Value>*, int>* p =
+ reinterpret_cast<std::pair<v8::Persistent<v8::Value>*, int>*>(
+ data.GetParameter());
+ if (p->second == 1234) WeakPointerCleared = true;
+ p->first->Reset();
}
h2 = global_handles->Create(*u);
}
- global_handles->MakeWeak(h2.location(),
- reinterpret_cast<void*>(1234),
- &TestWeakGlobalHandleCallback);
+ std::pair<Handle<Object>*, int> handle_and_id(&h2, 1234);
+ GlobalHandles::MakeWeak(h2.location(),
+ reinterpret_cast<void*>(&handle_and_id),
+ &TestWeakGlobalHandleCallback);
// Scavenge treats weak pointers as normal roots.
heap->PerformScavenge();
CHECK(!global_handles->IsNearDeath(h2.location()));
CHECK(!global_handles->IsNearDeath(h1.location()));
- global_handles->Destroy(h1.location());
- global_handles->Destroy(h2.location());
+ GlobalHandles::Destroy(h1.location());
+ GlobalHandles::Destroy(h2.location());
}
heap->CollectGarbage(NEW_SPACE);
CHECK(!heap->InNewSpace(*h1) && !heap->InNewSpace(*h2));
- global_handles->MakeWeak(h2.location(),
- reinterpret_cast<void*>(1234),
- &TestWeakGlobalHandleCallback);
+ std::pair<Handle<Object>*, int> handle_and_id(&h2, 1234);
+ GlobalHandles::MakeWeak(h2.location(),
+ reinterpret_cast<void*>(&handle_and_id),
+ &TestWeakGlobalHandleCallback);
CHECK(!GlobalHandles::IsNearDeath(h1.location()));
CHECK(!GlobalHandles::IsNearDeath(h2.location()));
CHECK(WeakPointerCleared);
CHECK(!GlobalHandles::IsNearDeath(h1.location()));
- global_handles->Destroy(h1.location());
+ GlobalHandles::Destroy(h1.location());
}
h = global_handles->Create(*i);
}
- global_handles->MakeWeak(h.location(),
- reinterpret_cast<void*>(1234),
- &TestWeakGlobalHandleCallback);
+ std::pair<Handle<Object>*, int> handle_and_id(&h, 1234);
+ GlobalHandles::MakeWeak(h.location(),
+ reinterpret_cast<void*>(&handle_and_id),
+ &TestWeakGlobalHandleCallback);
// Scanvenge does not recognize weak reference.
heap->PerformScavenge();
#include <errno.h>
#endif
+#include <utility>
#include "v8.h"
static int NumberOfWeakCalls = 0;
-static void WeakPointerCallback(v8::Isolate* isolate,
- v8::Persistent<v8::Value>* handle,
- void* id) {
- ASSERT(id == reinterpret_cast<void*>(1234));
+static void WeakPointerCallback(
+ const v8::WeakCallbackData<v8::Value, void>& data) {
+ std::pair<v8::Persistent<v8::Value>*, int>* p =
+ reinterpret_cast<std::pair<v8::Persistent<v8::Value>*, int>*>(
+ data.GetParameter());
+ ASSERT_EQ(1234, p->second);
NumberOfWeakCalls++;
- handle->Reset();
+ p->first->Reset();
}
global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked());
Handle<Object> g1c1 =
global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked());
- global_handles->MakeWeak(g1s1.location(),
- reinterpret_cast<void*>(1234),
- &WeakPointerCallback);
- global_handles->MakeWeak(g1s2.location(),
- reinterpret_cast<void*>(1234),
- &WeakPointerCallback);
- global_handles->MakeWeak(g1c1.location(),
- reinterpret_cast<void*>(1234),
- &WeakPointerCallback);
+ std::pair<Handle<Object>*, int> g1s1_and_id(&g1s1, 1234);
+ GlobalHandles::MakeWeak(g1s1.location(),
+ reinterpret_cast<void*>(&g1s1_and_id),
+ &WeakPointerCallback);
+ std::pair<Handle<Object>*, int> g1s2_and_id(&g1s2, 1234);
+ GlobalHandles::MakeWeak(g1s2.location(),
+ reinterpret_cast<void*>(&g1s2_and_id),
+ &WeakPointerCallback);
+ std::pair<Handle<Object>*, int> g1c1_and_id(&g1c1, 1234);
+ GlobalHandles::MakeWeak(g1c1.location(),
+ reinterpret_cast<void*>(&g1c1_and_id),
+ &WeakPointerCallback);
Handle<Object> g2s1 =
global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked());
global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked());
Handle<Object> g2c1 =
global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked());
- global_handles->MakeWeak(g2s1.location(),
- reinterpret_cast<void*>(1234),
- &WeakPointerCallback);
- global_handles->MakeWeak(g2s2.location(),
- reinterpret_cast<void*>(1234),
- &WeakPointerCallback);
- global_handles->MakeWeak(g2c1.location(),
- reinterpret_cast<void*>(1234),
- &WeakPointerCallback);
+ std::pair<Handle<Object>*, int> g2s1_and_id(&g2s1, 1234);
+ GlobalHandles::MakeWeak(g2s1.location(),
+ reinterpret_cast<void*>(&g2s1_and_id),
+ &WeakPointerCallback);
+ std::pair<Handle<Object>*, int> g2s2_and_id(&g2s2, 1234);
+ GlobalHandles::MakeWeak(g2s2.location(),
+ reinterpret_cast<void*>(&g2s2_and_id),
+ &WeakPointerCallback);
+ std::pair<Handle<Object>*, int> g2c1_and_id(&g2c1, 1234);
+ GlobalHandles::MakeWeak(g2c1.location(),
+ reinterpret_cast<void*>(&g2c1_and_id),
+ &WeakPointerCallback);
Handle<Object> root = global_handles->Create(*g1s1); // make a root.
CHECK_EQ(0, NumberOfWeakCalls);
// Weaken the root.
- global_handles->MakeWeak(root.location(),
- reinterpret_cast<void*>(1234),
- &WeakPointerCallback);
+ std::pair<Handle<Object>*, int> root_and_id(&root, 1234);
+ GlobalHandles::MakeWeak(root.location(),
+ reinterpret_cast<void*>(&root_and_id),
+ &WeakPointerCallback);
// But make children strong roots---all the objects (except for children)
// should be collectable now.
global_handles->ClearWeakness(g1c1.location());
CHECK_EQ(5, NumberOfWeakCalls);
// And now make children weak again and collect them.
- global_handles->MakeWeak(g1c1.location(),
- reinterpret_cast<void*>(1234),
- &WeakPointerCallback);
- global_handles->MakeWeak(g2c1.location(),
- reinterpret_cast<void*>(1234),
- &WeakPointerCallback);
+ GlobalHandles::MakeWeak(g1c1.location(),
+ reinterpret_cast<void*>(&g1c1_and_id),
+ &WeakPointerCallback);
+ GlobalHandles::MakeWeak(g2c1.location(),
+ reinterpret_cast<void*>(&g2c1_and_id),
+ &WeakPointerCallback);
heap->CollectGarbage(OLD_POINTER_SPACE);
CHECK_EQ(7, NumberOfWeakCalls);
// (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 <utility>
+
#include "v8.h"
#include "global-handles.h"
}
static int NumberOfWeakCalls = 0;
-static void WeakPointerCallback(v8::Isolate* isolate,
- v8::Persistent<v8::Value>* handle,
- void* id) {
- ASSERT(id == reinterpret_cast<void*>(1234));
+static void WeakPointerCallback(
+ const v8::WeakCallbackData<v8::Value, void>& data) {
+ std::pair<v8::Persistent<v8::Value>*, int>* p =
+ reinterpret_cast<std::pair<v8::Persistent<v8::Value>*, int>*>(
+ data.GetParameter());
+ ASSERT_EQ(1234, p->second);
NumberOfWeakCalls++;
- handle->Reset();
+ p->first->Reset();
}
// Make the global reference to the key weak.
{
HandleScope scope(isolate);
- global_handles->MakeWeak(key.location(),
- reinterpret_cast<void*>(1234),
- &WeakPointerCallback);
+ std::pair<Handle<Object>*, int> handle_and_id(&key, 1234);
+ GlobalHandles::MakeWeak(key.location(),
+ reinterpret_cast<void*>(&handle_and_id),
+ &WeakPointerCallback);
}
CHECK(global_handles->IsWeak(key.location()));
// (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 <utility>
+
#include "v8.h"
#include "global-handles.h"
}
static int NumberOfWeakCalls = 0;
-static void WeakPointerCallback(v8::Isolate* isolate,
- v8::Persistent<v8::Value>* handle,
- void* id) {
- ASSERT(id == reinterpret_cast<void*>(1234));
+static void WeakPointerCallback(
+ const v8::WeakCallbackData<v8::Value, void>& data) {
+ std::pair<v8::Persistent<v8::Value>*, int>* p =
+ reinterpret_cast<std::pair<v8::Persistent<v8::Value>*, int>*>(
+ data.GetParameter());
+ ASSERT_EQ(1234, p->second);
NumberOfWeakCalls++;
- handle->Reset();
+ p->first->Reset();
}
// Make the global reference to the key weak.
{
HandleScope scope(isolate);
- global_handles->MakeWeak(key.location(),
- reinterpret_cast<void*>(1234),
- &WeakPointerCallback);
+ std::pair<Handle<Object>*, int> handle_and_id(&key, 1234);
+ GlobalHandles::MakeWeak(key.location(),
+ reinterpret_cast<void*>(&handle_and_id),
+ &WeakPointerCallback);
}
CHECK(global_handles->IsWeak(key.location()));