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

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 per Adam 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 if (array_len == 0) return constructor;
184
185 DCHECK(property_names->GetElementsKind() == FAST_ELEMENTS);
186 DCHECK(property_funcs->GetElementsKind() == FAST_ELEMENTS);
187 DCHECK(property_infos->GetElementsKind() == FAST_SMI_ELEMENTS);
188
189 Handle<FixedArray> property_names_elements(
190 FixedArray::cast(property_names->elements()));
191 Handle<FixedArray> property_funcs_elements(
192 FixedArray::cast(property_funcs->elements()));
193 Handle<FixedArray> property_infos_elements(
194 FixedArray::cast(property_infos->elements()));
195
196 for (int i = 0; i < array_len; ++i) {
197 Handle<Object> name_obj(property_names_elements->get(i), isolate);
198 DCHECK(name_obj->IsName());
199 Handle<Name> name = Handle<Name>::cast(name_obj);
200
201 Handle<Object> func_obj(property_funcs_elements->get(i), isolate);
202 DCHECK(func_obj->IsJSFunction());
203 Handle<JSFunction> func = Handle<JSFunction>::cast(func_obj);
204
205 Handle<Object> info_obj(property_infos_elements->get(i), isolate);
206 DCHECK(info_obj->IsSmi());
207 int info = Smi::cast(*info_obj)->value();
208
209 bool is_static = info & kIsStaticMask;
210
211 if (is_static) {
212 if (Name::Equals(name, isolate->factory()->prototype_string())) {
213 THROW_NEW_ERROR(
214 isolate, NewTypeError(MessageTemplate::kStaticPrototype), Object);
215 }
216 }
217
218 Handle<JSObject> receiver =
219 is_static ? static_cast<Handle<JSObject>>(constructor) : prototype;
220
221 if (func->shared()->needs_home_object()) {
222 RETURN_ON_EXCEPTION(isolate,
223 JSObject::SetOwnPropertyIgnoreAttributes(
224 func, home_object_symbol, receiver, DONT_ENUM),
225 Object);
226 }
227
228 if (info & kIsAccessorMask) {
229 if (info & kIsSetterMask) {
230 // Setter
231 if (String::cast(func->shared()->name())->length() == 0) {
232 JSFunction::SetName(func, name, isolate->factory()->set_string());
233 }
234
235 RETURN_ON_EXCEPTION(
236 isolate, JSObject::DefineAccessor(receiver, name,
237 isolate->factory()->null_value(),
238 func, DONT_ENUM),
239 Object);
240 } else {
241 // Getter
242 if (String::cast(func->shared()->name())->length() == 0) {
243 JSFunction::SetName(func, name, isolate->factory()->get_string());
244 }
245
246 RETURN_ON_EXCEPTION(
247 isolate, JSObject::DefineAccessor(receiver, name, func,
248 isolate->factory()->null_value(),
249 DONT_ENUM),
250 Object);
251 }
252 } else {
253 // Method
254 if (String::cast(func->shared()->name())->length() == 0) {
255 JSFunction::SetName(func, name, isolate->factory()->empty_string());
256 }
257
258 LookupIterator it = LookupIterator::PropertyOrElement(
259 isolate, receiver, name, receiver, LookupIterator::OWN);
260 CHECK(JSObject::DefineOwnPropertyIgnoreAttributes(&it, func, DONT_ENUM,
261 Object::DONT_THROW)
262 .IsJust());
263 }
264 }
265
173 return constructor; 266 return constructor;
174 } 267 }
175 268
176 269
177 RUNTIME_FUNCTION(Runtime_DefineClass) { 270 RUNTIME_FUNCTION(Runtime_DefineClass) {
178 HandleScope scope(isolate); 271 HandleScope scope(isolate);
179 DCHECK(args.length() == 4); 272 DCHECK(args.length() == 7);
180 CONVERT_ARG_HANDLE_CHECKED(Object, super_class, 0); 273 CONVERT_ARG_HANDLE_CHECKED(Object, super_class, 0);
181 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 1); 274 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 1);
182 CONVERT_SMI_ARG_CHECKED(start_position, 2); 275 CONVERT_ARG_HANDLE_CHECKED(JSArray, property_names, 2);
183 CONVERT_SMI_ARG_CHECKED(end_position, 3); 276 CONVERT_ARG_HANDLE_CHECKED(JSArray, property_funcs, 3);
277 CONVERT_ARG_HANDLE_CHECKED(JSArray, property_infos, 4);
278 CONVERT_SMI_ARG_CHECKED(start_position, 5);
279 CONVERT_SMI_ARG_CHECKED(end_position, 6);
184 280
185 RETURN_RESULT_OR_FAILURE( 281 RETURN_RESULT_OR_FAILURE(
186 isolate, DefineClass(isolate, super_class, constructor, start_position, 282 isolate, DefineClass(isolate, super_class, constructor, property_names,
283 property_funcs, property_infos, start_position,
187 end_position)); 284 end_position));
188 } 285 }
189 286
190 287
191 static MaybeHandle<Object> LoadFromSuper(Isolate* isolate, 288 static MaybeHandle<Object> LoadFromSuper(Isolate* isolate,
192 Handle<Object> receiver, 289 Handle<Object> receiver,
193 Handle<JSObject> home_object, 290 Handle<JSObject> home_object,
194 Handle<Name> name) { 291 Handle<Name> name) {
195 if (home_object->IsAccessCheckNeeded() && 292 if (home_object->IsAccessCheckNeeded() &&
196 !isolate->MayAccess(handle(isolate->context()), home_object)) { 293 !isolate->MayAccess(handle(isolate->context()), home_object)) {
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 487
391 RUNTIME_FUNCTION(Runtime_GetSuperConstructor) { 488 RUNTIME_FUNCTION(Runtime_GetSuperConstructor) {
392 SealHandleScope shs(isolate); 489 SealHandleScope shs(isolate);
393 DCHECK_EQ(1, args.length()); 490 DCHECK_EQ(1, args.length());
394 CONVERT_ARG_CHECKED(JSFunction, active_function, 0); 491 CONVERT_ARG_CHECKED(JSFunction, active_function, 0);
395 return active_function->map()->prototype(); 492 return active_function->map()->prototype();
396 } 493 }
397 494
398 } // namespace internal 495 } // namespace internal
399 } // namespace v8 496 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698