Index: src/runtime/runtime-classes.cc |
diff --git a/src/runtime/runtime-classes.cc b/src/runtime/runtime-classes.cc |
index ca309f5fecd5a89e66e2287d116741620d3e97b2..0e61cb60c0014882872e83c938325e7df23697e5 100644 |
--- a/src/runtime/runtime-classes.cc |
+++ b/src/runtime/runtime-classes.cc |
@@ -26,7 +26,6 @@ RUNTIME_FUNCTION(Runtime_ThrowNonMethodError) { |
isolate, NewReferenceError(MessageTemplate::kNonMethod)); |
} |
- |
RUNTIME_FUNCTION(Runtime_ThrowUnsupportedSuperError) { |
HandleScope scope(isolate); |
DCHECK(args.length() == 0); |
@@ -59,6 +58,36 @@ RUNTIME_FUNCTION(Runtime_ThrowStaticPrototypeError) { |
isolate, NewTypeError(MessageTemplate::kStaticPrototype)); |
} |
+namespace { |
+ |
+Object* ThrowNotSuperConstructor(Isolate* isolate, Handle<Object> constructor, |
+ Handle<JSFunction> function) { |
+ Handle<Object> super_name; |
+ if (constructor->IsJSFunction()) { |
+ super_name = handle(Handle<JSFunction>::cast(constructor)->shared()->name(), |
+ isolate); |
+ } else if (constructor->IsOddball()) { |
Benedikt Meurer
2016/12/09 18:30:28
As far as I can tell, this should always be null i
|
+ super_name = |
+ handle(Handle<Oddball>::cast(constructor)->to_string(), isolate); |
+ } else { |
+ super_name = Object::NoSideEffectsToString(isolate, constructor); |
+ } |
+ Handle<Object> function_name(function->shared()->name(), isolate); |
+ THROW_NEW_ERROR_RETURN_FAILURE( |
+ isolate, NewTypeError(MessageTemplate::kNotSuperConstructor, super_name, |
+ function_name)); |
+} |
+ |
+} // anonymous namespace |
Benedikt Meurer
2016/12/09 18:30:28
Nit: just namespace here.
|
+ |
+RUNTIME_FUNCTION(Runtime_ThrowNotSuperConstructor) { |
+ HandleScope scope(isolate); |
+ DCHECK(args.length() == 2); |
+ CONVERT_ARG_HANDLE_CHECKED(Object, constructor, 0); |
+ CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 1); |
+ return ThrowNotSuperConstructor(isolate, constructor, function); |
+} |
+ |
RUNTIME_FUNCTION(Runtime_HomeObjectSymbol) { |
DCHECK(args.length() == 0); |
return isolate->heap()->home_object_symbol(); |
@@ -421,8 +450,14 @@ RUNTIME_FUNCTION(Runtime_StoreKeyedToSuper_Sloppy) { |
RUNTIME_FUNCTION(Runtime_GetSuperConstructor) { |
SealHandleScope shs(isolate); |
DCHECK_EQ(1, args.length()); |
- CONVERT_ARG_CHECKED(JSFunction, active_function, 0); |
- return active_function->map()->prototype(); |
+ CONVERT_ARG_HANDLE_CHECKED(JSFunction, active_function, 0); |
+ Object* prototype = active_function->map()->prototype(); |
+ if (!prototype->IsConstructor()) { |
+ return ThrowNotSuperConstructor( |
+ isolate, Handle<JSFunction>::cast(handle(prototype, isolate)), |
+ active_function); |
+ } |
+ return prototype; |
} |
RUNTIME_FUNCTION(Runtime_NewWithSpread) { |