Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Unified Diff: src/runtime/runtime-classes.cc

Issue 2423053002: Install the 'name' property in classes at runtime (Closed)
Patch Set: Rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/runtime/runtime-classes.cc
diff --git a/src/runtime/runtime-classes.cc b/src/runtime/runtime-classes.cc
index aafd7779870f74cbd9bc2e5380b79f4842e8638b..9c304181ae9b7112f0e1c1acb6f556900be757b8 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() == 2);
+ CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0);
+ InstallClassNameAccessor(isolate, object);
+ return *object;
+}
+
+RUNTIME_FUNCTION(Runtime_InstallClassNameAccessorWithCheck) {
+ HandleScope scope(isolate);
+ DCHECK(args.length() == 2);
+ 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 };

Powered by Google App Engine
This is Rietveld 408576698