Skip to content

Commit

Permalink
Identify ArrayBuffers by their string representation in json_schema.js.
Browse files Browse the repository at this point in the history
Previously, ArrayBuffers were identified by comparing their constructor
to the current context's ArrayBuffer constructor. This caused
ArrayBuffers from other contexts to be identified as "object" instead of
"binary".

BUG=389016

Review URL: https://codereview.chromium.org/684403002

Cr-Commit-Position: refs/heads/master@{#306294}
  • Loading branch information
sammc authored and Commit bot committed Dec 1, 2014
1 parent 62f7ce4 commit c3cf421
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
13 changes: 13 additions & 0 deletions extensions/renderer/json_schema_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "extensions/renderer/module_system_test.h"
#include "extensions/renderer/v8_schema_registry.h"
#include "gin/dictionary.h"
#include "grit/extensions_renderer_resources.h"

namespace extensions {
Expand Down Expand Up @@ -72,6 +73,18 @@ TEST_F(JsonSchemaTest, TestIntegerBounds) {
}

TEST_F(JsonSchemaTest, TestType) {
gin::Dictionary array_buffer_container(
env()->isolate(),
env()->CreateGlobal("otherContextArrayBufferContainer"));
{
// Create an ArrayBuffer in another v8 context and pass it to the test
// through a global.
scoped_ptr<ModuleSystemTestEnvironment> other_env(CreateEnvironment());
v8::Context::Scope scope(other_env->context()->v8_context());
v8::Handle<v8::ArrayBuffer> array_buffer(
v8::ArrayBuffer::New(env()->isolate(), 1));
array_buffer_container.Set("value", array_buffer);
}
TestFunction("testType");
}

Expand Down
4 changes: 2 additions & 2 deletions extensions/renderer/resources/json_schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ JSONSchemaValidator.getType = function(value) {
return "null";
} else if (Object.prototype.toString.call(value) == "[object Array]") {
return "array";
} else if (typeof(ArrayBuffer) != "undefined" &&
value.constructor == ArrayBuffer) {
} else if (Object.prototype.toString.call(value) ==
"[object ArrayBuffer]") {
return "binary";
}
} else if (s == "number") {
Expand Down
2 changes: 2 additions & 0 deletions extensions/test/data/json_schema_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ function testType() {
assertValid("Type", false, {type:"boolean"});
assertValid("Type", null, {type:"null"});
assertValid("Type", undefined, {type:"undefined"});
assertValid("Type", new ArrayBuffer(1), {type:"binary"});
assertValid("Type", otherContextArrayBufferContainer.value, {type:"binary"});

// not valid
assertNotValid("Type", [], {type: "object"},
Expand Down

0 comments on commit c3cf421

Please sign in to comment.