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/runtime/JSObject.cpp

    r184050 r184324  
    11981198}
    11991199
     1200void JSObject::putGetter(ExecState* exec, PropertyName propertyName, JSValue getter)
     1201{
     1202    PropertyDescriptor descriptor;
     1203    descriptor.setGetter(getter);
     1204    descriptor.setEnumerable(true);
     1205    descriptor.setConfigurable(true);
     1206    defineOwnProperty(this, exec, propertyName, descriptor, false);
     1207}
     1208
     1209void JSObject::putSetter(ExecState* exec, PropertyName propertyName, JSValue setter)
     1210{
     1211    PropertyDescriptor descriptor;
     1212    descriptor.setSetter(setter);
     1213    descriptor.setEnumerable(true);
     1214    descriptor.setConfigurable(true);
     1215    defineOwnProperty(this, exec, propertyName, descriptor, false);
     1216}
     1217
    12001218void JSObject::putDirectAccessor(ExecState* exec, PropertyName propertyName, JSValue value, unsigned attributes)
    12011219{
     
    12291247    PutPropertySlot slot(this);
    12301248    putDirectInternal<PutModeDefineOwnProperty>(vm, propertyName, value, attributes, slot);
    1231 
    1232     // putDirect will change our Structure if we add a new property. For
    1233     // getters and setters, though, we also need to change our Structure
    1234     // if we override an existing non-getter or non-setter.
    1235     if (slot.type() != PutPropertySlot::NewProperty)
    1236         setStructure(vm, Structure::attributeChangeTransition(vm, structure(vm), propertyName, attributes));
    12371249
    12381250    Structure* structure = this->structure(vm);
Note: See TracChangeset for help on using the changeset viewer.