Ignore:
Timestamp:
May 13, 2015, 6:32:25 PM (10 years ago)
Author:
[email protected]
Message:

ES6: Allow duplicate property names
https://bugs.webkit.org/show_bug.cgi?id=142895

Patch by Joseph Pecoraro <Joseph Pecoraro> on 2015-05-13
Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

Introduce new op_put_getter_by_id and op_put_setter_by_id opcodes
that will define a single getter or setter property on an object.

The existing op_put_getter_setter opcode is still preferred for
putting both a getter and setter at the same time but cannot be used
for putting an individual getter or setter which is needed in
some cases.

Add a new slow path when generating bytecodes for a property list
with computed properties, as computed properties are the only time
the list of properties cannot be determined statically.

  • bytecompiler/NodesCodegen.cpp:

(JSC::PropertyListNode::emitBytecode):

  • fast path for all constant properties
  • slow but paired getter/setter path if there are no computed properties
  • slow path, individual put operation for every property, if there are computed properties
  • parser/Nodes.h:

Distinguish a Computed property from a Constant property.

  • parser/Parser.cpp:

(JSC::Parser<LexerType>::parseProperty):
(JSC::Parser<LexerType>::parsePropertyMethod):
Distingish Computed and Constant properties.

(JSC::Parser<LexerType>::parseObjectLiteral):
When we drop into strict mode it is because we saw a getter
or setter, so be more explicit.

(JSC::Parser<LexerType>::parseStrictObjectLiteral):
Eliminate duplicate property syntax error exception.

  • parser/SyntaxChecker.h:

(JSC::SyntaxChecker::getName):

  • parser/ASTBuilder.h:

(JSC::ASTBuilder::getName): Deleted.
No longer used.

  • runtime/JSObject.h:

(JSC::JSObject::putDirectInternal):
When updating a property. If the Accessor attribute changed
update the Structure.

  • runtime/JSObject.cpp:

(JSC::JSObject::putGetter):
(JSC::JSObject::putSetter):
Called by the opcodes, just perform the same operation that
defineGetter or defineSetter would do.

(JSC::JSObject::putDirectNonIndexAccessor):
This transition is now handled in putDirectInternal.

  • runtime/Structure.h:

Add needed export.

  • bytecode/BytecodeList.json:
  • bytecode/BytecodeUseDef.h:

(JSC::computeUsesForBytecodeOffset):
(JSC::computeDefsForBytecodeOffset):

  • bytecode/CodeBlock.cpp:

(JSC::CodeBlock::dumpBytecode):

  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::emitPutGetterById):
(JSC::BytecodeGenerator::emitPutSetterById):

  • bytecompiler/BytecodeGenerator.h:
  • jit/JIT.cpp:

(JSC::JIT::privateCompileMainPass):

  • jit/JIT.h:
  • jit/JITInlines.h:

(JSC::JIT::callOperation):

  • jit/JITOperations.cpp:
  • jit/JITOperations.h:
  • jit/JITPropertyAccess.cpp:

(JSC::JIT::emit_op_put_getter_by_id):
(JSC::JIT::emit_op_put_setter_by_id):

  • jit/JITPropertyAccess32_64.cpp:

(JSC::JIT::emit_op_put_getter_by_id):
(JSC::JIT::emit_op_put_setter_by_id):

  • llint/LLIntSlowPaths.cpp:

(JSC::LLInt::LLINT_SLOW_PATH_DECL):

  • llint/LLIntSlowPaths.h:
  • llint/LowLevelInterpreter.asm:

New bytecodes. Modelled after existing op_put_getter_setter.

LayoutTests:

  • js/object-literal-duplicate-properties-expected.txt: Added.
  • js/object-literal-duplicate-properties.html: Added.
  • js/script-tests/object-literal-duplicate-properties.js: Added.

Include a new test all about testing duplicate property names
and their expected cascading results.

  • ietestcenter/Javascript/11.1.5_4-4-b-1-expected.txt:
  • ietestcenter/Javascript/11.1.5_4-4-b-2-expected.txt:
  • ietestcenter/Javascript/11.1.5_4-4-c-1-expected.txt:
  • ietestcenter/Javascript/11.1.5_4-4-c-2-expected.txt:
  • ietestcenter/Javascript/11.1.5_4-4-d-1-expected.txt:
  • ietestcenter/Javascript/11.1.5_4-4-d-2-expected.txt:
  • ietestcenter/Javascript/11.1.5_4-4-d-3-expected.txt:
  • ietestcenter/Javascript/11.1.5_4-4-d-4-expected.txt:

ES5 behavior for duplciate properties has changed.

  • js/mozilla/strict/11.1.5-expected.txt:
  • js/object-literal-syntax-expected.txt:
  • js/script-tests/object-literal-syntax.js:

Update other tests and values now that duplicate properties
are allowed, and their cascade order behaves correctly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/jit/JITOperations.cpp

    r183631 r184324  
    12801280
    12811281#if USE(JSVALUE64)
     1282void JIT_OPERATION operationPutGetterById(ExecState* exec, EncodedJSValue encodedObjectValue, Identifier* identifier, EncodedJSValue encodedGetterValue)
     1283{
     1284    VM& vm = exec->vm();
     1285    NativeCallFrameTracer tracer(&vm, exec);
     1286
     1287    ASSERT(JSValue::decode(encodedObjectValue).isObject());
     1288    JSObject* baseObj = asObject(JSValue::decode(encodedObjectValue));
     1289
     1290    JSValue getter = JSValue::decode(encodedGetterValue);
     1291    ASSERT(getter.isObject());
     1292    baseObj->putGetter(exec, *identifier, asObject(getter));
     1293}
     1294
     1295void JIT_OPERATION operationPutSetterById(ExecState* exec, EncodedJSValue encodedObjectValue, Identifier* identifier, EncodedJSValue encodedSetterValue)
     1296{
     1297    VM& vm = exec->vm();
     1298    NativeCallFrameTracer tracer(&vm, exec);
     1299
     1300    ASSERT(JSValue::decode(encodedObjectValue).isObject());
     1301    JSObject* baseObj = asObject(JSValue::decode(encodedObjectValue));
     1302
     1303    JSValue setter = JSValue::decode(encodedSetterValue);
     1304    ASSERT(setter.isObject());
     1305    baseObj->putSetter(exec, *identifier, asObject(setter));
     1306}
     1307
    12821308void JIT_OPERATION operationPutGetterSetter(ExecState* exec, EncodedJSValue encodedObjectValue, Identifier* identifier, EncodedJSValue encodedGetterValue, EncodedJSValue encodedSetterValue)
    12831309{
     
    13031329}
    13041330#else
     1331void JIT_OPERATION operationPutGetterById(ExecState* exec, JSCell* object, Identifier* identifier, JSCell* getter)
     1332{
     1333    VM& vm = exec->vm();
     1334    NativeCallFrameTracer tracer(&vm, exec);
     1335
     1336    ASSERT(object && object->isObject());
     1337    JSObject* baseObj = object->getObject();
     1338
     1339    ASSERT(getter->isObject());
     1340    baseObj->putGetter(exec, *identifier, getter);
     1341}
     1342
     1343void JIT_OPERATION operationPutSetterById(ExecState* exec, JSCell* object, Identifier* identifier, JSCell* setter)
     1344{
     1345    VM& vm = exec->vm();
     1346    NativeCallFrameTracer tracer(&vm, exec);
     1347
     1348    ASSERT(object && object->isObject());
     1349    JSObject* baseObj = object->getObject();
     1350
     1351    ASSERT(setter->isObject());
     1352    baseObj->putSetter(exec, *identifier, setter);
     1353}
     1354
    13051355void JIT_OPERATION operationPutGetterSetter(ExecState* exec, JSCell* object, Identifier* identifier, JSCell* getter, JSCell* setter)
    13061356{
Note: See TracChangeset for help on using the changeset viewer.