silverme / base2

Automatically exported from code.google.com/p/base2
0 stars 0 forks source link

Null pointer error in Enumerable.reduce() in Rhino #102

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. With Rhino 1.7 release 1 2008 03 06 and base2.js from
http://base2.googlecode.com/svn/version/1.0(beta2)/src/base2.js
2. Load the code of base2.js in Rhino (readFile()) and evaluate it
3. Get error message

js: "..\..\lib\autopack.js#59(eval)", line 368: uncaught JavaScript runtime
exception: TypeError: Cannot convert null to an object.
        at ..\..\lib\autopack.js#59(eval):368
        at ..\..\lib\autopack.js#59(eval):205
        at ..\..\lib\autopack.js#59(eval):121 (_class)
        at ..\..\lib\autopack.js#59(eval):1413
        at ..\..\lib\autopack.js#59(eval):68

What is the expected output? What do you see instead?
I expect the base2.js file to run initially without errors, but its first
load fails because of a "null pointer exception".

What version of the product are you using? On what operating system?
Rhino 1.7 release 1 2008 03 06, and base2.js from
http://base2.googlecode.com/svn/version/1.0(beta2)/src/base2.js

Please provide any additional information below.
The cause of the issue seems located in the Enumerable.reduce() function.

Source code:
  reduce: function(object, block, result, context) {
    var initialised = arguments.length > 2;
    this.forEach (object, function(value, key) {
      if (initialised) { 
        result = block.call(context, result, value, key, object);
      } else { 
        result = value;
        initialised = true;
      }
    });
    return result;
  },

If the "object" argument is null, the forEach breaks in Rhino. Note that I
checked the value of this argument in FF3 and it doesn't break even if
object===null. 
In FF3, when object===null, it returns the "results" argument without
modifications.

So I guess that checking the value of "object" beforehand would fix the
issue in Rhino:
  reduce: function(object, block, result, context) {
    var initialised = arguments.length > 2;
        if (object) {
        this.forEach (object, function(value, key) {
          if (initialised) { 
            result = block.call(context, result, value, key, object);
          } else { 
            result = value;
            initialised = true;
          }
        });
        }
    return result;
  },

Original issue reported on code.google.com by kayhad...@gmail.com on 20 Nov 2008 at 4:36

GoogleCodeExporter commented 8 years ago
OS: Win XP

Original comment by kayhad...@gmail.com on 20 Nov 2008 at 4:37

GoogleCodeExporter commented 8 years ago
This should be fixed in version 1.0 of base2:

http://base2.googlecode.com/svn/version/1.0/

Original comment by dean.edw...@gmail.com on 17 Dec 2008 at 7:36