[webkit-changes] cvs commit: WebCore/layout-tests/fast/js array-every-expected.txt array-every.html array-foreach-expected.txt array-foreach.html array-some-expected.txt array-some.html

Geoffrey ggaren at opensource.apple.com
Wed Jun 29 18:19:48 PDT 2005


ggaren      05/06/29 18:19:47

  Modified:    .        ChangeLog
               kjs      array_object.cpp array_object.h
               .        ChangeLog
  Added:       layout-tests/fast/js array-every-expected.txt
                        array-every.html array-foreach-expected.txt
                        array-foreach.html array-some-expected.txt
                        array-some.html
  Log:
  JavaScriptCore:
  
  	Patch by Francisco Tolmasky <tolmasky at gmail.com>
  
  	- fixes http://bugzilla.opendarwin.org/show_bug.cgi?id=3667
  	Core JavaScript 1.5 Reference:Objects:Array:forEach
  
  	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 <tolmasky at gmail.com>
  
  	-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.
  
  Revision  Changes    Path
  1.727     +16 -0     JavaScriptCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/ChangeLog,v
  retrieving revision 1.726
  retrieving revision 1.727
  diff -u -r1.726 -r1.727
  --- ChangeLog	29 Jun 2005 20:59:09 -0000	1.726
  +++ ChangeLog	30 Jun 2005 01:19:41 -0000	1.727
  @@ -1,5 +1,21 @@
   2005-06-29  Geoffrey Garen  <ggaren at apple.com>
   
  +	Patch by Francisco Tolmasky <tolmasky at gmail.com>
  +
  +	- fixes http://bugzilla.opendarwin.org/show_bug.cgi?id=3667
  +	Core JavaScript 1.5 Reference:Objects:Array:forEach
  +
  +	See WebCore Changelog for layout tests added.
  +
  +        Reviewed by darin.
  +
  +        * kjs/array_object.cpp:
  +        (ArrayProtoFuncImp::call):
  +        * kjs/array_object.h:
  +        (KJS::ArrayProtoFuncImp::):
  +
  +2005-06-29  Geoffrey Garen  <ggaren at apple.com>
  +
   	Patch contributed by Oliver Hunt <ojh16 at student.canterbury.ac.nz>
   
   	-fixed http://bugzilla.opendarwin.org/show_bug.cgi?id=3743
  
  
  
  1.42      +50 -1     JavaScriptCore/kjs/array_object.cpp
  
  Index: array_object.cpp
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kjs/array_object.cpp,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- array_object.cpp	22 Jun 2005 00:48:47 -0000	1.41
  +++ array_object.cpp	30 Jun 2005 01:19:42 -0000	1.42
  @@ -390,7 +390,7 @@
   const ClassInfo ArrayPrototypeImp::info = {"Array", &ArrayInstanceImp::info, &arrayTable, 0};
   
   /* Source for array_object.lut.h
  - at begin arrayTable 13
  + at begin arrayTable 16
     toString       ArrayProtoFuncImp::ToString       DontEnum|Function 0
     toLocaleString ArrayProtoFuncImp::ToLocaleString DontEnum|Function 0
     concat         ArrayProtoFuncImp::Concat         DontEnum|Function 1
  @@ -403,6 +403,9 @@
     sort           ArrayProtoFuncImp::Sort           DontEnum|Function 1
     splice         ArrayProtoFuncImp::Splice         DontEnum|Function 2
     unshift        ArrayProtoFuncImp::UnShift        DontEnum|Function 1
  +  every          ArrayProtoFuncImp::Every          DontEnum|Function 5
  +  forEach        ArrayProtoFuncImp::ForEach        DontEnum|Function 5
  +  some           ArrayProtoFuncImp::Some           DontEnum|Function 5
   @end
   */
   
  @@ -443,6 +446,7 @@
     unsigned int length = thisObj.get(exec,lengthPropertyName).toUInt32(exec);
   
     Value result;
  +  
     switch (id) {
     case ToLocaleString:
       // TODO  - see 15.4.4.3
  @@ -767,6 +771,51 @@
       thisObj.put(exec, lengthPropertyName, result, DontEnum | DontDelete);
       break;
     }
  +  case Every:
  +  case ForEach:
  +  case Some: {
  +    //Documentation for these three is available at:
  +    //http://developer-test.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:every
  +    //http://developer-test.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:forEach
  +    //http://developer-test.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:some
  +    
  +    Object eachFunction = args[0].toObject(exec);
  +    
  +    if (!eachFunction.implementsCall()) {
  +      Object err = Error::create(exec,TypeError);
  +      exec->setException(err);
  +      return err;
  +    }
  +    
  +    Object applyThis = args[1].imp()->isUndefinedOrNull() ? exec->dynamicInterpreter()->globalObject() :  args[1].toObject(exec);
  +    
  +    if (id == Some || id == Every)
  +      result = Boolean(id == Every);
  +    else
  +      result = thisObj;
  +    
  +    for (unsigned k = 0; k < length && !exec->hadException(); ++k) {
  +      
  +      List eachArguments;
  +      
  +      eachArguments.append(thisObj.get(exec, k));
  +      eachArguments.append(Number(k));
  +      eachArguments.append(thisObj);
  +      
  +      bool predicateResult = eachFunction.call(exec, applyThis, eachArguments).toBoolean(exec);
  +      
  +      if (id == Every && !predicateResult) {
  +        result = Boolean(false);
  +        break;
  +      }
  +      if (id == Some && predicateResult) {
  +        result = Boolean(true);
  +        break;
  +      }
  +    }
  +    break;
  +  }
  +    
     default:
       assert(0);
       break;
  
  
  
  1.12      +2 -1      JavaScriptCore/kjs/array_object.h
  
  Index: array_object.h
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kjs/array_object.h,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- array_object.h	12 Dec 2002 09:20:02 -0000	1.11
  +++ array_object.h	30 Jun 2005 01:19:42 -0000	1.12
  @@ -44,7 +44,8 @@
       virtual Value call(ExecState *exec, Object &thisObj, const List &args);
   
       enum { ToString, ToLocaleString, Concat, Join, Pop, Push,
  -	   Reverse, Shift, Slice, Sort, Splice, UnShift };
  +          Reverse, Shift, Slice, Sort, Splice, UnShift, 
  +          Every, ForEach, Some };
     private:
       int id;
     };
  
  
  
  1.4339    +19 -0     WebCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebCore/ChangeLog,v
  retrieving revision 1.4338
  retrieving revision 1.4339
  diff -u -r1.4338 -r1.4339
  --- ChangeLog	30 Jun 2005 00:41:44 -0000	1.4338
  +++ ChangeLog	30 Jun 2005 01:19:42 -0000	1.4339
  @@ -1,3 +1,22 @@
  +2005-06-29  Geoffrey Garen  <ggaren at apple.com>
  +
  +	Contributed by Francisco Tolmasky <tolmasky at gmail.com>
  +
  +	-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.
  +
   2005-06-29  Bruce DiBello  <bdibello at apple.com>
   
           Reviewed by Geoff Garen
  
  
  
  1.1                  WebCore/layout-tests/fast/js/array-every-expected.txt
  
  Index: array-every-expected.txt
  ===================================================================
  1.0 Single Argument Testing
  The following tests every with one argument, the callback. It should print whether the arrays [12, 5, 8, 130, 44] and [12, 54, 18, 130, 44] solely contain numbers >= to 10 (false and true, respectively).
  
  false
  true
  
  2.0 Two Argument Testing
  The following tests every with two arguments, the callback and the applied "this" object. It should print whether the arrays [12, 5, 11, 130, 44] and [12, 54, 18, 130, 44] solely contain numbers >= to 11 (false and true, respectively).
  
  false
  true
  
  3.0 Array Mutation Tests
  These tests the affects of array mutation during execution of every.
  
  3.1 Array Element Removal
  This test is equivalent to 1.0, with the exception that it removes elements from the array on each visit. Both should thus yield "false" since undefined is not >= to 10.
  
  false
  false
  
  3.3 Array Element Addition
  This test is equivalent to 1.0, with that it test whether elements are >= 131 and it adds elements greater than 131 to the end of the list. However, both results should be false since every uses the original length to create the range it iterates over.
  
  false
  false
  
  3.2 Array Element Changing
  This test is equivalent to 1.0, with the exception that it changes elements in the array to be < 10 in reverse order. These elements should appear in their mutated form when reached by every, and thus both tests should result in "false".
  
  false
  false
  
  4.0 Exception Test
  This test uses a function that throws an exception, and thus halts the execution of every. There should thus be no output.
  
  
  5.0 Wrong Type for Callback Test This test sends in incorrect types for the callback parameter of every. An exception should be thrown in each case. There should be 6 type errors (and no crashes!):
  
  TypeError - Type error
  TypeError - Type error
  TypeError - Type error
  TypeError - Type error
  TypeError - Type error
  TypeError - Type error
  
  6.0 Early Abortion ("Short Circuiting") This test is nearly identical to 1.0, except that it prints upon every call to the designated callback function. Since every aborts as soon as it finds one element that does not qualify, the first array should print only twice, and the second all 5 times.
  
  Testing element 12...
  Testing element 5...
  Done with first array.
  Testing element 12...
  Testing element 54...
  Testing element 18...
  Testing element 130...
  Testing element 44...
  Done with second array.
  
  
  
  
  1.1                  WebCore/layout-tests/fast/js/array-every.html
  
  Index: array-every.html
  ===================================================================
  <html>
  <head>
  <script type="text/javascript">
  
  function print(str) {
      document.writeln(str+"<br/>");
  }
  
  if (window.layoutTestController)  layoutTestController.dumpAsText();
  </script>
  </head>
  <body>
  1.0 Single Argument Testing<br/>
  The following tests every with one argument, the callback.  It should print whether the arrays [12, 5, 8, 130, 44] and [12, 54, 18, 130, 44] solely contain numbers >= to 10 (false and true, respectively).<br/><br/>
  <script>
  function isBigEnough(element, index, array) {
      return (element >= 10);
  }
  
  print([12, 5, 8, 130, 44].every(isBigEnough));
  print([12, 54, 18, 130, 44].every(isBigEnough));
  </script>
  <br/>
  
  2.0 Two Argument Testing<br/>
  The following tests every with two arguments, the callback and the applied "this" object.  It should print whether the arrays [12, 5, 11, 130, 44] and [12, 54, 18, 130, 44] solely contain numbers >= to 11 (false and true, respectively).<br/><br/>
  <script>
      var predicate = {
          comparison:     11,
          isBigEnough:    function(s) {
              return (s >= comparison);
          }
      };
      
      print([12, 5, 10, 130, 44].every(isBigEnough), predicate);
      print([12, 54, 18, 130, 44].every(isBigEnough), predicate);
  
  </script>
  <br/>
  
  3.0 Array Mutation Tests<br/>
  These tests the affects of array mutation during execution of every.<br/><br/>
  3.1 Array Element Removal<br/>
  This test is equivalent to 1.0, with the exception that it removes elements from the array on each visit.  Both should thus yield "false" since undefined is not >= to 10.<br/><br/>
  
  <script>
  function isBigEnoughAndPop(element, index, array) {
      array.pop();
      return (element >= 10);
  }
  
  print([12, 5, 8, 130, 44].every(isBigEnoughAndPop));
  print([12, 54, 18, 130, 44].every(isBigEnoughAndPop));
  </script>
  <br/>
  
  3.3 Array Element Addition<br/>
  This test is equivalent to 1.0, with that it test whether elements are >= 131 and it adds elements greater than 131 to the end of the list.  However, both results should be false since every uses the original length to create the range it iterates over.<br/><br/>
  <script>
  function isBigEnoughAndPush(element, index, array) {
      array.push(131);
      return (element >= 131);
  }
  
  print([12, 5, 8, 130, 44].every(isBigEnoughAndPush));
  print([12, 54, 18, 130, 44].every(isBigEnoughAndPush));
  </script>
  <br/>
  
  3.2 Array Element Changing<br/>
  This test is equivalent to 1.0, with the exception that it changes elements in the array to be < 10 in reverse order. These elements should appear in their mutated form when reached by every, and thus both tests should result in "false".<br/><br/>
  <script>
  function isBigEnoughAndChange(element, index, array) {
      array[array.length-1-index]= 5;
      return (element >= 10);
  }
  
  print([12, 5, 8, 130, 44].every(isBigEnoughAndChange));
  print([12, 54, 18, 130, 44].every(isBigEnoughAndChange));
  </script>
  <br/>
  4.0 Exception Test<br/>
  This test uses a function that throws an exception, and thus halts the execution of every.  There should thus be no output.<br/><br/>
  <script>
  function isBigEnough(element, index, array) {
      if(index==1) throw exception();
      return (element >= 10);
  }
  
  print([12, 5, 8, 130, 44].every(isBigEnoughAndException));
  print([12, 54, 18, 130, 44].every(isBigEnoughAndException));
  
  </script>
  <br/>
  5.0 Wrong Type for Callback Test
  This test sends in incorrect types for the callback parameter of every.  An exception should be thrown in each case.  There should be 6 type errors (and no crashes!):<br/><br/>
  <script>
  
  try { [12, 5, 8, 130, 44].every(5) }
  catch (e) { print(e); }
  
  try { [12, 5, 8, 130, 44].every("wrong"); }
  catch (e) { print(e); }
  
  try { [12, 5, 8, 130, 44].every(new Object()); }
  catch (e) { print(e); }
  
  try { [12, 5, 8, 130, 44].every(null); }
  catch (e) { print(e); }
  
  try { [12, 5, 8, 130, 44].every(undefined); }
  catch (e) { print(e) }
  
  try { [12, 5, 8, 130, 44].every(); }
  catch (e) { print(e); }
  
  </script>
  <br/>
  6.0 Early Abortion ("Short Circuiting")
  This test is nearly identical to 1.0, except that it prints upon every call to the designated callback function.  Since every aborts as soon as it finds one element that does not qualify, the first array should print only twice, and the second all 5 times.<br/><br/>
  <script>
  function isBigEnough(element, index, array) {
      print("Testing element "+element+"...");
      return (element >= 10);
  }
  
  [12, 5, 8, 130, 44].every(isBigEnough);
  print("Done with first array.");
  [12, 54, 18, 130, 44].every(isBigEnough);
  print("Done with second array.");
  </script>
  </body>
  </html>
  
  
  1.1                  WebCore/layout-tests/fast/js/array-foreach-expected.txt
  
  Index: array-foreach-expected.txt
  ===================================================================
  1.0 Single Argument Testing
  The following tests forEach with one argument, the callback. It should print the contents of the array [2, 5, 9] alongside each index.
  
  [0] is 2
  [1] is 5
  [2] is 9
  
  2.0 Two Argument Testing
  The following tests forEach with two arguments, the callback and the applied "this" object. It should print the contents of the array.
  
  2
  5
  9
  
  3.0 Array Mutation Tests
  These tests the affects of array mutation during execution of forEach.
  
  3.1 Array Element Removal
  This test removes elements from the array, these elements should thus appear as undefined when reached by forEach.
  
  [0] is 2
  [1] is 5
  [2] is undefined
  
  3.2 Array Element Addition
  This test adds elements to the array, these elements should not appear since forEach uses the original length to create the range it iterates over. It should be identical to 1.0.
  
  [0] is 2
  [1] is 5
  [2] is 9
  
  3.3 Array Element Changing
  This test changes elements in the array, these elements should appear in their mutated form when reached by forEach.
  
  [0] is 2
  [1] is 5
  [2] is changed
  
  4.0 Exception Test
  This test uses a function that throws an exception, and thus halts the execution of forEach.
  
  [0] is 2
  [1] is 5
  
  5.0 Wrong Type for Callback Test This test sends in incorrect types for the callback parameter of forEach. An exception should be thrown in each case. There should be 6 type errors (and no crashes!):
  
  TypeError - Type error
  TypeError - Type error
  TypeError - Type error
  TypeError - Type error
  TypeError - Type error
  TypeError - Type error
  
  
  
  
  1.1                  WebCore/layout-tests/fast/js/array-foreach.html
  
  Index: array-foreach.html
  ===================================================================
  <html>
  <head>
  <script type="text/javascript">
  
  function print(str) {
      document.writeln(str+"<br/>");
  }
  
  if (window.layoutTestController)  layoutTestController.dumpAsText();
  </script>
  </head>
  <body>
  1.0 Single Argument Testing<br/>
  The following tests forEach with one argument, the callback.  It should print the contents of the array [2, 5, 9] alongside each index.<br/><br/>
  <script>
  function printElt(element, index, array) {
      print("[" + index + "] is " + element);
  }
  
  [2, 5, 9].forEach(printElt);
  </script>
  <br/>
  
  2.0 Two Argument Testing<br/>
  The following tests forEach with two arguments, the callback and the applied "this" object.  It should print the contents of the array.<br/><br/>
  <script>
      var writer = {
          sb:       [],
          write:    function (s) {
              this.sb.push(s);
          },
          writeln:  function (s) {
              this.write(s+"<br/>");
          },
          toString: function () {
              return this.sb.join("");
          }
      };
      
      [2, 5, 9].forEach(writer.writeln, writer);
      print(writer.toString());
  
  </script>
  
  3.0 Array Mutation Tests<br/>
  These tests the affects of array mutation during execution of forEach.<br/><br/>
  3.1 Array Element Removal<br/>
  This test removes elements from the array, these elements should thus appear as undefined when reached by forEach.<br/><br/>
  
  <script>
  function printEltAndPop(element, index, array) {
      print("[" + index + "] is " + element);
      array.pop();
  }
  
  [2, 5, 9].forEach(printEltAndPop);
  </script>
  <br/>
  
  3.2 Array Element Addition<br/>
  This test adds elements to the array, these elements should not appear since forEach uses the original length to create the range it iterates over.  It should be identical to 1.0.<br/><br/>
  <script>
  function printEltAndPush(element, index, array) {
      print("[" + index + "] is " + element);
      array.push(1);
  }
  
  [2, 5, 9].forEach(printEltAndPush);
  </script>
  <br/>
  
  3.3 Array Element Changing<br/>
  This test changes elements in the array, these elements should appear in their mutated form when reached by forEach.<br/><br/>
  <script>
  function printEltAndChange(element, index, array) {
      print("[" + index + "] is " + element);
      array[array.length-1-index]= "changed";
  }
  
  [2, 5, 9].forEach(printEltAndChange);
  </script>
  <br/>
  4.0 Exception Test<br/>
  This test uses a function that throws an exception, and thus halts the execution of forEach.<br/><br/>
  <script>
  function printEltAndException(element, index, array) {
      print("[" + index + "] is " + element);
      if(index==1) throw exception();
  }
  
  [2, 5, 9].forEach(printEltAndException);
  </script>
  <br/>
  5.0 Wrong Type for Callback Test
  This test sends in incorrect types for the callback parameter of forEach.  An exception should be thrown in each case.  There should be 6 type errors (and no crashes!):<br/><br/>
  <script>
  
  try { [2, 5, 9].forEach(5); }
  catch (e) { print(e); }
  
  try { [2, 5, 9].forEach("wrong"); }
  catch (e) { print(e); }
  
  try { [2, 5, 9].forEach(new Object()); }
  catch (e) { print(e); }
  
  try { [2, 5, 9].forEach(null); }
  catch (e) { print(e); }
  
  try { [2, 5, 9].forEach(undefined); }
  catch (e) { print(e) }
  
  try { [2, 5, 9].forEach(); }
  catch (e) { print(e); }
  
  </script>
  
  </body>
  </html>
  
  
  1.1                  WebCore/layout-tests/fast/js/array-some-expected.txt
  
  Index: array-some-expected.txt
  ===================================================================
  1.0 Single Argument Testing
  The following tests every with one argument, the callback. It should print whether the arrays [2, 5, 8, 1, 4] and [12, 5, 8, 1, 44] contain any numbers >= to 10 (false and true, respectively).
  
  false
  true
  
  2.0 Two Argument Testing
  The following tests every with two arguments, the callback and the applied "this" object. It should print whether the arrays [2, 5, 8, 1, 4] and [12, 5, 8, 1, 44] contain any numbers >= 8. Both should yield "true".
  
  true
  true
  
  3.0 Array Mutation Tests
  These tests the affects of array mutation during execution of some.
  
  3.1 Array Element Removal
  This test is equivalent to 1.0, with the exception that it tests whether elements are >= 44 instead of 10, and that it removes elements from the array on each visit. Both should thus yield "false" since undefined is not >= to 44.
  
  false
  false
  
  3.2 Array Element Addition
  This test is equivalent to 1.0, with the exception that it adds elements greater than 10 to the end of the list. However, the results should be the same as those in 1.0 since some uses the original length to create the range it iterates over.
  
  false
  true
  
  3.3 Array Element Changing
  This test is equivalent to 1.0, with the exception that it changes elements in the array to be > 10 in reverse order. These elements should appear in their mutated form when reached by every, and thus both tests should result in "true".
  
  true
  true
  
  4.0 Exception Test
  This test uses a function that throws an exception, and thus halts the execution of some. There should thus be no output.
  
  
  5.0 Wrong Type for Callback Test
  This test sends in incorrect types for the callback parameter of every. An exception should be thrown in each case. There should be 6 type errors (and no crashes!):
  
  TypeError - Type error
  TypeError - Type error
  TypeError - Type error
  TypeError - Type error
  TypeError - Type error
  TypeError - Type error
  
  6.0 Early Abortion ("Short Circuiting") This test is nearly identical to 1.0, except that it prints upon every call to the designated callback function. Since some aborts as soon as it finds one qualifying element, the first array should print 5 times, and the second only once.
  
  Testing element 2...
  Testing element 5...
  Testing element 8...
  Testing element 1...
  Testing element 4...
  Done with first array.
  Testing element 12...
  Done with second array.
  
  
  
  
  1.1                  WebCore/layout-tests/fast/js/array-some.html
  
  Index: array-some.html
  ===================================================================
  <html>
  <head>
  <script type="text/javascript">
  
  function print(str) {
      document.writeln(str+"<br/>");
  }
  
  if (window.layoutTestController)  layoutTestController.dumpAsText();
  </script>
  </head>
  <body>
  1.0 Single Argument Testing<br/>
  The following tests every with one argument, the callback.  It should print whether the arrays [2, 5, 8, 1, 4] and [12, 5, 8, 1, 44] contain any numbers >= to 10 (false and true, respectively).<br/><br/>
  <script>
  function isBigEnough(element, index, array) {
      return (element >= 10);
  }
  
  print([2, 5, 8, 1, 4].some(isBigEnough));
  print([12, 5, 8, 1, 44].some(isBigEnough));
  </script>
  <br/>
  
  2.0 Two Argument Testing<br/>
  The following tests every with two arguments, the callback and the applied "this" object.  It should print whether the arrays [2, 5, 8, 1, 4] and [12, 5, 8, 1, 44] contain any numbers >= 8. Both should yield "true".<br/><br/>
  <script>
      var predicate = {
          comparison:     8,
          isBigEnough:    function(s) {
              return (s >= this.comparison);
          }
      };
      
      print([2, 5, 8, 1, 4].some(predicate.isBigEnough, predicate));
      print([12, 5, 8, 1, 44].some(predicate.isBigEnough, predicate));
  
  </script>
  <br/>
  
  3.0 Array Mutation Tests<br/>
  These tests the affects of array mutation during execution of some.<br/><br/>
  3.1 Array Element Removal<br/>
  This test is equivalent to 1.0, with the exception that it tests whether elements are >= 44 instead of 10, and that it removes elements from the array on each visit.  Both should thus yield "false" since undefined is not >= to 44.<br/><br/>
  
  <script>
  function isBigEnoughAndPop(element, index, array) {
      array.pop();
      return (element >= 44);
  }
  
  print([2, 5, 8, 1, 4].some(isBigEnoughAndPop));
  print([12, 5, 8, 1, 44].some(isBigEnoughAndPop));
  </script>
  <br/>
  
  3.2 Array Element Addition<br/>
  This test is equivalent to 1.0, with the exception that it adds elements greater than 10 to the end of the list.  However, the results should be the same as those in 1.0 since some uses the original length to create the range it iterates over.<br/><br/>
  <script>
  function isBigEnoughAndPush(element, index, array) {
      array.push(11);
      return (element >= 10);
  }
  
  print([2, 5, 8, 1, 4].some(isBigEnoughAndPush));
  print([12, 5, 8, 1, 44].some(isBigEnoughAndPush));
  </script>
  <br/>
  
  3.3 Array Element Changing<br/>
  This test is equivalent to 1.0, with the exception that it changes elements in the array to be > 10 in reverse order. These elements should appear in their mutated form when reached by every, and thus both tests should result in "true".<br/><br/>
  <script>
  function isBigEnoughAndChange(element, index, array) {
      array[array.length-1-index]= 10;
      return (element >= 10);
  }
  
  print([2, 5, 8, 1, 4].some(isBigEnoughAndChange));
  print([12, 5, 8, 1, 44].some(isBigEnoughAndChange));
  </script>
  <br/>
  4.0 Exception Test<br/>
  This test uses a function that throws an exception, and thus halts the execution of some.  There should thus be no output.<br/><br/>
  <script>
  function isBigEnough(element, index, array) {
      throw exception();
      return (element >= 10);
  }
  
  print([2, 5, 8, 1, 4].some(isBigEnoughAndException));
  print([12, 5, 8, 1, 44].some(isBigEnoughAndException));
  
  </script>
  <br/>
  5.0 Wrong Type for Callback Test<br/>
  This test sends in incorrect types for the callback parameter of every.  An exception should be thrown in each case.  There should be 6 type errors (and no crashes!):<br/><br/>
  <script>
  
  try { [12, 5, 8, 1, 44].some(5) }
  catch (e) { print(e); }
  
  try { [12, 5, 8, 1, 44].some("wrong"); }
  catch (e) { print(e); }
  
  try { [12, 5, 8, 1, 44].some(new Object()); }
  catch (e) { print(e); }
  
  try { [12, 5, 8, 1, 44].some(null); }
  catch (e) { print(e); }
  
  try { [12, 5, 8, 1, 44].some(undefined); }
  catch (e) { print(e) }
  
  try { [12, 5, 8, 1, 44].some(); }
  catch (e) { print(e); }
  
  </script>
  <br/>
  6.0 Early Abortion ("Short Circuiting")
  This test is nearly identical to 1.0, except that it prints upon every call to the designated callback function.  Since some aborts as soon as it finds one qualifying element, the first array should print 5 times, and the second only once.<br/><br/>
  <script>
  function isBigEnough(element, index, array) {
      print("Testing element "+element+"...");
      return (element >= 10);
  }
  
  [2, 5, 8, 1, 4].some(isBigEnough);
  print("Done with first array.");
  [12, 5, 8, 1, 44].some(isBigEnough);
  print("Done with second array.");
  </script>
  </body>
  </html>
  
  



More information about the webkit-changes mailing list