(注:このブログはもう更新していません)この日記は私的なものであり所属会社の見解とは無関係です。 GitHub: takahashikzn

[クラウド帳票エンジンDocurain]

jQuery-2.2.0をEnv.js上で動かすためにパッチを当てる

jQuery-2.2.0がリリースされています。

「まだjQueryで消耗してるの?」と言われそうですが、細かいDOM操作をするならjQueryは依然として非常に優れた選択肢です。

ウチはクローラーJavaで書いたりしている都合上、jQueryをEnv.js上で動かしているのですが、先ほどjQuery-2.2.0にアップデートしたら動かなくなりました。 こんなエラーになります。

org.mozilla.javascript.EcmaError: ReferenceError: "$implementation" is not defined. (env.rhino.js#4551)

そして4551行目付近は次の通りです。

    createHTMLDocument : function(title){
        var doc = new HTMLDocument($implementation, null, ""); // 4551行目
        var html = doc.createElement("html"); doc.appendChild(html);
        var head = doc.createElement("head"); html.appendChild(head);
        var body = doc.createElement("body"); html.appendChild(body);
        var t = doc.createElement("title"); head.appendChild(t);
        if( title) {
            t.appendChild(doc.createTextNode(title));
        }
        return doc;
    },

ソース全体を検索してみたのですが、$implementationという変数は未定義のようです。 何故いままで動作していたのか不明ですが、とりあえず次のようにパッチを当てたら動作するようになりました。

    createHTMLDocument : function(title){
        var doc = new HTMLDocument(new DOMImplementation(), null, ""); // ← 変更した行
        ... // (略)
    },

2016-03-04追記

var doc = new HTMLDocument(document.implementation, null, "");

でも良い模様です。

https://groups.google.com/forum/#!topic/envjs/bCLQ-VlmYAk