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 }; |