Index: src/runtime/runtime-classes.cc |
diff --git a/src/runtime/runtime-classes.cc b/src/runtime/runtime-classes.cc |
index 323604ffdec47047d31e14cd4600fa9e0f78e068..511d2cd1f18aa885d51ad2e57a51683fa98cbe41 100644 |
--- a/src/runtime/runtime-classes.cc |
+++ b/src/runtime/runtime-classes.cc |
@@ -7,6 +7,7 @@ |
#include <stdlib.h> |
#include <limits> |
+#include "src/accessors.h" |
#include "src/arguments.h" |
#include "src/debug/debug.h" |
#include "src/frames-inl.h" |
@@ -188,6 +189,32 @@ RUNTIME_FUNCTION(Runtime_DefineClass) { |
end_position)); |
} |
+ |
+RUNTIME_FUNCTION(Runtime_InstallClassNameAccessor) { |
+ HandleScope scope(isolate); |
+ DCHECK(args.length() == 2); |
+ CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
+ CONVERT_BOOLEAN_ARG_CHECKED(needs_name_check, 1); |
+ |
+ // If a property named "name" is already defined, exit. |
+ if (needs_name_check) { |
+ Handle<Name> key = isolate->factory()->name_string(); |
+ if (JSObject::HasRealNamedProperty(object, key).FromMaybe(false)) { |
+ return *object; |
+ } |
+ } |
+ |
+ // Define the "name" accessor. |
+ PropertyAttributes attrs = |
+ static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY); |
+ // Cannot fail since this should only be called when creating an object |
+ // literal. |
+ CHECK(!JSObject::SetAccessor( |
+ object, Accessors::FunctionNameInfo(object->GetIsolate(), attrs)) |
+ .is_null()); |
+ return *object; |
+} |
+ |
namespace { |
enum class SuperMode { kLoad, kStore }; |