2016-04-07 3 views
0

Rhino 1.5 R5(Rhino 1.5リリース5 2004 03 25)を使用しているアプリで評価されているJavaScriptに問題があります。 Rhinoを個別に更新することはできません。Rhino 1.5 R5で配列の相違が見つかったときにJavaScriptが正しく評価されない

私は2つの配列を持っています:元のデータ(pastedArr)と有効な値(validatedArr)の配列だけで、その差異(「不良」値)を見つけようとしています。私はオンラインで(sym)を助けるための関数を見つけました。私はforEachのプロトタイプを作成しなければなりませんでしたが、それは完全にjsfiddle(https://jsfiddle.net/zr3abc0c/)で動作します。

Rhinoを使用しているアプリケーションでは、以下のスクリプトやjsfiddleでは「33」を返すフィドルリンクのように(文字列として格納されていても)整数である要素は返されません私のアプリケーション。 parameter0が["33"、 "1A"、 "ABC"]だった場合、アプリ内の["1A"、 "ABC"]のみが返されます。

これらの「整数」文字列要素では、どこが失敗しているのかわかりません。

// Production steps of ECMA-262, Edition 5, 15.4.4.18 
 
// Reference: http://es5.github.io/#x15.4.4.18 
 
if (!Array.prototype.forEach) { 
 

 
    Array.prototype.forEach = function(callback, thisArg) { 
 

 
    var T, k; 
 

 
    if (this == null) { 
 
     throw new TypeError(' this is null or not defined'); 
 
    } 
 

 
    // 1. Let O be the result of calling toObject() passing the 
 
    // |this| value as the argument. 
 
    var O = Object(this); 
 

 
    // 2. Let lenValue be the result of calling the Get() internal 
 
    // method of O with the argument "length". 
 
    // 3. Let len be toUint32(lenValue). 
 
    var len = O.length >>> 0; 
 

 
    // 4. If isCallable(callback) is false, throw a TypeError exception. 
 
    // See: http://es5.github.com/#x9.11 
 
    if (typeof callback !== "function") { 
 
     throw new TypeError(callback + ' is not a function'); 
 
    } 
 

 
    // 5. If thisArg was supplied, let T be thisArg; else let 
 
    // T be undefined. 
 
    if (arguments.length > 1) { 
 
     T = thisArg; 
 
    } 
 

 
    // 6. Let k be 0 
 
    k = 0; 
 

 
    // 7. Repeat, while k < len 
 
    while (k < len) { 
 

 
     var kValue; 
 

 
     // a. Let Pk be ToString(k). 
 
     // This is implicit for LHS operands of the in operator 
 
     // b. Let kPresent be the result of calling the HasProperty 
 
     // internal method of O with argument Pk. 
 
     // This step can be combined with c 
 
     // c. If kPresent is true, then 
 
     if (k in O) { 
 

 
     // i. Let kValue be the result of calling the Get internal 
 
     // method of O with argument Pk. 
 
     kValue = O[k]; 
 

 
     // ii. Call the Call internal method of callback with T as 
 
     // the this value and argument list containing kValue, k, and O. 
 
     callback.call(T, kValue, k, O); 
 
     } 
 
     // d. Increase k by 1. 
 
     k++; 
 
    } 
 
    // 8. return undefined 
 
    }; 
 
} 
 

 
function sym(/* pass one or more arrays here */) { 
 
    var ans = [], 
 
    cnts = {}, 
 
    currentMap; 
 

 
    //count all items in the array 
 
    for (var i = 0; i < arguments.length; i++) { 
 
    currentMap = {}; 
 
    arguments[i].forEach(function(item) { 
 
     // if we haven't already counted this item in this array 
 
     if (!currentMap.hasOwnProperty(item)) { 
 
     if (cnts.hasOwnProperty(item)) { 
 
      // increase cnt 
 
      ++cnts[item].cnt; 
 
     } else { 
 
      // initalize cnt and value 
 
      cnts[item] = { 
 
      cnt: 1, 
 
      val: item 
 
      }; 
 
     } 
 
     } 
 
     // keep track of whethere we've already counted this item in this array 
 
     currentMap[item] = true; 
 
    }); 
 
    } 
 
    // output all items that have a cnt of 1 
 
    for (var item in cnts) { 
 
    if (cnts.hasOwnProperty(item) && cnts[item].cnt === 1) { 
 
     ans.push(cnts[item].val); 
 
    } 
 
    } 
 

 
    return ans; 
 
} 
 

 
function sort_uniq_fast(a) { 
 
    var seen = {}; 
 
    var out = []; 
 
    var len = a.length; 
 
    var j = 0; 
 
    for (var i = 0; i < len; i++) { 
 
    var item = a[i]; 
 
    if (seen[item] !== 1) { 
 
     seen[item] = 1; 
 
     out[j++] = item; 
 
    } 
 
    } 
 
    return out.sort(); 
 
} 
 

 
function getBadCodes(pastedArr, validatedArr) { 
 
    var result = sym(pastedArr, validatedArr); 
 
    return sort_uniq_fast(result); 
 
} 
 

 
    var parameter0 = ["33"]; 
 
    var parameter1 = new Array(); 
 

 
alert(getBadCodes(parameter0,parameter1));

答えて

1

私はRhinoの1.5R5が転がっていませんが、Rhinoは理由アレイでの使用のため、特別なとして整数の性質を扱います。私はRhino 1.5R5でこの処理にバグがあると推測しています。

この回答(プレフィックスとプレフィックスを参照)のように、結果を比較して後処理するアイテムを前処理することをお勧めします。

動作しているかどうかをお知らせください。 (そして、私はそれに応じて答えを更新します。)

// Production steps of ECMA-262, Edition 5, 15.4.4.18 
 
// Reference: http://es5.github.io/#x15.4.4.18 
 
if (!Array.prototype.forEach) { 
 

 
    Array.prototype.forEach = function(callback, thisArg) { 
 

 
    var T, k; 
 

 
    if (this == null) { 
 
     throw new TypeError(' this is null or not defined'); 
 
    } 
 

 
    // 1. Let O be the result of calling toObject() passing the 
 
    // |this| value as the argument. 
 
    var O = Object(this); 
 

 
    // 2. Let lenValue be the result of calling the Get() internal 
 
    // method of O with the argument "length". 
 
    // 3. Let len be toUint32(lenValue). 
 
    var len = O.length >>> 0; 
 

 
    // 4. If isCallable(callback) is false, throw a TypeError exception. 
 
    // See: http://es5.github.com/#x9.11 
 
    if (typeof callback !== "function") { 
 
     throw new TypeError(callback + ' is not a function'); 
 
    } 
 

 
    // 5. If thisArg was supplied, let T be thisArg; else let 
 
    // T be undefined. 
 
    if (arguments.length > 1) { 
 
     T = thisArg; 
 
    } 
 

 
    // 6. Let k be 0 
 
    k = 0; 
 

 
    // 7. Repeat, while k < len 
 
    while (k < len) { 
 

 
     var kValue; 
 

 
     // a. Let Pk be ToString(k). 
 
     // This is implicit for LHS operands of the in operator 
 
     // b. Let kPresent be the result of calling the HasProperty 
 
     // internal method of O with argument Pk. 
 
     // This step can be combined with c 
 
     // c. If kPresent is true, then 
 
     if (k in O) { 
 

 
     // i. Let kValue be the result of calling the Get internal 
 
     // method of O with argument Pk. 
 
     kValue = O[k]; 
 

 
     // ii. Call the Call internal method of callback with T as 
 
     // the this value and argument list containing kValue, k, and O. 
 
     callback.call(T, kValue, k, O); 
 
     } 
 
     // d. Increase k by 1. 
 
     k++; 
 
    } 
 
    // 8. return undefined 
 
    }; 
 
} 
 

 
function sym(/* pass one or more arrays here */) { 
 
    var ans = [], 
 
    cnts = {}, 
 
    currentMap; 
 

 
    //count all items in the array 
 
    for (var i = 0; i < arguments.length; i++) { 
 
    currentMap = {}; 
 
    arguments[i].forEach(function(item) { 
 
     // if we haven't already counted this item in this array 
 
     if (!currentMap.hasOwnProperty(item)) { 
 
     if (cnts.hasOwnProperty(item)) { 
 
      // increase cnt 
 
      ++cnts[item].cnt; 
 
     } else { 
 
      // initalize cnt and value 
 
      cnts[item] = { 
 
      cnt: 1, 
 
      val: item 
 
      }; 
 
     } 
 
     } 
 
     // keep track of whethere we've already counted this item in this array 
 
     currentMap[item] = true; 
 
    }); 
 
    } 
 
    // output all items that have a cnt of 1 
 
    for (var item in cnts) { 
 
    if (cnts.hasOwnProperty(item) && cnts[item].cnt === 1) { 
 
     ans.push(cnts[item].val); 
 
    } 
 
    } 
 

 
    return ans; 
 
} 
 

 
function sort_uniq_fast(a) { 
 
    var seen = {}; 
 
    var out = []; 
 
    var len = a.length; 
 
    var j = 0; 
 
    for (var i = 0; i < len; i++) { 
 
    var item = a[i]; 
 
    if (seen[item] !== 1) { 
 
     seen[item] = 1; 
 
     out[j++] = item; 
 
    } 
 
    } 
 
    return out.sort(); 
 
} 
 

 
function prefix(array) { 
 
    var rv = []; 
 
    for (var i=0; i<array.length; i++) { 
 
     rv[i] = "A" + array[i]; 
 
    } 
 
    return rv; 
 
} 
 

 
function unprefix(array) { 
 
    var rv = []; 
 
    for (var i=0; i<array.length; i++) { 
 
     rv[i] = array[i].substring(1); 
 
    } 
 
    return rv; 
 
} 
 

 
function getBadCodes(pastedArr, validatedArr) { 
 
    var result = unprefix(sym(prefix(pastedArr), prefix(validatedArr))); 
 
    return sort_uniq_fast(result); 
 
} 
 

 
    var parameter0 = ["33"]; 
 
    var parameter1 = new Array(); 
 

 
alert(getBadCodes(parameter0,parameter1));

+0

これは、作業を行い、記載された問題を解決し、しかし、それは別の問題を公開します。 var parameter0 = [null、 "1a"、 "33"、 "33-D-1A"]; var parameter1 = ["33-D-1A"]; これは、インタフェース/ユーザにnullを表示する["1a"、 "33"、 "null"]を返すようになりました – trueimage

+0

@ david-p-caldwell Iプレフィックス関数にif節を追加しました。 'function prefix(array){ var rv = [];for(var i = 0; i trueimage

+0

ええ、記載されたアプローチは「null」では機能しません。あなたのケースでnullの「正しい」処理は何でしょうか? –

関連する問題