Commit 7c6f155e authored by abarth@chromium.org's avatar abarth@chromium.org

We want to be able to use the generated mojom.js files on web servers

without having access to the core Mojo system. Currently the only reason
these files depend on core is to get kInvalidHandle, but there's no such
constant on the C++ side anymore.

This CL replaces core.kInvalidHandle with |null| and teaches the handle
converters how to convert null to and from an invalid handle.

R=sky@chromium.org
BUG=372065

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269704 0039d316-1c4b-4281-b951-d872f2087c98
parent 174a621f
......@@ -174,7 +174,7 @@ define([
var foo = new sample_service.Foo();
foo.bar = new sample_service.Bar();
// TODO(darin): crbug.com/357043: pass null in place of |foo| here.
connection1.remote.frobinate(foo, true, core.kInvalidHandle);
connection1.remote.frobinate(foo, true, null);
// Write failures are not reported.
expect(connection1.encounteredError()).toBeFalsy();
......
......@@ -220,10 +220,6 @@ v8::Local<v8::Value> Core::GetModule(v8::Isolate* isolate) {
.SetMethod("writeData", WriteData)
.SetMethod("readData", ReadData)
// TODO(vtl): Change name of "kInvalidHandle", now that there's no such
// C++ constant?
.SetValue("kInvalidHandle", mojo::Handle())
.SetValue("RESULT_OK", MOJO_RESULT_OK)
.SetValue("RESULT_CANCELLED", MOJO_RESULT_CANCELLED)
.SetValue("RESULT_UNKNOWN", MOJO_RESULT_UNKNOWN)
......
......@@ -17,12 +17,19 @@ HandleWrapper::~HandleWrapper() {
v8::Handle<v8::Value> Converter<mojo::Handle>::ToV8(v8::Isolate* isolate,
const mojo::Handle& val) {
if (!val.is_valid())
return v8::Null(isolate);
return HandleWrapper::Create(isolate, val.value()).ToV8();
}
bool Converter<mojo::Handle>::FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val,
mojo::Handle* out) {
if (val->IsNull()) {
*out = mojo::Handle();
return true;
}
gin::Handle<HandleWrapper> handle;
if (!Converter<gin::Handle<HandleWrapper> >::FromV8(isolate, val, &handle))
return false;
......
......@@ -45,6 +45,31 @@ struct Converter<mojo::Handle> {
mojo::Handle* out);
};
// We need to specialize the normal gin::Handle converter in order to handle
// converting |null| to a wrapper for an empty mojo::Handle.
template<>
struct Converter<gin::Handle<gin::HandleWrapper> > {
static v8::Handle<v8::Value> ToV8(
v8::Isolate* isolate, const gin::Handle<gin::HandleWrapper>& val) {
return val.ToV8();
}
static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
gin::Handle<gin::HandleWrapper>* out) {
if (val->IsNull()) {
*out = HandleWrapper::Create(isolate, MOJO_HANDLE_INVALID);
return true;
}
gin::HandleWrapper* object = NULL;
if (!Converter<gin::HandleWrapper*>::FromV8(isolate, val, &object)) {
return false;
}
*out = gin::Handle<gin::HandleWrapper>(val, object);
return true;
}
};
} // namespace gin
#endif // MOJO_BINDINGS_JS_HANDLE_H_
......@@ -24,9 +24,9 @@ define("mojo/public/js/bindings/connector", [
support.cancelWait(this.readWaitCookie_);
this.readWaitCookie_ = null;
}
if (this.handle_ != core.kInvalidHandle) {
if (this.handle_ != null) {
core.close(this.handle_);
this.handle_ = core.kInvalidHandle;
this.handle_ = null;
}
};
......
......@@ -3,12 +3,11 @@
// found in the LICENSE file.
define("{{module.path}}", [
"mojo/public/js/bindings/core",
"mojo/public/js/bindings/codec",
{%- for import in imports %}
"{{import.module.path}}",
{%- endfor %}
], function(core, codec
], function(codec
{%- for import in imports -%}
, {{import.unique_name}}
{%- endfor -%}
......
......@@ -18,11 +18,11 @@ _kind_to_javascript_default_value = {
mojom.INT32: "0",
mojom.UINT32: "0",
mojom.FLOAT: "0",
mojom.HANDLE: "core.kInvalidHandle",
mojom.DCPIPE: "core.kInvalidHandle",
mojom.DPPIPE: "core.kInvalidHandle",
mojom.MSGPIPE: "core.kInvalidHandle",
mojom.SHAREDBUFFER: "core.kInvalidHandle",
mojom.HANDLE: "null",
mojom.DCPIPE: "null",
mojom.DPPIPE: "null",
mojom.MSGPIPE: "null",
mojom.SHAREDBUFFER: "null",
mojom.INT64: "0",
mojom.UINT64: "0",
mojom.DOUBLE: "0",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment