Ignore:
Timestamp:
Jun 29, 2005, 6:19:47 PM (20 years ago)
Author:
ggaren
Message:

JavaScriptCore:

Patch by Francisco Tolmasky <[email protected]>

See WebCore Changelog for layout tests added.

Reviewed by darin.

  • kjs/array_object.cpp: (ArrayProtoFuncImp::call):
  • kjs/array_object.h: (KJS::ArrayProtoFuncImp::):

WebCore:

Contributed by Francisco Tolmasky <[email protected]>

-test cases for fix to http://bugzilla.opendarwin.org/show_bug.cgi?id=3667
Core JavaScript 1.5 Reference:Objects:Array:forEach

See JavaScriptCore Changelog for details on the patch.

Reviewed by darin.

Test cases added:

  • layout-tests/fast/js/array-every-expected.txt: Added.
  • layout-tests/fast/js/array-every.html: Added.
  • layout-tests/fast/js/array-foreach-expected.txt: Added.
  • layout-tests/fast/js/array-foreach.html: Added.
  • layout-tests/fast/js/array-some-expected.txt: Added.
  • layout-tests/fast/js/array-some.html: Added.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/array_object.cpp

    r9455 r9539  
    391391
    392392/* Source for array_object.lut.h
    393 @begin arrayTable 13
     393@begin arrayTable 16
    394394  toString       ArrayProtoFuncImp::ToString       DontEnum|Function 0
    395395  toLocaleString ArrayProtoFuncImp::ToLocaleString DontEnum|Function 0
     
    404404  splice         ArrayProtoFuncImp::Splice         DontEnum|Function 2
    405405  unshift        ArrayProtoFuncImp::UnShift        DontEnum|Function 1
     406  every          ArrayProtoFuncImp::Every          DontEnum|Function 5
     407  forEach        ArrayProtoFuncImp::ForEach        DontEnum|Function 5
     408  some           ArrayProtoFuncImp::Some           DontEnum|Function 5
    406409@end
    407410*/
     
    444447
    445448  Value result;
     449 
    446450  switch (id) {
    447451  case ToLocaleString:
     
    768772    break;
    769773  }
     774  case Every:
     775  case ForEach:
     776  case Some: {
     777    //Documentation for these three is available at:
     778    //http://developer-test.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:every
     779    //http://developer-test.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:forEach
     780    //http://developer-test.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:some
     781   
     782    Object eachFunction = args[0].toObject(exec);
     783   
     784    if (!eachFunction.implementsCall()) {
     785      Object err = Error::create(exec,TypeError);
     786      exec->setException(err);
     787      return err;
     788    }
     789   
     790    Object applyThis = args[1].imp()->isUndefinedOrNull() ? exec->dynamicInterpreter()->globalObject() :  args[1].toObject(exec);
     791   
     792    if (id == Some || id == Every)
     793      result = Boolean(id == Every);
     794    else
     795      result = thisObj;
     796   
     797    for (unsigned k = 0; k < length && !exec->hadException(); ++k) {
     798     
     799      List eachArguments;
     800     
     801      eachArguments.append(thisObj.get(exec, k));
     802      eachArguments.append(Number(k));
     803      eachArguments.append(thisObj);
     804     
     805      bool predicateResult = eachFunction.call(exec, applyThis, eachArguments).toBoolean(exec);
     806     
     807      if (id == Every && !predicateResult) {
     808        result = Boolean(false);
     809        break;
     810      }
     811      if (id == Some && predicateResult) {
     812        result = Boolean(true);
     813        break;
     814      }
     815    }
     816    break;
     817  }
     818   
    770819  default:
    771820    assert(0);
Note: See TracChangeset for help on using the changeset viewer.