Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: src/api.cc

Issue 2196533003: [api] Cleaning up: Replace NeanderArray with FixedArray implementation (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: mind the pointers Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/api.h ('k') | src/api-natives.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/api.h" 5 #include "src/api.h"
6 6
7 #include <string.h> // For memcpy, strlen. 7 #include <string.h> // For memcpy, strlen.
8 #ifdef V8_USE_ADDRESS_SANITIZER 8 #ifdef V8_USE_ADDRESS_SANITIZER
9 #include <sanitizer/asan_interface.h> 9 #include <sanitizer/asan_interface.h>
10 #endif // V8_USE_ADDRESS_SANITIZER 10 #endif // V8_USE_ADDRESS_SANITIZER
(...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 i::Handle<i::FixedArray> elements = isolate->factory()->NewFixedArray(size); 1045 i::Handle<i::FixedArray> elements = isolate->factory()->NewFixedArray(size);
1046 value_->set_elements(*elements); 1046 value_->set_elements(*elements);
1047 } 1047 }
1048 1048
1049 1049
1050 int NeanderObject::size() { 1050 int NeanderObject::size() {
1051 return i::FixedArray::cast(value_->elements())->length(); 1051 return i::FixedArray::cast(value_->elements())->length();
1052 } 1052 }
1053 1053
1054 1054
1055 NeanderArray::NeanderArray(v8::internal::Isolate* isolate) : obj_(isolate, 2) {
1056 obj_.set(0, i::Smi::FromInt(0));
1057 }
1058
1059
1060 int NeanderArray::length() {
1061 return i::Smi::cast(obj_.get(0))->value();
1062 }
1063
1064
1065 i::Object* NeanderArray::get(int offset) {
1066 DCHECK_LE(0, offset);
1067 DCHECK_LT(offset, length());
1068 return obj_.get(offset + 1);
1069 }
1070
1071
1072 // This method cannot easily return an error value, therefore it is necessary
1073 // to check for a dead VM with ON_BAILOUT before calling it. To remind you
1074 // about this there is no HandleScope in this method. When you add one to the
1075 // site calling this method you should check that you ensured the VM was not
1076 // dead first.
1077 void NeanderArray::add(i::Isolate* isolate, i::Handle<i::Object> value) {
1078 int length = this->length();
1079 int size = obj_.size();
1080 if (length == size - 1) {
1081 i::Factory* factory = isolate->factory();
1082 i::Handle<i::FixedArray> new_elms = factory->NewFixedArray(2 * size);
1083 for (int i = 0; i < length; i++)
1084 new_elms->set(i + 1, get(i));
1085 obj_.value()->set_elements(*new_elms);
1086 }
1087 obj_.set(length + 1, *value);
1088 obj_.set(0, i::Smi::FromInt(length + 1));
1089 }
1090
1091
1092 void NeanderArray::set(int index, i::Object* value) {
1093 if (index < 0 || index >= this->length()) return;
1094 obj_.set(index + 1, value);
1095 }
1096
1097
1098 // --- T e m p l a t e --- 1055 // --- T e m p l a t e ---
1099 1056
1100 1057
1101 static void InitializeTemplate(i::Handle<i::TemplateInfo> that, int type) { 1058 static void InitializeTemplate(i::Handle<i::TemplateInfo> that, int type) {
1102 that->set_number_of_properties(0); 1059 that->set_number_of_properties(0);
1103 that->set_tag(i::Smi::FromInt(type)); 1060 that->set_tag(i::Smi::FromInt(type));
1104 } 1061 }
1105 1062
1106 1063
1107 void Template::Set(v8::Local<Name> name, v8::Local<Data> value, 1064 void Template::Set(v8::Local<Name> name, v8::Local<Data> value,
(...skipping 6867 matching lines...) Expand 10 before | Expand all | Expand 10 after
7975 bool Isolate::IsDead() { 7932 bool Isolate::IsDead() {
7976 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); 7933 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
7977 return isolate->IsDead(); 7934 return isolate->IsDead();
7978 } 7935 }
7979 7936
7980 7937
7981 bool Isolate::AddMessageListener(MessageCallback that, Local<Value> data) { 7938 bool Isolate::AddMessageListener(MessageCallback that, Local<Value> data) {
7982 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); 7939 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
7983 ENTER_V8(isolate); 7940 ENTER_V8(isolate);
7984 i::HandleScope scope(isolate); 7941 i::HandleScope scope(isolate);
7985 NeanderArray listeners(isolate->factory()->message_listeners()); 7942 i::Handle<i::TemplateList> list = isolate->factory()->message_listeners();
7986 NeanderObject obj(isolate, 2); 7943 NeanderObject obj(isolate, 2);
7987 obj.set(0, *isolate->factory()->NewForeign(FUNCTION_ADDR(that))); 7944 obj.set(0, *isolate->factory()->NewForeign(FUNCTION_ADDR(that)));
7988 obj.set(1, data.IsEmpty() ? isolate->heap()->undefined_value() 7945 obj.set(1, data.IsEmpty() ? isolate->heap()->undefined_value()
7989 : *Utils::OpenHandle(*data)); 7946 : *Utils::OpenHandle(*data));
7990 listeners.add(isolate, obj.value()); 7947 list = i::TemplateList::Add(isolate, list, obj.value());
7948 isolate->heap()->SetMessageListeners(*list);
7991 return true; 7949 return true;
7992 } 7950 }
7993 7951
7994 7952
7995 void Isolate::RemoveMessageListeners(MessageCallback that) { 7953 void Isolate::RemoveMessageListeners(MessageCallback that) {
7996 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); 7954 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
7997 ENTER_V8(isolate); 7955 ENTER_V8(isolate);
7998 i::HandleScope scope(isolate); 7956 i::HandleScope scope(isolate);
7999 NeanderArray listeners(isolate->factory()->message_listeners()); 7957 i::DisallowHeapAllocation no_gc;
8000 for (int i = 0; i < listeners.length(); i++) { 7958 i::TemplateList* listeners = isolate->heap()->message_listeners();
8001 if (listeners.get(i)->IsUndefined(isolate)) continue; // skip deleted ones 7959 for (int i = 0; i < listeners->length(); i++) {
7960 if (listeners->get(i)->IsUndefined(isolate)) continue; // skip deleted ones
8002 7961
8003 NeanderObject listener(i::JSObject::cast(listeners.get(i))); 7962 NeanderObject listener(i::JSObject::cast(listeners->get(i)));
8004 i::Handle<i::Foreign> callback_obj(i::Foreign::cast(listener.get(0))); 7963 i::Foreign* callback_obj = i::Foreign::cast(listener.get(0));
8005 if (callback_obj->foreign_address() == FUNCTION_ADDR(that)) { 7964 if (callback_obj->foreign_address() == FUNCTION_ADDR(that)) {
8006 listeners.set(i, isolate->heap()->undefined_value()); 7965 listeners->set(i, isolate->heap()->undefined_value());
8007 } 7966 }
8008 } 7967 }
8009 } 7968 }
8010 7969
8011 7970
8012 void Isolate::SetFailedAccessCheckCallbackFunction( 7971 void Isolate::SetFailedAccessCheckCallbackFunction(
8013 FailedAccessCheckCallback callback) { 7972 FailedAccessCheckCallback callback) {
8014 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); 7973 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
8015 isolate->SetFailedAccessCheckCallback(callback); 7974 isolate->SetFailedAccessCheckCallback(callback);
8016 } 7975 }
(...skipping 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after
9038 Address callback_address = 8997 Address callback_address =
9039 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8998 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
9040 VMState<EXTERNAL> state(isolate); 8999 VMState<EXTERNAL> state(isolate);
9041 ExternalCallbackScope call_scope(isolate, callback_address); 9000 ExternalCallbackScope call_scope(isolate, callback_address);
9042 callback(info); 9001 callback(info);
9043 } 9002 }
9044 9003
9045 9004
9046 } // namespace internal 9005 } // namespace internal
9047 } // namespace v8 9006 } // namespace v8
OLDNEW
« no previous file with comments | « src/api.h ('k') | src/api-natives.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698