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

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

Issue 2423053002: Install the 'name' property in classes at runtime (Closed)
Patch Set: Use an accessor instead of a data property Created 4 years, 1 month 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 323604ffdec47047d31e14cd4600fa9e0f78e068..e585baa8bd4a194c6015cc23460eee86189a3b14 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_DefineClassNameProperty) {
+ HandleScope scope(isolate);
+ DCHECK(args.length() == 2);
+ CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0);
+ CONVERT_ARG_HANDLE_CHECKED(String, name, 1);
+
+ // Abort if "name" is undefined.
+ if (name->length() == 0) return *object;
Toon Verwaest 2016/11/24 07:13:38 You can check this at compile-time, which means yo
+
+ // 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" property.
+ PropertyAttributes attrs =
+ static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY);
+ // Cannot fail since this should only be called when creating an object
+ // literal.
+ DCHECK(!JSObject::SetAccessor(
+ object, Accessors::FunctionNameInfo(object->GetIsolate(), attrs))
+ .is_null());
+ return *object;
+}
+
namespace {
enum class SuperMode { kLoad, kStore };

Powered by Google App Engine
This is Rietveld 408576698