summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-11 14:20:37 +0000
committerabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-11 14:20:37 +0000
commit7c6f155e075991e2e94d1682c5d0e9b341a8831e (patch)
treeb67c5dc4658230ca0c9de989037d51132fefbcbe
parent174a621f96913029748c965389706d2b32eb153b (diff)
downloadchromium_src-7c6f155e075991e2e94d1682c5d0e9b341a8831e.zip
chromium_src-7c6f155e075991e2e94d1682c5d0e9b341a8831e.tar.gz
chromium_src-7c6f155e075991e2e94d1682c5d0e9b341a8831e.tar.bz2
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
-rw-r--r--mojo/apps/js/bindings/connection_unittests.js2
-rw-r--r--mojo/bindings/js/core.cc4
-rw-r--r--mojo/bindings/js/handle.cc7
-rw-r--r--mojo/bindings/js/handle.h25
-rw-r--r--mojo/public/js/bindings/connector.js4
-rw-r--r--mojo/public/tools/bindings/generators/js_templates/module.js.tmpl3
-rw-r--r--mojo/public/tools/bindings/generators/mojom_js_generator.py10
7 files changed, 41 insertions, 14 deletions
diff --git a/mojo/apps/js/bindings/connection_unittests.js b/mojo/apps/js/bindings/connection_unittests.js
index 91ea8e3..0b0a71b 100644
--- a/mojo/apps/js/bindings/connection_unittests.js
+++ b/mojo/apps/js/bindings/connection_unittests.js
@@ -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();
diff --git a/mojo/bindings/js/core.cc b/mojo/bindings/js/core.cc
index dd46594..976a534 100644
--- a/mojo/bindings/js/core.cc
+++ b/mojo/bindings/js/core.cc
@@ -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)
diff --git a/mojo/bindings/js/handle.cc b/mojo/bindings/js/handle.cc
index 36a4988..e1d0fb0 100644
--- a/mojo/bindings/js/handle.cc
+++ b/mojo/bindings/js/handle.cc
@@ -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;
diff --git a/mojo/bindings/js/handle.h b/mojo/bindings/js/handle.h
index ad03f87..35202b0 100644
--- a/mojo/bindings/js/handle.h
+++ b/mojo/bindings/js/handle.h
@@ -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_
diff --git a/mojo/public/js/bindings/connector.js b/mojo/public/js/bindings/connector.js
index 51fb7fe..5774598 100644
--- a/mojo/public/js/bindings/connector.js
+++ b/mojo/public/js/bindings/connector.js
@@ -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;
}
};
diff --git a/mojo/public/tools/bindings/generators/js_templates/module.js.tmpl b/mojo/public/tools/bindings/generators/js_templates/module.js.tmpl
index aaa3ed5..2757303 100644
--- a/mojo/public/tools/bindings/generators/js_templates/module.js.tmpl
+++ b/mojo/public/tools/bindings/generators/js_templates/module.js.tmpl
@@ -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 -%}
diff --git a/mojo/public/tools/bindings/generators/mojom_js_generator.py b/mojo/public/tools/bindings/generators/mojom_js_generator.py
index e0493c1..136e577 100644
--- a/mojo/public/tools/bindings/generators/mojom_js_generator.py
+++ b/mojo/public/tools/bindings/generators/mojom_js_generator.py
@@ -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",