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

Side by Side Diff: src/api.cc

Issue 901923002: cleanup api-natives a bit (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 10 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 | « no previous file | src/api-natives.h » ('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 748 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 759
760 760
761 // --- T e m p l a t e --- 761 // --- T e m p l a t e ---
762 762
763 763
764 static void InitializeTemplate(i::Handle<i::TemplateInfo> that, int type) { 764 static void InitializeTemplate(i::Handle<i::TemplateInfo> that, int type) {
765 that->set_tag(i::Smi::FromInt(type)); 765 that->set_tag(i::Smi::FromInt(type));
766 } 766 }
767 767
768 768
769 static void TemplateSet(i::Isolate* isolate,
770 v8::Template* templ,
771 int length,
772 v8::Handle<v8::Data>* data) {
773 i::Handle<i::Object> list(Utils::OpenHandle(templ)->property_list(), isolate);
774 if (list->IsUndefined()) {
775 list = NeanderArray(isolate).value();
776 Utils::OpenHandle(templ)->set_property_list(*list);
777 }
778 NeanderArray array(list);
779 array.add(isolate, isolate->factory()->NewNumberFromInt(length));
780 for (int i = 0; i < length; i++) {
781 i::Handle<i::Object> value = data[i].IsEmpty() ?
782 i::Handle<i::Object>(isolate->factory()->undefined_value()) :
783 Utils::OpenHandle(*data[i]);
784 array.add(isolate, value);
785 }
786 }
787
788
789 void Template::Set(v8::Handle<Name> name, 769 void Template::Set(v8::Handle<Name> name,
790 v8::Handle<Data> value, 770 v8::Handle<Data> value,
791 v8::PropertyAttribute attribute) { 771 v8::PropertyAttribute attribute) {
792 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 772 auto templ = Utils::OpenHandle(this);
773 i::Isolate* isolate = templ->GetIsolate();
793 ENTER_V8(isolate); 774 ENTER_V8(isolate);
794 i::HandleScope scope(isolate); 775 i::HandleScope scope(isolate);
795 const int kSize = 3; 776 // TODO(dcarney): split api to allow values of v8::Value or v8::TemplateInfo.
796 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); 777 i::ApiNatives::AddDataProperty(isolate, templ, Utils::OpenHandle(*name),
797 v8::Handle<v8::Data> data[kSize] = { 778 Utils::OpenHandle(*value),
798 name, 779 static_cast<PropertyAttributes>(attribute));
799 value,
800 v8::Integer::New(v8_isolate, attribute)};
801 TemplateSet(isolate, this, kSize, data);
802 } 780 }
803 781
804 782
805 void Template::SetAccessorProperty( 783 void Template::SetAccessorProperty(
806 v8::Local<v8::Name> name, 784 v8::Local<v8::Name> name,
807 v8::Local<FunctionTemplate> getter, 785 v8::Local<FunctionTemplate> getter,
808 v8::Local<FunctionTemplate> setter, 786 v8::Local<FunctionTemplate> setter,
809 v8::PropertyAttribute attribute, 787 v8::PropertyAttribute attribute,
810 v8::AccessControl access_control) { 788 v8::AccessControl access_control) {
811 // TODO(verwaest): Remove |access_control|. 789 // TODO(verwaest): Remove |access_control|.
812 DCHECK_EQ(v8::DEFAULT, access_control); 790 DCHECK_EQ(v8::DEFAULT, access_control);
813 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 791 auto templ = Utils::OpenHandle(this);
792 auto isolate = templ->GetIsolate();
814 ENTER_V8(isolate); 793 ENTER_V8(isolate);
815 DCHECK(!name.IsEmpty()); 794 DCHECK(!name.IsEmpty());
816 DCHECK(!getter.IsEmpty() || !setter.IsEmpty()); 795 DCHECK(!getter.IsEmpty() || !setter.IsEmpty());
817 i::HandleScope scope(isolate); 796 i::HandleScope scope(isolate);
818 const int kSize = 5; 797 i::ApiNatives::AddAccessorProperty(
819 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); 798 isolate, templ, Utils::OpenHandle(*name),
820 v8::Handle<v8::Data> data[kSize] = { 799 Utils::OpenHandle(*getter, true), Utils::OpenHandle(*setter, true),
821 name, 800 static_cast<PropertyAttributes>(attribute));
822 getter,
823 setter,
824 v8::Integer::New(v8_isolate, attribute)};
825 TemplateSet(isolate, this, kSize, data);
826 } 801 }
827 802
828 803
829 // --- F u n c t i o n T e m p l a t e --- 804 // --- F u n c t i o n T e m p l a t e ---
830 static void InitializeFunctionTemplate( 805 static void InitializeFunctionTemplate(
831 i::Handle<i::FunctionTemplateInfo> info) { 806 i::Handle<i::FunctionTemplateInfo> info) {
832 info->set_tag(i::Smi::FromInt(Consts::FUNCTION_TEMPLATE)); 807 info->set_tag(i::Smi::FromInt(Consts::FUNCTION_TEMPLATE));
833 info->set_flag(0); 808 info->set_flag(0);
834 } 809 }
835 810
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 } 1112 }
1138 Local<FunctionTemplate> templ = 1113 Local<FunctionTemplate> templ =
1139 FunctionTemplate::New(reinterpret_cast<Isolate*>(isolate)); 1114 FunctionTemplate::New(reinterpret_cast<Isolate*>(isolate));
1140 i::Handle<i::FunctionTemplateInfo> constructor = Utils::OpenHandle(*templ); 1115 i::Handle<i::FunctionTemplateInfo> constructor = Utils::OpenHandle(*templ);
1141 constructor->set_instance_template(*Utils::OpenHandle(object_template)); 1116 constructor->set_instance_template(*Utils::OpenHandle(object_template));
1142 Utils::OpenHandle(object_template)->set_constructor(*constructor); 1117 Utils::OpenHandle(object_template)->set_constructor(*constructor);
1143 return constructor; 1118 return constructor;
1144 } 1119 }
1145 1120
1146 1121
1147 static inline void AddPropertyToTemplate(
1148 i::Handle<i::TemplateInfo> info,
1149 i::Handle<i::AccessorInfo> obj) {
1150 i::Isolate* isolate = info->GetIsolate();
1151 i::Handle<i::Object> list(info->property_accessors(), isolate);
1152 if (list->IsUndefined()) {
1153 list = NeanderArray(isolate).value();
1154 info->set_property_accessors(*list);
1155 }
1156 NeanderArray array(list);
1157 array.add(isolate, obj);
1158 }
1159
1160
1161 static inline i::Handle<i::TemplateInfo> GetTemplateInfo( 1122 static inline i::Handle<i::TemplateInfo> GetTemplateInfo(
1162 i::Isolate* isolate, 1123 i::Isolate* isolate,
1163 Template* template_obj) { 1124 Template* template_obj) {
1164 return Utils::OpenHandle(template_obj); 1125 return Utils::OpenHandle(template_obj);
1165 } 1126 }
1166 1127
1167 1128
1168 // TODO(dcarney): remove this with ObjectTemplate::SetAccessor 1129 // TODO(dcarney): remove this with ObjectTemplate::SetAccessor
1169 static inline i::Handle<i::TemplateInfo> GetTemplateInfo( 1130 static inline i::Handle<i::TemplateInfo> GetTemplateInfo(
1170 i::Isolate* isolate, 1131 i::Isolate* isolate,
1171 ObjectTemplate* object_template) { 1132 ObjectTemplate* object_template) {
1172 EnsureConstructor(isolate, object_template); 1133 EnsureConstructor(isolate, object_template);
1173 return Utils::OpenHandle(object_template); 1134 return Utils::OpenHandle(object_template);
1174 } 1135 }
1175 1136
1176 1137
1177 template<typename Getter, typename Setter, typename Data, typename Template> 1138 template<typename Getter, typename Setter, typename Data, typename Template>
1178 static bool TemplateSetAccessor( 1139 static bool TemplateSetAccessor(
1179 Template* template_obj, 1140 Template* template_obj,
1180 v8::Local<Name> name, 1141 v8::Local<Name> name,
1181 Getter getter, 1142 Getter getter,
1182 Setter setter, 1143 Setter setter,
1183 Data data, 1144 Data data,
1184 AccessControl settings, 1145 AccessControl settings,
1185 PropertyAttribute attribute, 1146 PropertyAttribute attribute,
1186 v8::Local<AccessorSignature> signature) { 1147 v8::Local<AccessorSignature> signature) {
1187 i::Isolate* isolate = Utils::OpenHandle(template_obj)->GetIsolate(); 1148 auto isolate = Utils::OpenHandle(template_obj)->GetIsolate();
1188 ENTER_V8(isolate); 1149 ENTER_V8(isolate);
1189 i::HandleScope scope(isolate); 1150 i::HandleScope scope(isolate);
1190 i::Handle<i::AccessorInfo> obj = MakeAccessorInfo( 1151 auto obj = MakeAccessorInfo(name, getter, setter, data, settings, attribute,
1191 name, getter, setter, data, settings, attribute, signature); 1152 signature);
1192 if (obj.is_null()) return false; 1153 if (obj.is_null()) return false;
1193 i::Handle<i::TemplateInfo> info = GetTemplateInfo(isolate, template_obj); 1154 auto info = GetTemplateInfo(isolate, template_obj);
1194 AddPropertyToTemplate(info, obj); 1155 i::ApiNatives::AddNativeDataProperty(isolate, info, obj);
1195 return true; 1156 return true;
1196 } 1157 }
1197 1158
1198 1159
1199 void Template::SetNativeDataProperty(v8::Local<String> name, 1160 void Template::SetNativeDataProperty(v8::Local<String> name,
1200 AccessorGetterCallback getter, 1161 AccessorGetterCallback getter,
1201 AccessorSetterCallback setter, 1162 AccessorSetterCallback setter,
1202 v8::Handle<Value> data, 1163 v8::Handle<Value> data,
1203 PropertyAttribute attribute, 1164 PropertyAttribute attribute,
1204 v8::Local<AccessorSignature> signature, 1165 v8::Local<AccessorSignature> signature,
(...skipping 6432 matching lines...) Expand 10 before | Expand all | Expand 10 after
7637 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 7598 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7638 Address callback_address = 7599 Address callback_address =
7639 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 7600 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
7640 VMState<EXTERNAL> state(isolate); 7601 VMState<EXTERNAL> state(isolate);
7641 ExternalCallbackScope call_scope(isolate, callback_address); 7602 ExternalCallbackScope call_scope(isolate, callback_address);
7642 callback(info); 7603 callback(info);
7643 } 7604 }
7644 7605
7645 7606
7646 } } // namespace v8::internal 7607 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/api-natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698