output[mime/type] -> output.data[mime/type] in javascript

MinRK 12 years ago committed by Min RK
parent a50042745f
commit 6ca260e611

@ -213,11 +213,11 @@ define([
json.text = content.text;
json.name = content.name;
} else if (msg_type === "display_data") {
json = content.data;
json.data = content.data;
json.output_type = msg_type;
json.metadata = content.metadata;
} else if (msg_type === "execute_result") {
json = content.data;
json.data = content.data;
json.output_type = msg_type;
json.metadata = content.metadata;
json.execution_count = content.execution_count;
@ -258,15 +258,14 @@ define([
OutputArea.prototype.validate_output = function (json) {
// scrub invalid outputs
// TODO: right now everything is a string, but JSON really shouldn't be.
// nbformat 4 will fix that.
var data = json.data;
$.map(OutputArea.output_types, function(key){
if (key !== 'application/json' &&
json[key] !== undefined &&
typeof json[key] !== 'string'
data[key] !== undefined &&
typeof data[key] !== 'string'
) {
console.log("Invalid type for " + key, json[key]);
delete json[key];
console.log("Invalid type for " + key, data[key]);
delete data[key];
}
});
return json;
@ -276,7 +275,9 @@ define([
this.expand();
// validate output data types
json = this.validate_output(json);
if (json.data) {
json = this.validate_output(json);
}
// Clear the output if clear is queued.
var needs_height_reset = false;
@ -517,8 +518,8 @@ define([
for (var i=0; i < OutputArea.display_order.length; i++) {
var type = OutputArea.display_order[i];
var append = OutputArea.append_map[type];
if ((json[type] !== undefined) && append) {
var value = json[type];
if ((json.data[type] !== undefined) && append) {
var value = json.data[type];
if (!this.trusted && !OutputArea.safe_outputs[type]) {
// not trusted, sanitize HTML
if (type==='text/html' || type==='text/svg') {
@ -804,7 +805,7 @@ define([
// replace with plaintext version in stdout
this.append_output(content, false);
this.events.trigger('send_input_reply.Kernel', value);
}
};
OutputArea.prototype.handle_clear_output = function (msg) {

@ -24,13 +24,13 @@ var svg = "\"<svg width='1cm' height='1cm' viewBox='0 0 1000 500'><defs><style>r
// name, and that fromJSON also gets its long mimetype name
function assert_has(short_name, json, result, result2) {
long_name = mime[short_name];
this.test.assertFalse(json[0].hasOwnProperty(short_name),
this.test.assertFalse(json[0].data.hasOwnProperty(short_name),
"toJSON() representation doesn't use " + short_name);
this.test.assertTrue(json[0].hasOwnProperty(long_name),
this.test.assertTrue(json[0].data.hasOwnProperty(long_name),
'toJSON() representation uses ' + long_name);
this.test.assertTrue(result.hasOwnProperty(long_name),
this.test.assertTrue(result.data.hasOwnProperty(long_name),
'toJSON() original embedded JSON keeps ' + long_name);
this.test.assertTrue(result2.hasOwnProperty(long_name),
this.test.assertTrue(result2.data.hasOwnProperty(long_name),
'fromJSON() embedded ' + short_name + ' gets mime key ' + long_name);
}
@ -71,7 +71,7 @@ function clear_and_execute(that, code) {
that.execute_cell(0);
that.wait_for_idle();
});
};
}
casper.notebook_test(function () {
this.evaluate(function () {
@ -88,7 +88,7 @@ casper.notebook_test(function () {
var result = this.get_output_cell(0);
var num_cells = this.get_cells_length();
this.test.assertEquals(num_cells, 2, '%%javascript magic works');
this.test.assertTrue(result.hasOwnProperty('application/javascript'),
this.test.assertTrue(result.data.hasOwnProperty('application/javascript'),
'testing JS embedded with mime key');
});
@ -236,10 +236,10 @@ casper.notebook_test(function () {
this.then(function () {
var long_name = 'text/superfancymimetype';
var result = this.get_output_cell(0);
this.test.assertTrue(result.hasOwnProperty(long_name),
this.test.assertTrue(result.data.hasOwnProperty(long_name),
'display_data custom mimetype ' + long_name);
var result = this.get_output_cell(0, 1);
this.test.assertTrue(result.hasOwnProperty(long_name),
result = this.get_output_cell(0, 1);
this.test.assertTrue(result.data.hasOwnProperty(long_name),
'execute_result custom mimetype ' + long_name);
});

@ -26,7 +26,7 @@ casper.notebook_test(function () {
var output = this.get_output_cell(0);
this.test.assert(messages.length > 0, "Captured log message");
this.test.assertEquals(messages[messages.length-1].substr(0,26), "Invalid type for image/png", "Logged Invalid type message");
this.test.assertEquals(output['image/png'], undefined, "Non-string png data was stripped");
this.test.assertEquals(output['text/plain'], '5', "text data is fine");
this.test.assertEquals(output.data['image/png'], undefined, "Non-string png data was stripped");
this.test.assertEquals(output.data['text/plain'], '5', "text data is fine");
});
});

@ -170,7 +170,7 @@ casper.notebook_test(function () {
this.test.assert(outputs.length <= 5, 'Messages throttled.');
// We also need to verify that the last state sent was correct.
var last_state = outputs[outputs.length-1]['text/plain'];
var last_state = outputs[outputs.length-1].data['text/plain'];
this.test.assertEquals(last_state, "20", "Last state sent when throttling.");
});
});

@ -37,7 +37,7 @@ casper.notebook_test(function () {
this.wait_for_output(button_index, 1);
this.then(function () {
this.test.assertEquals(this.get_output_cell(button_index, 1)['text/plain'], "'Clicked'",
this.test.assertEquals(this.get_output_cell(button_index, 1).data['text/plain'], "'Clicked'",
'Button click event fires.');
});
});
Loading…
Cancel
Save