コンソールからアクセスできるグローバル変数 NS があります。
NS.some_func();
NS は、と呼ばれるメソッドを使用して設定されます。extendSafe()
some_scope.extendSafe = function (o1, o2) {
var key;
for (key in o2) {
if (o2.hasOwnProperty(key) && o1.hasOwnProperty(key)) {
throw "naming collision: " + key;
}
o1[key] = o2[key];
}
return o1;
};
これは、呼び出されるパブリック スコープを設定し、すべての $P メソッドが定義されたら$P
グローバル スコープにコピーすることによって使用されます。NS
このようにしたいので、プロパティを上書きしていないことを確認できます。
$P
後で にコピーするためにローカル変数を に保存しようとするまで、これはうまくいきましたNS
。インタープリターは、$P がウィンドウ スコープに "解放" されることを認識していないため、ローカル変数をアクティブに保つことを認識していません。そのため、safeExtend メソッドを使用できません。
次のように直接コピーして、これが問題であることを確認しました。
NS.local = local;
コンソールから NS.local にアクセスできるようになりました。
ただし、やりたいようにコピーすると:
$P.local = local;
extendSafe(NS, $P);
ローカル変数は使用できません。
どうすれば安全に解放できsafeExtend()
ますか?
コードスニペット
問題は次のようにコメントされています
// hacked needs a fix
$P.machine = function (obj) {
var pipe,
data_send,
ajax_type,
wait_animation,
set;
wait_animation = document.getElementById('wait_animation');
set = false;
pipe = NS.makePipe(obj);
if ($R.Parsel[pipe.model] === undefined) {
return;
}
time('start');
if ($R.Parsel[pipe.model].hasOwnProperty("pre")) {
pipe = $R.Parsel[pipe.model].pre(pipe);
} else {
return;
}
if (pipe.form_data) {
ajax_type = 'multi';
var form_data = pipe.form_data;
delete pipe.form_data;
form_data.append("pipe", JSON.stringify(pipe));
data_send = form_data;
} else {
ajax_type = 'post';
data_send = 'pipe=' + encodeURIComponent(JSON.stringify(pipe));
}
if (pipe.state === true) {
time('middle');
if (wait_animation) {
set = true;
wait_animation.style.opacity = 1;
}
NS.ajax({
type: ajax_type,
url: NS.Reg.get('path') + NS.Reg.get('path_ajax'),
data: data_send,
callback: function (pipe_string_receive) {
var pass_prefix = pipe_string_receive.slice(0, 3),
times;
if (wait_animation && set) {
wait_animation.style.opacity = 0;
}
if (pass_prefix === '|D|') {
NS.log('|DEBUG| ' + pipe_string_receive.slice(3));
} else if (pass_prefix === '|A|') {
time('middle');
pipe = JSON.parse(pipe_string_receive.slice(3));
if ($R.Parsel[pipe.model].hasOwnProperty("post")) {
pipe = $R.Parsel[pipe.model].post(pipe);
times = time('finish');
pipe.time.pre = times[0];
pipe.time.transit = times[1];
pipe.time.post = times[2];
// works but hacked needs a fix
NS.last = pipe;
// will not exendSafe()
$P.last = pipe;
} else {
return;
}
} else {
throw "<No 'A' or 'D'>" + pipe_string_receive;
}
}
});
}
};