diff options
-rw-r--r-- | mojo/apps/js/bindings/connection_unittests.js | 2 | ||||
-rw-r--r-- | mojo/bindings/js/core.cc | 4 | ||||
-rw-r--r-- | mojo/bindings/js/handle.cc | 7 | ||||
-rw-r--r-- | mojo/bindings/js/handle.h | 25 | ||||
-rw-r--r-- | mojo/public/js/bindings/connector.js | 4 | ||||
-rw-r--r-- | mojo/public/tools/bindings/generators/js_templates/module.js.tmpl | 3 | ||||
-rw-r--r-- | mojo/public/tools/bindings/generators/mojom_js_generator.py | 10 |
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", |