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

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

Issue 631433002: Classes runtime (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix issue with function state Created 6 years, 2 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 | Annotate | Revision Log
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 <stdlib.h> 5 #include <stdlib.h>
6 #include <limits> 6 #include <limits>
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/accessors.h" 10 #include "src/accessors.h"
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 DCHECK(args.length() == 4); 354 DCHECK(args.length() == 4);
355 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 0); 355 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 0);
356 CONVERT_ARG_HANDLE_CHECKED(JSObject, home_object, 1); 356 CONVERT_ARG_HANDLE_CHECKED(JSObject, home_object, 1);
357 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); 357 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
358 CONVERT_ARG_HANDLE_CHECKED(Name, name, 3); 358 CONVERT_ARG_HANDLE_CHECKED(Name, name, 3);
359 359
360 return StoreToSuper(isolate, home_object, receiver, name, value, SLOPPY); 360 return StoreToSuper(isolate, home_object, receiver, name, value, SLOPPY);
361 } 361 }
362 362
363 363
364 RUNTIME_FUNCTION(Runtime_DefineClass) {
365 HandleScope scope(isolate);
366 DCHECK(args.length() == 3);
367 CONVERT_ARG_HANDLE_CHECKED(Object, name, 0);
368 CONVERT_ARG_HANDLE_CHECKED(Object, super_class, 1);
369 CONVERT_ARG_HANDLE_CHECKED(Object, constructor, 2);
370
371 Handle<Object> prototype_parent;
372 Handle<Object> constructor_parent;
373 bool has_constructor_parent = false;
374
375 if (super_class->IsTheHole()) {
376 prototype_parent = isolate->initial_object_prototype();
Dmitry Lomov (no reviews) 2014/10/07 10:28:32 What happens, per spec, if user assigns to Object.
arv (Not doing code reviews) 2014/10/07 14:47:09 The spec uses %ObjectPrototype% which is the origi
377 } else {
378 if (super_class->IsNull()) {
379 prototype_parent = isolate->factory()->null_value();
380 } else if (super_class->IsSpecFunction()) {
381 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
382 isolate, prototype_parent,
383 Runtime::GetObjectProperty(isolate, super_class,
384 isolate->factory()->prototype_string()));
385 if (!prototype_parent->IsNull() && !prototype_parent->IsSpecObject()) {
386 Handle<Object> args[1] = {prototype_parent};
387 THROW_NEW_ERROR_RETURN_FAILURE(
388 isolate, NewTypeError("prototype_parent_not_an_object",
389 HandleVector(args, 1)));
390 }
391 constructor_parent = super_class;
392 has_constructor_parent = true;
393 } else {
394 // TODO(arv): Should be IsConstructor.
395 Handle<Object> args[1] = {super_class};
396 THROW_NEW_ERROR_RETURN_FAILURE(
397 isolate,
398 NewTypeError("extends_value_not_a_function", HandleVector(args, 1)));
399 }
400 }
401
402 Handle<JSObject> prototype =
403 isolate->factory()->NewJSObject(isolate->object_function());
404 RETURN_FAILURE_ON_EXCEPTION(
405 isolate, JSObject::SetPrototype(prototype, prototype_parent, false));
Dmitry Lomov (no reviews) 2014/10/07 10:28:32 Instead of SetPrototype here, I suggest using NewJ
arv (Not doing code reviews) 2014/10/07 14:47:09 Done. I used to have a todo for this... I'm not s
406
407 Handle<String> name_string = name->IsString()
408 ? Handle<String>::cast(name)
409 : isolate->factory()->empty_string();
410
411 Handle<JSFunction> ctor;
412 if (constructor->IsSpecFunction()) {
413 ctor = Handle<JSFunction>::cast(constructor);
414 JSFunction::SetPrototype(ctor, prototype);
415 PropertyAttributes attribs =
416 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
417 RETURN_FAILURE_ON_EXCEPTION(
418 isolate,
419 JSObject::SetOwnPropertyIgnoreAttributes(
420 ctor, isolate->factory()->prototype_string(), prototype, attribs));
421 } else {
422 // TODO(arv): This should not use an empty function but a function that
423 // calls super.
424 Handle<Code> code(isolate->builtins()->builtin(Builtins::kEmptyFunction));
425 ctor = isolate->factory()->NewFunction(name_string, code, prototype, true);
426 }
427
428 Handle<Symbol> home_object_symbol(isolate->heap()->home_object_symbol());
429 RETURN_FAILURE_ON_EXCEPTION(
430 isolate, JSObject::SetOwnPropertyIgnoreAttributes(
431 ctor, home_object_symbol, prototype, DONT_ENUM));
432
433 if (has_constructor_parent) {
434 RETURN_FAILURE_ON_EXCEPTION(
435 isolate, JSObject::SetPrototype(ctor, constructor_parent, false));
436 }
437
438 JSObject::AddProperty(prototype, isolate->factory()->constructor_string(),
439 ctor, DONT_ENUM);
440
441 return *ctor;
442 }
443
444
364 RUNTIME_FUNCTION(Runtime_IsExtensible) { 445 RUNTIME_FUNCTION(Runtime_IsExtensible) {
365 SealHandleScope shs(isolate); 446 SealHandleScope shs(isolate);
366 DCHECK(args.length() == 1); 447 DCHECK(args.length() == 1);
367 CONVERT_ARG_CHECKED(JSObject, obj, 0); 448 CONVERT_ARG_CHECKED(JSObject, obj, 0);
368 if (obj->IsJSGlobalProxy()) { 449 if (obj->IsJSGlobalProxy()) {
369 PrototypeIterator iter(isolate, obj); 450 PrototypeIterator iter(isolate, obj);
370 if (iter.IsAtEnd()) return isolate->heap()->false_value(); 451 if (iter.IsAtEnd()) return isolate->heap()->false_value();
371 DCHECK(iter.GetCurrent()->IsJSGlobalObject()); 452 DCHECK(iter.GetCurrent()->IsJSGlobalObject());
372 obj = JSObject::cast(iter.GetCurrent()); 453 obj = JSObject::cast(iter.GetCurrent());
373 } 454 }
(...skipping 3060 matching lines...) Expand 10 before | Expand all | Expand 10 after
3434 } 3515 }
3435 return NULL; 3516 return NULL;
3436 } 3517 }
3437 3518
3438 3519
3439 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { 3520 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) {
3440 return &(kIntrinsicFunctions[static_cast<int>(id)]); 3521 return &(kIntrinsicFunctions[static_cast<int>(id)]);
3441 } 3522 }
3442 } 3523 }
3443 } // namespace v8::internal 3524 } // namespace v8::internal
OLDNEW
« src/preparser.h ('K') | « src/runtime/runtime.h ('k') | test/mjsunit/harmony/classes.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698