Added: trunk/JSTests/stress/object-literal-methods.js (0 => 206082)
--- trunk/JSTests/stress/object-literal-methods.js (rev 0)
+++ trunk/JSTests/stress/object-literal-methods.js 2016-09-18 17:40:11 UTC (rev 206082)
@@ -0,0 +1,105 @@
+function shouldBe(actual, expected) {
+ if (actual !== expected)
+ throw new Error('bad value: ' + actual);
+}
+
+{
+ let name = 'prototype';
+ let object = {
+ prototype() { },
+ get [name]() { },
+ };
+
+ shouldBe(JSON.stringify(Object.getOwnPropertyDescriptor(object, 'prototype')), `{"enumerable":true,"configurable":true}`);
+}
+
+{
+ let name = 'prototype';
+ let object = {
+ get [name]() { },
+ prototype() { },
+ };
+
+ shouldBe(JSON.stringify(Object.getOwnPropertyDescriptor(object, 'prototype')), `{"writable":true,"enumerable":true,"configurable":true}`);
+}
+
+
+{
+ let name = 'prototype';
+ let object = {
+ [name]() { },
+ get prototype() { },
+ };
+
+ shouldBe(JSON.stringify(Object.getOwnPropertyDescriptor(object, 'prototype')), `{"enumerable":true,"configurable":true}`);
+}
+
+{
+ let name = 'prototype';
+ let object = {
+ get prototype() { },
+ [name]() { },
+ };
+
+ shouldBe(JSON.stringify(Object.getOwnPropertyDescriptor(object, 'prototype')), `{"writable":true,"enumerable":true,"configurable":true}`);
+}
+
+{
+ let object = {
+ __proto__() { }
+ };
+ shouldBe(JSON.stringify(Object.getOwnPropertyDescriptor(object, '__proto__')), `{"writable":true,"enumerable":true,"configurable":true}`);
+ shouldBe(Object.getPrototypeOf(object), Object.prototype);
+}
+
+{
+ let name = '__proto__';
+ let object = {
+ [name]() { }
+ };
+ shouldBe(JSON.stringify(Object.getOwnPropertyDescriptor(object, '__proto__')), `{"writable":true,"enumerable":true,"configurable":true}`);
+ shouldBe(Object.getPrototypeOf(object), Object.prototype);
+}
+
+{
+ let name = '42';
+ let object = {
+ 42() { },
+ get [name]() { },
+ };
+
+ shouldBe(JSON.stringify(Object.getOwnPropertyDescriptor(object, '42')), `{"enumerable":true,"configurable":true}`);
+}
+
+{
+ let name = '42';
+ let object = {
+ get [name]() { },
+ 42() { },
+ };
+
+ shouldBe(JSON.stringify(Object.getOwnPropertyDescriptor(object, '42')), `{"writable":true,"enumerable":true,"configurable":true}`);
+}
+
+
+{
+ let name = '42';
+ let object = {
+ [name]() { },
+ get 42() { },
+ };
+
+ shouldBe(JSON.stringify(Object.getOwnPropertyDescriptor(object, '42')), `{"enumerable":true,"configurable":true}`);
+}
+
+{
+ let name = '42';
+ let object = {
+ get 42() { },
+ [name]() { },
+ };
+
+ shouldBe(JSON.stringify(Object.getOwnPropertyDescriptor(object, '42')), `{"writable":true,"enumerable":true,"configurable":true}`);
+}
+
+
Modified: trunk/Source/_javascript_Core/ChangeLog (206081 => 206082)
--- trunk/Source/_javascript_Core/ChangeLog 2016-09-18 17:36:31 UTC (rev 206081)
+++ trunk/Source/_javascript_Core/ChangeLog 2016-09-18 17:40:11 UTC (rev 206082)
@@ -1,3 +1,38 @@
+2016-09-18 Yusuke Suzuki <utatane....@gmail.com>
+
+ [JSC] Do not need to use defineProperty to define methods for object literals
+ https://bugs.webkit.org/show_bug.cgi?id=162111
+
+ Reviewed by Saam Barati.
+
+ When we receive the following code,
+
+ var object = { method() { } };
+
+ currently, we use defineProperty to define "method" function for "object".
+ This patch replaces it with the ordinary put_by_id_direct / put_by_val_direct
+ because the following 2 conditions are met.
+
+ 1. While methods in classes have special attributes ({configurable: true, writable: true, enumerable: false}),
+ the attributes of methods in object literals is just the same to the other normal properties ({configurable: true, writable: true, enumerable: true}).
+ This means that we can use the usual put_by_id_direct / put_by_val_direct to define method properties for object literals.
+
+ 2. Furthermore, all the own properties that can reside in objects created by object literals have {configurable: true}.
+ So there is no need to check conflict by defineProperty. Always overwriting is OK.
+
+ let name = 'method';
+ var object = { get [name]() { }, method() { } };
+ // Latter method wins.
+
+ On the other hand, in class syntax, conflict check is necessary since "prototype" own property is defined as {configurable: false}.
+
+ class Hello { static prototype() { } } // Should throw error by defineProperty's check.
+
+ This means that conflict check done in defneProperty is not necessary for object literals' properties.
+
+ * bytecompiler/NodesCodegen.cpp:
+ (JSC::PropertyListNode::emitPutConstantProperty):
+
2016-09-16 Yusuke Suzuki <utatane....@gmail.com>
[DFG] Introduce IsCellWithType node and unify IsJSArray, IsRegExpObject and newly added IsProxyObject
Modified: trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp (206081 => 206082)
--- trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp 2016-09-18 17:36:31 UTC (rev 206081)
+++ trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp 2016-09-18 17:40:11 UTC (rev 206082)
@@ -587,9 +587,11 @@
void PropertyListNode::emitPutConstantProperty(BytecodeGenerator& generator, RegisterID* newObj, PropertyNode& node)
{
RefPtr<RegisterID> value = generator.emitNode(node.m_assign);
- if (node.needsSuperBinding()) {
+ if (node.needsSuperBinding())
emitPutHomeObject(generator, value.get(), newObj);
+ if (node.isClassProperty()) {
+ ASSERT(node.needsSuperBinding());
RefPtr<RegisterID> propertyNameRegister;
if (node.name())
propertyNameRegister = generator.emitLoad(generator.newTemporary(), *node.name());
@@ -596,12 +598,8 @@
else
propertyNameRegister = generator.emitNode(node.m_expression);
- unsigned attributes = BytecodeGenerator::PropertyConfigurable | BytecodeGenerator::PropertyWritable;
- if (!node.isClassProperty())
- attributes |= BytecodeGenerator::PropertyEnumerable;
generator.emitSetFunctionNameIfNeeded(node.m_assign, value.get(), propertyNameRegister.get());
- generator.emitCallDefineProperty(newObj, propertyNameRegister.get(),
- value.get(), nullptr, nullptr, attributes, m_position);
+ generator.emitCallDefineProperty(newObj, propertyNameRegister.get(), value.get(), nullptr, nullptr, BytecodeGenerator::PropertyConfigurable | BytecodeGenerator::PropertyWritable, m_position);
return;
}
if (const auto* identifier = node.name()) {