| Index: src/runtime/runtime.cc
|
| diff --git a/src/runtime/runtime.cc b/src/runtime/runtime.cc
|
| index 815bc4592a65600086955620e69c10557621eb25..130b28f73e133eacfb157334080ccaf02868ba52 100644
|
| --- a/src/runtime/runtime.cc
|
| +++ b/src/runtime/runtime.cc
|
| @@ -361,6 +361,83 @@ 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();
|
| + } else {
|
| + if (super_class->IsNull()) {
|
| + prototype_parent = isolate->factory()->null_value();
|
| + } else if (!super_class->IsSpecFunction()) {
|
| + // 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)));
|
| + } else {
|
| + 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;
|
| + }
|
| + }
|
| +
|
| + Handle<JSObject> prototype =
|
| + isolate->factory()->NewJSObject(isolate->object_function());
|
| + JSObject::SetPrototype(prototype, prototype_parent, false).Assert();
|
| +
|
| + Handle<String> name_string = name->IsString()
|
| + ? Handle<String>::cast(name)
|
| + : isolate->factory()->empty_string();
|
| +
|
| + Handle<JSFunction> ctor;
|
| + if (constructor->IsUndefined()) {
|
| + // 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);
|
| + } else {
|
| + ctor = Handle<JSFunction>::cast(constructor);
|
| + JSFunction::SetPrototype(ctor, prototype);
|
| + PropertyAttributes attribs =
|
| + static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
|
| + JSObject::SetOwnPropertyIgnoreAttributes(
|
| + ctor, isolate->factory()->prototype_string(), prototype, attribs)
|
| + .Assert();
|
| + }
|
| +
|
| + Handle<Symbol> home_object_symbol(isolate->heap()->home_object_symbol());
|
| + JSObject::SetOwnPropertyIgnoreAttributes(ctor, home_object_symbol, prototype,
|
| + DONT_ENUM).Assert();
|
| +
|
| + if (has_constructor_parent) {
|
| + JSObject::SetPrototype(ctor, constructor_parent, false).Assert();
|
| + }
|
| +
|
| + JSObject::AddProperty(prototype, isolate->factory()->constructor_string(),
|
| + ctor, DONT_ENUM);
|
| +
|
| + return *ctor;
|
| +}
|
| +
|
| +
|
| RUNTIME_FUNCTION(Runtime_IsExtensible) {
|
| SealHandleScope shs(isolate);
|
| DCHECK(args.length() == 1);
|
|
|