Index: src/runtime/runtime-classes.cc |
diff --git a/src/runtime/runtime-classes.cc b/src/runtime/runtime-classes.cc |
index 9c432da711dab843c17ab01ecd0a229fb1bb22ca..ca309f5fecd5a89e66e2287d116741620d3e97b2 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" |
@@ -171,6 +172,42 @@ RUNTIME_FUNCTION(Runtime_DefineClass) { |
} |
namespace { |
+void InstallClassNameAccessor(Isolate* isolate, Handle<JSObject> object) { |
+ 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()); |
+} |
+} // anonymous namespace |
+ |
+RUNTIME_FUNCTION(Runtime_InstallClassNameAccessor) { |
+ HandleScope scope(isolate); |
+ DCHECK(args.length() == 1); |
+ CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
+ InstallClassNameAccessor(isolate, object); |
+ return *object; |
+} |
+ |
+RUNTIME_FUNCTION(Runtime_InstallClassNameAccessorWithCheck) { |
+ HandleScope scope(isolate); |
+ DCHECK(args.length() == 1); |
+ CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
+ |
+ // If a property named "name" is already defined, exit. |
+ Handle<Name> key = isolate->factory()->name_string(); |
+ if (JSObject::HasRealNamedProperty(object, key).FromMaybe(false)) { |
+ return *object; |
+ } |
+ |
+ // Define the "name" accessor. |
+ InstallClassNameAccessor(isolate, object); |
+ return *object; |
+} |
+ |
+namespace { |
enum class SuperMode { kLoad, kStore }; |