Mantis Bugtracker

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0000348 [Yate - Yet Another Telephony Engine] module major always 2013-06-27 10:38 2013-07-15 14:34
Reporter folarte View Status public  
Assigned To
Priority normal Resolution fixed  
Status resolved   Product Version SVN
Summary 0000348: Javascript constant arrays / objects surprissing or bad behaviour.
Description This is two problems, which I think are related.

1.- When I create empty objects / arrays using {} / [] the __proto__ properties seem to be pulled into the object.

2.- This leads to a lot of fields appearing when I iterate the objects with a for(key in object). I think the internal fields should not be enumerable.

Following is a proof of concept code with the output. When using the ph() function new xx() version come out empty. I suspect this is because for..in correctly ignores the prototype, but when using the constant version they have the methods pulled down which leads to unexpected output ( and near disaster in the original code, which used constant objects to copy fields into messages ).

The print_r output clearly shows the methods safely tucked in the __proto__ for the new constructions, but pulled down for the constant ones.

Francisco Olarte.

Code:


function ph(name, obj) {
    Engine.output(name+":");
    for (k in obj) {
            Engine.output("\t"+k+":\t"+obj[k]+"\t"+typeof(obj[k]));
    }
}

ph("New object:", new Object());
ph("Constant empty objectEmpty2:", {});
ph("new Array:", new Array());
ph("constant empty array:", []);

newObject = new Object();
Engine.print_r(newObject);
emptyObject = {};
Engine.print_r(emptyObject);

newArray = new Array();
Engine.print_r(newArray);
emptyArray = [];
Engine.print_r(emptyArray);




Output:

New object::
Constant empty objectEmpty2::
        freeze: [function freeze()] function
        isFrozen: [function isFrozen()] function
        toString: [function toString()] function
        hasOwnProperty: [function hasOwnProperty()] function
new Array::
constant empty array::
        freeze: [function freeze()] function
        isFrozen: [function isFrozen()] function
        toString: [function toString()] function
        hasOwnProperty: [function hasOwnProperty()] function
        push: [function push()] function
        pop: [function pop()] function
        concat: [function concat()] function
        join: [function join()] function
        reverse: [function reverse()] function
        shift: [function shift()] function
        unshift: [function unshift()] function
        slice: [function slice()] function
        splice: [function splice()] function
        sort: [function sort()] function
        indexOf: [function indexOf()] function
        length: 0 number
'newObject' = '[object Object]' (JsObject)
  '__proto__' = '[object Object]' (JsObject)
    'freeze' = '[function freeze()]' (ExpFunction)
    'isFrozen' = '[function isFrozen()]' (ExpFunction)
    'toString' = '[function toString()]' (ExpFunction)
    'hasOwnProperty' = '[function hasOwnProperty()]' (ExpFunction)
'emptyObject' = '[object Object]' (JsObject)
  'freeze' = '[function freeze()]' (ExpFunction)
  'isFrozen' = '[function isFrozen()]' (ExpFunction)
  'toString' = '[function toString()]' (ExpFunction)
  'hasOwnProperty' = '[function hasOwnProperty()]' (ExpFunction)
'newArray' = '[object Array]' (JsArray)
  '__proto__' = '[object Array]' (JsArray)
    'freeze' = '[function freeze()]' (ExpFunction)
    'isFrozen' = '[function isFrozen()]' (ExpFunction)
    'toString' = '[function toString()]' (ExpFunction)
    'hasOwnProperty' = '[function hasOwnProperty()]' (ExpFunction)
    'push' = '[function push()]' (ExpFunction)
    'pop' = '[function pop()]' (ExpFunction)
    'concat' = '[function concat()]' (ExpFunction)
    'join' = '[function join()]' (ExpFunction)
    'reverse' = '[function reverse()]' (ExpFunction)
    'shift' = '[function shift()]' (ExpFunction)
    'unshift' = '[function unshift()]' (ExpFunction)
    'slice' = '[function slice()]' (ExpFunction)
    'splice' = '[function splice()]' (ExpFunction)
    'sort' = '[function sort()]' (ExpFunction)
    'indexOf' = '[function indexOf()]' (ExpFunction)
    'length' = '0' (NamedString)
'emptyArray' = '[object Array]' (JsArray)
  'freeze' = '[function freeze()]' (ExpFunction)
  'isFrozen' = '[function isFrozen()]' (ExpFunction)
  'toString' = '[function toString()]' (ExpFunction)
  'hasOwnProperty' = '[function hasOwnProperty()]' (ExpFunction)
  'push' = '[function push()]' (ExpFunction)
  'pop' = '[function pop()]' (ExpFunction)
  'concat' = '[function concat()]' (ExpFunction)
  'join' = '[function join()]' (ExpFunction)
  'reverse' = '[function reverse()]' (ExpFunction)
  'shift' = '[function shift()]' (ExpFunction)
  'unshift' = '[function unshift()]' (ExpFunction)
  'slice' = '[function slice()]' (ExpFunction)
  'splice' = '[function splice()]' (ExpFunction)
  'sort' = '[function sort()]' (ExpFunction)
  'indexOf' = '[function indexOf()]' (ExpFunction)
  'length' = '0' (NamedString)
Additional Information
Tags No tags attached.
Attached Files

- Relationships

-  Notes
(0000537)
oana (developer)
2013-07-15 14:34

Fixed in SVN rev. 5581 (2013-07-15).

- Issue History
Date Modified Username Field Change
2013-06-27 10:38 folarte New Issue
2013-07-11 12:12 paulc Status new => acknowledged
2013-07-15 14:34 oana Note Added: 0000537
2013-07-15 14:34 oana Status acknowledged => resolved
2013-07-15 14:34 oana Resolution open => fixed


Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker