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

Side by Side Diff: src/runtime/runtime-classes.cc

Issue 2142333002: Refactor class declaration logic to the parser and runtime Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: minor cleanup Created 4 years, 5 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
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <limits> 8 #include <limits>
9 9
10 #include "src/arguments.h" 10 #include "src/arguments.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 77
78 78
79 RUNTIME_FUNCTION(Runtime_HomeObjectSymbol) { 79 RUNTIME_FUNCTION(Runtime_HomeObjectSymbol) {
80 DCHECK(args.length() == 0); 80 DCHECK(args.length() == 0);
81 return isolate->heap()->home_object_symbol(); 81 return isolate->heap()->home_object_symbol();
82 } 82 }
83 83
84 static MaybeHandle<Object> DefineClass(Isolate* isolate, 84 static MaybeHandle<Object> DefineClass(Isolate* isolate,
85 Handle<Object> super_class, 85 Handle<Object> super_class,
86 Handle<JSFunction> constructor, 86 Handle<JSFunction> constructor,
87 Handle<JSArray> property_names,
88 Handle<JSArray> property_funcs,
89 Handle<JSArray> property_infos,
87 int start_position, int end_position) { 90 int start_position, int end_position) {
88 Handle<Object> prototype_parent; 91 Handle<Object> prototype_parent;
89 Handle<Object> constructor_parent; 92 Handle<Object> constructor_parent;
90 93
91 if (super_class->IsTheHole(isolate)) { 94 if (super_class->IsTheHole(isolate)) {
92 prototype_parent = isolate->initial_object_prototype(); 95 prototype_parent = isolate->initial_object_prototype();
93 } else { 96 } else {
94 if (super_class->IsNull(isolate)) { 97 if (super_class->IsNull(isolate)) {
95 prototype_parent = isolate->factory()->null_value(); 98 prototype_parent = isolate->factory()->null_value();
96 } else if (super_class->IsConstructor()) { 99 } else if (super_class->IsConstructor()) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 Object::SetProperty( 166 Object::SetProperty(
164 constructor, isolate->factory()->class_start_position_symbol(), 167 constructor, isolate->factory()->class_start_position_symbol(),
165 handle(Smi::FromInt(start_position), isolate), STRICT), 168 handle(Smi::FromInt(start_position), isolate), STRICT),
166 Object); 169 Object);
167 RETURN_ON_EXCEPTION( 170 RETURN_ON_EXCEPTION(
168 isolate, Object::SetProperty( 171 isolate, Object::SetProperty(
169 constructor, isolate->factory()->class_end_position_symbol(), 172 constructor, isolate->factory()->class_end_position_symbol(),
170 handle(Smi::FromInt(end_position), isolate), STRICT), 173 handle(Smi::FromInt(end_position), isolate), STRICT),
171 Object); 174 Object);
172 175
176 Object* array_length_obj = property_names->length();
177 CHECK(array_length_obj->IsSmi());
178 int array_len = Smi::cast(array_length_obj)->value();
179
180 DCHECK_EQ(array_length_obj, property_funcs->length());
181 DCHECK_EQ(array_length_obj, property_infos->length());
182
183 for (int i = 0; i < array_len; ++i) {
184 Handle<Object> name_obj =
185 JSReceiver::GetElement(isolate, property_names, i).ToHandleChecked();
adamk 2016/07/13 20:57:32 These are probably one of the reasons this is slow
186 DCHECK(name_obj->IsName());
187 Handle<Name> name = Handle<Name>::cast(name_obj);
188
189 Handle<Object> func_obj =
190 JSReceiver::GetElement(isolate, property_funcs, i).ToHandleChecked();
191 DCHECK(func_obj->IsJSFunction());
192 Handle<JSFunction> func = Handle<JSFunction>::cast(func_obj);
193
194 Handle<Object> info_obj =
195 JSReceiver::GetElement(isolate, property_infos, i).ToHandleChecked();
196 DCHECK(info_obj->IsSmi());
197 int info = Smi::cast(*info_obj)->value();
198
199 bool is_static = info & kIsStaticMask;
200
201 if (is_static) {
202 if (Name::Equals(name, isolate->factory()->prototype_string())) {
203 THROW_NEW_ERROR(
204 isolate, NewTypeError(MessageTemplate::kStaticPrototype), Object);
205 }
206 }
207
208 Handle<JSObject> receiver =
209 is_static ? static_cast<Handle<JSObject>>(constructor) : prototype;
210
211 if (func->shared()->needs_home_object()) {
212 RETURN_ON_EXCEPTION(isolate,
213 JSObject::SetOwnPropertyIgnoreAttributes(
214 func, home_object_symbol, receiver, DONT_ENUM),
215 Object);
216 }
217
218 if (info & kIsAccessorMask) {
219 if (info & kIsSetterMask) {
220 // Setter
221 if (String::cast(func->shared()->name())->length() == 0) {
222 JSFunction::SetName(func, name, isolate->factory()->set_string());
223 }
224
225 RETURN_ON_EXCEPTION(
226 isolate, JSObject::DefineAccessor(receiver, name,
227 isolate->factory()->null_value(),
228 func, DONT_ENUM),
229 Object);
230 } else {
231 // Getter
232 if (String::cast(func->shared()->name())->length() == 0) {
233 JSFunction::SetName(func, name, isolate->factory()->get_string());
234 }
235
236 RETURN_ON_EXCEPTION(
237 isolate, JSObject::DefineAccessor(receiver, name, func,
238 isolate->factory()->null_value(),
239 DONT_ENUM),
240 Object);
241 }
242 } else {
243 // Method
244 if (String::cast(func->shared()->name())->length() == 0) {
245 JSFunction::SetName(func, name, isolate->factory()->empty_string());
246 }
247
248 LookupIterator it = LookupIterator::PropertyOrElement(
249 isolate, receiver, name, receiver, LookupIterator::OWN);
250 CHECK(JSObject::DefineOwnPropertyIgnoreAttributes(&it, func, DONT_ENUM,
251 Object::DONT_THROW)
252 .IsJust());
253 }
254 }
255
173 return constructor; 256 return constructor;
174 } 257 }
175 258
176 259
177 RUNTIME_FUNCTION(Runtime_DefineClass) { 260 RUNTIME_FUNCTION(Runtime_DefineClass) {
178 HandleScope scope(isolate); 261 HandleScope scope(isolate);
179 DCHECK(args.length() == 4); 262 DCHECK(args.length() == 7);
180 CONVERT_ARG_HANDLE_CHECKED(Object, super_class, 0); 263 CONVERT_ARG_HANDLE_CHECKED(Object, super_class, 0);
181 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 1); 264 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 1);
182 CONVERT_SMI_ARG_CHECKED(start_position, 2); 265 CONVERT_ARG_HANDLE_CHECKED(JSArray, property_names, 2);
183 CONVERT_SMI_ARG_CHECKED(end_position, 3); 266 CONVERT_ARG_HANDLE_CHECKED(JSArray, property_funcs, 3);
267 CONVERT_ARG_HANDLE_CHECKED(JSArray, property_infos, 4);
268 CONVERT_SMI_ARG_CHECKED(start_position, 5);
269 CONVERT_SMI_ARG_CHECKED(end_position, 6);
184 270
185 RETURN_RESULT_OR_FAILURE( 271 RETURN_RESULT_OR_FAILURE(
186 isolate, DefineClass(isolate, super_class, constructor, start_position, 272 isolate, DefineClass(isolate, super_class, constructor, property_names,
273 property_funcs, property_infos, start_position,
187 end_position)); 274 end_position));
188 } 275 }
189 276
190 277
191 static MaybeHandle<Object> LoadFromSuper(Isolate* isolate, 278 static MaybeHandle<Object> LoadFromSuper(Isolate* isolate,
192 Handle<Object> receiver, 279 Handle<Object> receiver,
193 Handle<JSObject> home_object, 280 Handle<JSObject> home_object,
194 Handle<Name> name) { 281 Handle<Name> name) {
195 if (home_object->IsAccessCheckNeeded() && 282 if (home_object->IsAccessCheckNeeded() &&
196 !isolate->MayAccess(handle(isolate->context()), home_object)) { 283 !isolate->MayAccess(handle(isolate->context()), home_object)) {
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 477
391 RUNTIME_FUNCTION(Runtime_GetSuperConstructor) { 478 RUNTIME_FUNCTION(Runtime_GetSuperConstructor) {
392 SealHandleScope shs(isolate); 479 SealHandleScope shs(isolate);
393 DCHECK_EQ(1, args.length()); 480 DCHECK_EQ(1, args.length());
394 CONVERT_ARG_CHECKED(JSFunction, active_function, 0); 481 CONVERT_ARG_CHECKED(JSFunction, active_function, 0);
395 return active_function->map()->prototype(); 482 return active_function->map()->prototype();
396 } 483 }
397 484
398 } // namespace internal 485 } // namespace internal
399 } // namespace v8 486 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698