⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 211070 in webkit


Ignore:
Timestamp:
Jan 23, 2017, 4:15:21 PM (10 years ago)
Author:
sbarati@apple.com
Message:

https://bugs.webkit.org/show_bug.cgi?id=167247
JSC: operationSpreadGeneric uses the wrong global object for the builtin function and slow_path_spread consults the wrong global object to prove if the iterator protocol is unobservable
<rdar://problem/30121809>

Reviewed by Filip Pizlo.

JSTests:

  • stress/spread-consults-correct-global-object.js: Added.

(assert):
(spread):

  • stress/spread-correct-global-object-on-exception.js: Added.

(assert):
(spread):
(const.objectText.let.o.Symbol.iterator):
(catch):

Source/JavaScriptCore:

There were two bugs in the different tiers with respect to how
spread handled global objects.

The first was in the LLInt/baseline inside slow_path_spread:

We consulted the lexical global object instead of the thing we're
spreading's global object to determine if the array iterator protocol
is unobservable. This is wrong if the incoming array is from a different
global object. We must consult the incoming array's global object
to determine if it can be spread using the fast path.

The second was in operationSpreadGeneric in the DFG/FTL:

We were always using the incoming array's global object, even
when going down the slow path. This is wrong because we were
fetching the builtin iteration function helper from the incoming
array's global object, which meant that if the iterator function
were to throw an exception, it could leak objects from a different
global object. We should be executing the iterator function with
the lexical global object.

  • dfg/DFGOperations.cpp:
  • jsc.cpp:

(GlobalObject::finishCreation):
(functionGlobalObjectForObject):

  • runtime/CommonSlowPaths.cpp:

(JSC::SLOW_PATH_DECL):

  • runtime/JSArray.h:
  • runtime/JSArrayInlines.h:

(JSC::JSArray::isIteratorProtocolFastAndNonObservable):

Location:
trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r211017 r211070  
     12017-01-23  Saam Barati  <sbarati@apple.com>
     2
     3        https://bugs.webkit.org/show_bug.cgi?id=167247
     4        JSC: operationSpreadGeneric uses the wrong global object for the builtin function and slow_path_spread consults the wrong global object to prove if the iterator protocol is unobservable
     5        <rdar://problem/30121809>
     6
     7        Reviewed by Filip Pizlo.
     8
     9        * stress/spread-consults-correct-global-object.js: Added.
     10        (assert):
     11        (spread):
     12        * stress/spread-correct-global-object-on-exception.js: Added.
     13        (assert):
     14        (spread):
     15        (const.objectText.let.o.Symbol.iterator):
     16        (catch):
     17
    1182017-01-21  Yusuke Suzuki  <utatane.tea@gmail.com>
    219
  • trunk/Source/JavaScriptCore/ChangeLog

    r211069 r211070  
     12017-01-23  Saam Barati  <sbarati@apple.com>
     2
     3        https://bugs.webkit.org/show_bug.cgi?id=167247
     4        JSC: operationSpreadGeneric uses the wrong global object for the builtin function and slow_path_spread consults the wrong global object to prove if the iterator protocol is unobservable
     5        <rdar://problem/30121809>
     6
     7        Reviewed by Filip Pizlo.
     8
     9        There were two bugs in the different tiers with respect to how
     10        spread handled global objects.
     11       
     12        The first was in the LLInt/baseline inside slow_path_spread:
     13       
     14        We consulted the lexical global object instead of the thing we're
     15        spreading's global object to determine if the array iterator protocol
     16        is unobservable. This is wrong if the incoming array is from a different
     17        global object. We must consult the incoming array's global object
     18        to determine if it can be spread using the fast path.
     19       
     20        The second was in operationSpreadGeneric in the DFG/FTL:
     21       
     22        We were always using the incoming array's global object, even
     23        when going down the slow path. This is wrong because we were
     24        fetching the builtin iteration function helper from the incoming
     25        array's global object, which meant that if the iterator function
     26        were to throw an exception, it could leak objects from a different
     27        global object. We should be executing the iterator function with
     28        the lexical global object.
     29
     30        * dfg/DFGOperations.cpp:
     31        * jsc.cpp:
     32        (GlobalObject::finishCreation):
     33        (functionGlobalObjectForObject):
     34        * runtime/CommonSlowPaths.cpp:
     35        (JSC::SLOW_PATH_DECL):
     36        * runtime/JSArray.h:
     37        * runtime/JSArrayInlines.h:
     38        (JSC::JSArray::isIteratorProtocolFastAndNonObservable):
     39
    1402017-01-22  Filip Pizlo  <fpizlo@apple.com>
    241
  • trunk/Source/JavaScriptCore/dfg/DFGOperations.cpp

    r209638 r211070  
    4848#include "JIT.h"
    4949#include "JITExceptions.h"
     50#include "JSArrayInlines.h"
    5051#include "JSCInlines.h"
    5152#include "JSFixedArray.h"
     
    19851986    auto throwScope = DECLARE_THROW_SCOPE(vm);
    19861987
    1987     JSGlobalObject* globalObject = iterable->structure(vm)->globalObject();
    1988     if (!globalObject)
    1989         globalObject = exec->lexicalGlobalObject();
    1990 
    1991     if (isJSArray(iterable) && globalObject->isArrayIteratorProtocolFastAndNonObservable()) {
     1988    if (isJSArray(iterable)) {
    19921989        JSArray* array = jsCast<JSArray*>(iterable);
    1993         throwScope.release();
    1994         return JSFixedArray::createFromArray(exec, vm, array);
     1990        if (array->isIteratorProtocolFastAndNonObservable()) {
     1991            throwScope.release();
     1992            return JSFixedArray::createFromArray(exec, vm, array);
     1993        }
    19951994    }
    19961995
     
    19981997    // the iteration protocol builtin: https://bugs.webkit.org/show_bug.cgi?id=164520
    19991998
     1999    JSGlobalObject* globalObject = exec->lexicalGlobalObject();
    20002000    JSArray* array;
    20012001    {
     
    20232023    ASSERT(isJSArray(cell));
    20242024    JSArray* array = jsCast<JSArray*>(cell);
    2025     ASSERT(array->globalObject()->isArrayIteratorProtocolFastAndNonObservable());
     2025    ASSERT(array->isIteratorProtocolFastAndNonObservable());
    20262026
    20272027    return JSFixedArray::createFromArray(exec, vm, array);
  • trunk/Source/JavaScriptCore/jsc.cpp

    r211018 r211070  
    10121012static EncodedJSValue JSC_HOST_CALL functionIsRope(ExecState*);
    10131013static EncodedJSValue JSC_HOST_CALL functionCallerSourceOrigin(ExecState*);
     1014static EncodedJSValue JSC_HOST_CALL functionGlobalObjectForObject(ExecState*);
    10141015
    10151016struct Script {
     
    12351236        addFunction(vm, "isRope", functionIsRope, 1);
    12361237        addFunction(vm, "callerSourceOrigin", functionCallerSourceOrigin, 0);
     1238
     1239        addFunction(vm, "globalObjectForObject", functionGlobalObjectForObject, 1);
    12371240
    12381241        addFunction(vm, "is32BitPlatform", functionIs32BitPlatform, 0);
     
    21542157        return JSValue::encode(jsNull());
    21552158    return JSValue::encode(jsString(state, sourceOrigin.string()));
     2159}
     2160
     2161EncodedJSValue JSC_HOST_CALL functionGlobalObjectForObject(ExecState* exec)
     2162{
     2163    JSValue value = exec->argument(0);
     2164    RELEASE_ASSERT(value.isObject());
     2165    JSGlobalObject* globalObject = jsCast<JSObject*>(value)->globalObject();
     2166    RELEASE_ASSERT(globalObject);
     2167    return JSValue::encode(globalObject);
    21562168}
    21572169
  • trunk/Source/JavaScriptCore/runtime/CommonSlowPaths.cpp

    r208936 r211070  
    4444#include "IteratorOperations.h"
    4545#include "JIT.h"
     46#include "JSArrayInlines.h"
    4647#include "JSCInlines.h"
    4748#include "JSCJSValue.h"
     
    10351036    JSValue iterable = OP_C(2).jsValue();
    10361037
     1038    if (iterable.isCell() && isJSArray(iterable.asCell())) {
     1039        JSArray* array = jsCast<JSArray*>(iterable);
     1040        if (array->isIteratorProtocolFastAndNonObservable()) {
     1041            // JSFixedArray::createFromArray does not consult the prototype chain,
     1042            // so we must be sure that not consulting the prototype chain would
     1043            // produce the same value during iteration.
     1044            RETURN(JSFixedArray::createFromArray(exec, vm, array));
     1045        }
     1046    }
     1047
    10371048    JSGlobalObject* globalObject = exec->lexicalGlobalObject();
    1038 
    1039     if (iterable.isCell() && isJSArray(iterable.asCell()) && globalObject->isArrayIteratorProtocolFastAndNonObservable()) {
    1040         // JSFixedArray::createFromArray does not consult the prototype chain,
    1041         // so we must be sure that not consulting the prototype chain would
    1042         // produce the same value during iteration.
    1043         JSArray* array = jsCast<JSArray*>(iterable);
    1044         RETURN(JSFixedArray::createFromArray(exec, vm, array));
    1045     }
    10461049
    10471050    JSArray* array;
  • trunk/Source/JavaScriptCore/runtime/JSArray.h

    r211043 r211070  
    150150    JS_EXPORT_PRIVATE void fillArgList(ExecState*, MarkedArgumentBuffer&);
    151151    JS_EXPORT_PRIVATE void copyToArguments(ExecState*, VirtualRegister firstElementDest, unsigned offset, unsigned length);
     152
     153    bool isIteratorProtocolFastAndNonObservable();
    152154
    153155    static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype, IndexingType indexingType)
  • trunk/Source/JavaScriptCore/runtime/JSArrayInlines.h

    r209036 r211070  
    9494}
    9595
     96ALWAYS_INLINE bool JSArray::isIteratorProtocolFastAndNonObservable()
     97{
     98    return globalObject()->isArrayIteratorProtocolFastAndNonObservable();
     99}
     100
    96101} // namespace JSC
Note: See TracChangeset for help on using the changeset viewer.