[api] Remove NeanderObject
We no longer need NeanderObject, the only user left was the message listener machanism which could be replace by direct uses of FixedArrays. BUG=chromium:630217 Review-Url: https://codereview.chromium.org/2195243003 Cr-Commit-Position: refs/heads/master@{#38249}
This commit is contained in:
parent
0e988e4737
commit
7e51190458
38
src/api.cc
38
src/api.cc
@ -1031,27 +1031,6 @@ void Context::SetAlignedPointerInEmbedderData(int index, void* value) {
|
||||
}
|
||||
|
||||
|
||||
// --- 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(v8::internal::Isolate* isolate, int size) {
|
||||
ENTER_V8(isolate);
|
||||
value_ = isolate->factory()->NewNeanderObject();
|
||||
i::Handle<i::FixedArray> elements = isolate->factory()->NewFixedArray(size);
|
||||
value_->set_elements(*elements);
|
||||
}
|
||||
|
||||
|
||||
int NeanderObject::size() {
|
||||
return i::FixedArray::cast(value_->elements())->length();
|
||||
}
|
||||
|
||||
|
||||
// --- T e m p l a t e ---
|
||||
|
||||
|
||||
@ -7940,11 +7919,13 @@ bool Isolate::AddMessageListener(MessageCallback that, Local<Value> data) {
|
||||
ENTER_V8(isolate);
|
||||
i::HandleScope scope(isolate);
|
||||
i::Handle<i::TemplateList> list = isolate->factory()->message_listeners();
|
||||
NeanderObject obj(isolate, 2);
|
||||
obj.set(0, *isolate->factory()->NewForeign(FUNCTION_ADDR(that)));
|
||||
obj.set(1, data.IsEmpty() ? isolate->heap()->undefined_value()
|
||||
: *Utils::OpenHandle(*data));
|
||||
list = i::TemplateList::Add(isolate, list, obj.value());
|
||||
i::Handle<i::FixedArray> listener = isolate->factory()->NewFixedArray(2);
|
||||
i::Handle<i::Foreign> foreign =
|
||||
isolate->factory()->NewForeign(FUNCTION_ADDR(that));
|
||||
listener->set(0, *foreign);
|
||||
listener->set(1, data.IsEmpty() ? isolate->heap()->undefined_value()
|
||||
: *Utils::OpenHandle(*data));
|
||||
list = i::TemplateList::Add(isolate, list, listener);
|
||||
isolate->heap()->SetMessageListeners(*list);
|
||||
return true;
|
||||
}
|
||||
@ -7958,9 +7939,8 @@ void Isolate::RemoveMessageListeners(MessageCallback that) {
|
||||
i::TemplateList* listeners = isolate->heap()->message_listeners();
|
||||
for (int i = 0; i < listeners->length(); i++) {
|
||||
if (listeners->get(i)->IsUndefined(isolate)) continue; // skip deleted ones
|
||||
|
||||
NeanderObject listener(i::JSObject::cast(listeners->get(i)));
|
||||
i::Foreign* callback_obj = i::Foreign::cast(listener.get(0));
|
||||
i::FixedArray* listener = i::FixedArray::cast(listeners->get(i));
|
||||
i::Foreign* callback_obj = i::Foreign::cast(listener->get(0));
|
||||
if (callback_obj->foreign_address() == FUNCTION_ADDR(that)) {
|
||||
listeners->set(i, isolate->heap()->undefined_value());
|
||||
}
|
||||
|
41
src/api.h
41
src/api.h
@ -26,44 +26,6 @@ class Consts {
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
// Utilities for working with neander-objects, primitive
|
||||
// env-independent JSObjects used by the api.
|
||||
class NeanderObject {
|
||||
public:
|
||||
explicit NeanderObject(v8::internal::Isolate* isolate, int size);
|
||||
explicit inline NeanderObject(v8::internal::Handle<v8::internal::Object> obj);
|
||||
explicit inline NeanderObject(v8::internal::Object* obj);
|
||||
inline v8::internal::Object* get(int index);
|
||||
inline void set(int index, v8::internal::Object* value);
|
||||
inline v8::internal::Handle<v8::internal::JSObject> value() { return value_; }
|
||||
int size();
|
||||
private:
|
||||
v8::internal::Handle<v8::internal::JSObject> value_;
|
||||
};
|
||||
|
||||
|
||||
NeanderObject::NeanderObject(v8::internal::Handle<v8::internal::Object> obj)
|
||||
: value_(v8::internal::Handle<v8::internal::JSObject>::cast(obj)) { }
|
||||
|
||||
|
||||
NeanderObject::NeanderObject(v8::internal::Object* obj)
|
||||
: value_(v8::internal::Handle<v8::internal::JSObject>(
|
||||
v8::internal::JSObject::cast(obj))) { }
|
||||
|
||||
|
||||
v8::internal::Object* NeanderObject::get(int offset) {
|
||||
DCHECK(value()->HasFastObjectElements());
|
||||
return v8::internal::FixedArray::cast(value()->elements())->get(offset);
|
||||
}
|
||||
|
||||
|
||||
void NeanderObject::set(int offset, v8::internal::Object* value) {
|
||||
DCHECK(value_->HasFastObjectElements());
|
||||
v8::internal::FixedArray::cast(value_->elements())->set(offset, value);
|
||||
}
|
||||
|
||||
|
||||
template <typename T> inline T ToCData(v8::internal::Object* obj) {
|
||||
STATIC_ASSERT(sizeof(T) == sizeof(v8::internal::Address));
|
||||
if (obj == v8::internal::Smi::FromInt(0)) return nullptr;
|
||||
@ -158,9 +120,6 @@ class Utils {
|
||||
}
|
||||
static void ReportOOMFailure(const char* location, bool is_heap_oom);
|
||||
|
||||
static Local<FunctionTemplate> ToFunctionTemplate(NeanderObject obj);
|
||||
static Local<ObjectTemplate> ToObjectTemplate(NeanderObject obj);
|
||||
|
||||
static inline Local<Context> ToLocal(
|
||||
v8::internal::Handle<v8::internal::Context> obj);
|
||||
static inline Local<Value> ToLocal(
|
||||
|
@ -134,11 +134,11 @@ void MessageHandler::ReportMessage(Isolate* isolate, MessageLocation* loc,
|
||||
for (int i = 0; i < global_length; i++) {
|
||||
HandleScope scope(isolate);
|
||||
if (global_listeners->get(i)->IsUndefined(isolate)) continue;
|
||||
v8::NeanderObject listener(JSObject::cast(global_listeners->get(i)));
|
||||
Handle<Foreign> callback_obj(Foreign::cast(listener.get(0)));
|
||||
FixedArray* listener = FixedArray::cast(global_listeners->get(i));
|
||||
Foreign* callback_obj = Foreign::cast(listener->get(0));
|
||||
v8::MessageCallback callback =
|
||||
FUNCTION_CAST<v8::MessageCallback>(callback_obj->foreign_address());
|
||||
Handle<Object> callback_data(listener.get(1), isolate);
|
||||
Handle<Object> callback_data(listener->get(1), isolate);
|
||||
{
|
||||
// Do not allow exceptions to propagate.
|
||||
v8::TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
|
||||
|
Loading…
Reference in New Issue
Block a user