bug 788754: simplify SourceClient's api; r=past

This commit is contained in:
Nick Fitzgerald 2012-09-28 08:27:00 +03:00
Родитель 48f1ad12b4
Коммит 6a0adafae6
3 изменённых файлов: 36 добавлений и 42 удалений

Просмотреть файл

@ -1272,28 +1272,9 @@ SourceScripts.prototype = {
return this._logError(script.url, -1);
}
if (typeof aResponse.source === "string") {
// We did not receive a long string, instead we got the source directly.
this._onLoadSourceFinished(script.url,
aResponse.source,
options);
return;
}
if (aResponse.source.type !== "longString") {
return this._logError(script.url, -1);
}
let sourceTextClient = this.activeThread.threadLongString(aResponse.source);
let length = sourceTextClient.length;
sourceTextClient.substring(0, length, function (aResponse) {
if (aResponse.error) {
return this._logError(script.url, -1);
}
this._onLoadSourceFinished(script.url,
aResponse.substring,
options);
}.bind(this));
this._onLoadSourceFinished(script.url,
aResponse.source,
options);
}.bind(this));
},

Просмотреть файл

@ -1115,7 +1115,30 @@ SourceClient.prototype = {
to: this._actor,
type: "source"
};
this._client.request(packet, aCallback);
this._client.request(packet, function (aResponse) {
if (aResponse.error) {
aCallback(aResponse);
return;
}
if (typeof aResponse.source === "string") {
aCallback(aResponse);
return;
}
let longString = this._client.activeThread.threadLongString(
aResponse.source);
longString.substring(0, longString.length, function (aResponse) {
if (aResponse.error) {
aCallback(aResponse);
return;
}
aCallback({
source: aResponse.substring
});
});
}.bind(this));
}
};

Просмотреть файл

@ -57,27 +57,17 @@ function test_source()
do_check_true(!aResponse.error);
do_check_true(!!aResponse.source);
let source = aResponse.source;
do_check_eq(source.type, "longString");
let f = do_get_file("test_source-01.js", false);
let s = Cc["@mozilla.org/network/file-input-stream;1"]
.createInstance(Ci.nsIFileInputStream);
s.init(f, -1, -1, false);
let sourceStringClient = gThreadClient.threadLongString(source);
let len = sourceStringClient.length;
sourceStringClient.substring(0, len, function (aResponse) {
do_check_true(!!aResponse);
do_check_true(!!aResponse.substring);
do_check_eq(NetUtil.readInputStreamToString(s, s.available()),
aResponse.source);
let f = do_get_file("test_source-01.js", false);
let s = Cc["@mozilla.org/network/file-input-stream;1"]
.createInstance(Ci.nsIFileInputStream);
s.init(f, -1, -1, false);
do_check_eq(NetUtil.readInputStreamToString(s, s.available()),
aResponse.substring);
s.close();
gThreadClient.resume(function () {
finishClient(gClient);
});
s.close();
gThreadClient.resume(function () {
finishClient(gClient);
});
});
});