Changeset 272411 in webkit


Ignore:
Timestamp:
Feb 5, 2021 6:26:44 AM (18 months ago)
Author:
Alexey Shvayka
Message:

Object.assign should throw for property creation on non-extensible target
https://bugs.webkit.org/show_bug.cgi?id=220712

Reviewed by Ross Kirsling.

JSTests:

  • stress/object-assign-fast-path.js:

Source/JavaScriptCore:

This performance-neutral change precludes Object.assign from taking the
fast path if target is a non-extensible JSFinalObject, which ensures
a TypeError is thrown for property creation via Set?.

Aligns JSC with the spec [1], V8, and SpiderMonkey.

[1]: https://tc39.es/ecma262/#sec-validateandapplypropertydescriptor (step 2.a)

  • runtime/ObjectConstructor.cpp:

(JSC::JSC_DEFINE_HOST_FUNCTION):

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r272406 r272411  
     12021-02-05  Alexey Shvayka  <shvaikalesh@gmail.com>
     2
     3        Object.assign should throw for property creation on non-extensible `target`
     4        https://bugs.webkit.org/show_bug.cgi?id=220712
     5
     6        Reviewed by Ross Kirsling.
     7
     8        * stress/object-assign-fast-path.js:
     9
    1102021-02-05  Yusuke Suzuki  <ysuzuki@apple.com>
    211
  • trunk/JSTests/stress/object-assign-fast-path.js

    r250025 r272411  
    164164    shouldBe(setterCalledWithValue, "world");
    165165}
     166{
     167    let object = Object.freeze({ foo: 1 });
     168    shouldBe(Object.assign(object, {}), object);
     169}
     170{
     171    let object = Object.preventExtensions({ foo: 1 });
     172    shouldBe(Object.assign(object, { foo: 2 }), object);
     173    shouldBe(object.foo, 2);
     174}
     175{
     176    let object = Object.preventExtensions({ foo: 1 });
     177    shouldThrow(() => {
     178        Object.assign(object, { bar: 2 });
     179    }, `TypeError: Attempted to assign to readonly property.`);
     180    shouldBe(object.bar, undefined);
     181}
  • trunk/Source/JavaScriptCore/ChangeLog

    r272406 r272411  
     12021-02-05  Alexey Shvayka  <shvaikalesh@gmail.com>
     2
     3        Object.assign should throw for property creation on non-extensible `target`
     4        https://bugs.webkit.org/show_bug.cgi?id=220712
     5
     6        Reviewed by Ross Kirsling.
     7
     8        This performance-neutral change precludes Object.assign from taking the
     9        fast path if `target` is a non-extensible JSFinalObject, which ensures
     10        a TypeError is thrown for property creation via [[Set]].
     11
     12        Aligns JSC with the spec [1], V8, and SpiderMonkey.
     13
     14        [1]: https://tc39.es/ecma262/#sec-validateandapplypropertydescriptor (step 2.a)
     15
     16        * runtime/ObjectConstructor.cpp:
     17        (JSC::JSC_DEFINE_HOST_FUNCTION):
     18
    1192021-02-05  Yusuke Suzuki  <ysuzuki@apple.com>
    220
  • trunk/Source/JavaScriptCore/runtime/ObjectConstructor.cpp

    r272364 r272411  
    274274    // FIXME: Extend this for non JSFinalObject. For example, we would like to use this fast path for function objects too.
    275275    // https://bugs.webkit.org/show_bug.cgi?id=185358
    276     bool targetCanPerformFastPut = jsDynamicCast<JSFinalObject*>(vm, target) && target->canPerformFastPutInlineExcludingProto(vm);
     276    bool targetCanPerformFastPut = jsDynamicCast<JSFinalObject*>(vm, target) && target->canPerformFastPutInlineExcludingProto(vm) && target->isStructureExtensible(vm);
    277277
    278278    Vector<RefPtr<UniquedStringImpl>, 8> properties;
Note: See TracChangeset for help on using the changeset viewer.