Chromium Code Reviews| Index: src/runtime/runtime.cc |
| diff --git a/src/runtime/runtime.cc b/src/runtime/runtime.cc |
| index 815bc4592a65600086955620e69c10557621eb25..1b277dade979e72feb6d7099a25bc4751605e54b 100644 |
| --- a/src/runtime/runtime.cc |
| +++ b/src/runtime/runtime.cc |
| @@ -361,6 +361,87 @@ RUNTIME_FUNCTION(Runtime_StoreToSuper_Sloppy) { |
| } |
| +RUNTIME_FUNCTION(Runtime_DefineClass) { |
| + HandleScope scope(isolate); |
| + DCHECK(args.length() == 3); |
| + CONVERT_ARG_HANDLE_CHECKED(Object, name, 0); |
| + CONVERT_ARG_HANDLE_CHECKED(Object, super_class, 1); |
| + CONVERT_ARG_HANDLE_CHECKED(Object, constructor, 2); |
| + |
| + Handle<Object> prototype_parent; |
| + Handle<Object> constructor_parent; |
| + bool has_constructor_parent = false; |
| + |
| + if (super_class->IsTheHole()) { |
| + 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
|
| + } else { |
| + if (super_class->IsNull()) { |
| + prototype_parent = isolate->factory()->null_value(); |
| + } else if (super_class->IsSpecFunction()) { |
| + ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| + isolate, prototype_parent, |
| + Runtime::GetObjectProperty(isolate, super_class, |
| + isolate->factory()->prototype_string())); |
| + if (!prototype_parent->IsNull() && !prototype_parent->IsSpecObject()) { |
| + Handle<Object> args[1] = {prototype_parent}; |
| + THROW_NEW_ERROR_RETURN_FAILURE( |
| + isolate, NewTypeError("prototype_parent_not_an_object", |
| + HandleVector(args, 1))); |
| + } |
| + constructor_parent = super_class; |
| + has_constructor_parent = true; |
| + } else { |
| + // TODO(arv): Should be IsConstructor. |
| + Handle<Object> args[1] = {super_class}; |
| + THROW_NEW_ERROR_RETURN_FAILURE( |
| + isolate, |
| + NewTypeError("extends_value_not_a_function", HandleVector(args, 1))); |
| + } |
| + } |
| + |
| + Handle<JSObject> prototype = |
| + isolate->factory()->NewJSObject(isolate->object_function()); |
| + RETURN_FAILURE_ON_EXCEPTION( |
| + 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
|
| + |
| + Handle<String> name_string = name->IsString() |
| + ? Handle<String>::cast(name) |
| + : isolate->factory()->empty_string(); |
| + |
| + Handle<JSFunction> ctor; |
| + if (constructor->IsSpecFunction()) { |
| + ctor = Handle<JSFunction>::cast(constructor); |
| + JSFunction::SetPrototype(ctor, prototype); |
| + PropertyAttributes attribs = |
| + static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
| + RETURN_FAILURE_ON_EXCEPTION( |
| + isolate, |
| + JSObject::SetOwnPropertyIgnoreAttributes( |
| + ctor, isolate->factory()->prototype_string(), prototype, attribs)); |
| + } else { |
| + // TODO(arv): This should not use an empty function but a function that |
| + // calls super. |
| + Handle<Code> code(isolate->builtins()->builtin(Builtins::kEmptyFunction)); |
| + ctor = isolate->factory()->NewFunction(name_string, code, prototype, true); |
| + } |
| + |
| + Handle<Symbol> home_object_symbol(isolate->heap()->home_object_symbol()); |
| + RETURN_FAILURE_ON_EXCEPTION( |
| + isolate, JSObject::SetOwnPropertyIgnoreAttributes( |
| + ctor, home_object_symbol, prototype, DONT_ENUM)); |
| + |
| + if (has_constructor_parent) { |
| + RETURN_FAILURE_ON_EXCEPTION( |
| + isolate, JSObject::SetPrototype(ctor, constructor_parent, false)); |
| + } |
| + |
| + JSObject::AddProperty(prototype, isolate->factory()->constructor_string(), |
| + ctor, DONT_ENUM); |
| + |
| + return *ctor; |
| +} |
| + |
| + |
| RUNTIME_FUNCTION(Runtime_IsExtensible) { |
| SealHandleScope shs(isolate); |
| DCHECK(args.length() == 1); |