diff options
author | rockot <rockot@chromium.org> | 2015-01-05 20:27:49 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-06 04:28:43 +0000 |
commit | 84b8c80778fa2c728470c557c379ef34a1b525b0 (patch) | |
tree | 86562f30b06e2046efe90b7c1694ced1c4f451a4 /mojo | |
parent | d1896bcd60222e0999da63947ec60af7506c73d7 (diff) | |
download | chromium_src-84b8c80778fa2c728470c557c379ef34a1b525b0.zip chromium_src-84b8c80778fa2c728470c557c379ef34a1b525b0.tar.gz chromium_src-84b8c80778fa2c728470c557c379ef34a1b525b0.tar.bz2 |
Update mojo sdk to rev e3719475d5971283d1d2250533d53066b2ff9797
Includes diff from comment #6 at
https://codereview.chromium.org/803173009
BUG=None
TBR=darin@chromium.org
TBR=jamesr@chromium.org
Review URL: https://codereview.chromium.org/835253002
Cr-Commit-Position: refs/heads/master@{#310049}
Diffstat (limited to 'mojo')
-rw-r--r-- | mojo/public/VERSION | 2 | ||||
-rw-r--r-- | mojo/public/cpp/application/lazy_interface_ptr.h | 2 | ||||
-rw-r--r-- | mojo/public/cpp/system/handle.h | 2 | ||||
-rw-r--r-- | mojo/public/interfaces/bindings/tests/test_structs.mojom | 5 | ||||
-rw-r--r-- | mojo/public/js/bindings.js | 100 | ||||
-rw-r--r-- | mojo/public/js/connection.js | 61 | ||||
-rw-r--r-- | mojo/public/js/constants.cc | 1 | ||||
-rw-r--r-- | mojo/public/js/constants.h | 1 | ||||
-rw-r--r-- | mojo/public/js/struct_unittests.js | 6 | ||||
-rw-r--r-- | mojo/public/sky/BUILD.gn | 1 | ||||
-rw-r--r-- | mojo/public/tools/bindings/generators/js_templates/interface_definition.tmpl | 18 | ||||
-rw-r--r-- | mojo/public/tools/bindings/generators/js_templates/module.amd.tmpl | 3 | ||||
-rw-r--r-- | mojo/public/tools/bindings/generators/js_templates/module.sky.tmpl | 1 | ||||
-rw-r--r-- | mojo/public/tools/bindings/generators/mojom_cpp_generator.py | 15 | ||||
-rw-r--r-- | mojo/services/public/js/service_provider.js | 23 | ||||
-rw-r--r-- | mojo/services/public/js/shell.js | 17 |
16 files changed, 182 insertions, 76 deletions
diff --git a/mojo/public/VERSION b/mojo/public/VERSION index 2f0f2cd..bfe9476 100644 --- a/mojo/public/VERSION +++ b/mojo/public/VERSION @@ -1 +1 @@ -cc531b32182099a5a034a99daff35ed5d38a61c8
\ No newline at end of file +e3719475d5971283d1d2250533d53066b2ff9797
\ No newline at end of file diff --git a/mojo/public/cpp/application/lazy_interface_ptr.h b/mojo/public/cpp/application/lazy_interface_ptr.h index 1ecb043..a9b57db 100644 --- a/mojo/public/cpp/application/lazy_interface_ptr.h +++ b/mojo/public/cpp/application/lazy_interface_ptr.h @@ -26,7 +26,7 @@ class LazyInterfacePtr : public InterfacePtr<Interface> { } Interface* get() const { - if (!InterfacePtr<Interface>::get()) { + if (!InterfacePtr<Interface>::get() && service_provider_) { mojo::ConnectToService<Interface>( service_provider_, const_cast<LazyInterfacePtr<Interface>*>(this)); } diff --git a/mojo/public/cpp/system/handle.h b/mojo/public/cpp/system/handle.h index 3549854..021fa87 100644 --- a/mojo/public/cpp/system/handle.h +++ b/mojo/public/cpp/system/handle.h @@ -301,7 +301,7 @@ inline WaitManyResult WaitMany(const HandleVectorType& handles, if (signals.size() != handles.size()) return WaitManyResult(MOJO_RESULT_INVALID_ARGUMENT); if (handles.size() >= kInvalidWaitManyIndexValue) - return WaitManyResult(MOJO_RESULT_OUT_OF_RANGE); + return WaitManyResult(MOJO_RESULT_RESOURCE_EXHAUSTED); if (handles.size() == 0) { return WaitManyResult( diff --git a/mojo/public/interfaces/bindings/tests/test_structs.mojom b/mojo/public/interfaces/bindings/tests/test_structs.mojom index 490a587..40fa9a6 100644 --- a/mojo/public/interfaces/bindings/tests/test_structs.mojom +++ b/mojo/public/interfaces/bindings/tests/test_structs.mojom @@ -183,10 +183,7 @@ struct IntegerNumberValues { const int16 V8 = 12345; const int16 V9 = 32767; - // MSVC can't parse -2147483648 so V10 is intentionally off by one. - // See http://msdn.microsoft.com/en-us/library/4kh09110.aspx - // Tests may override V10. - const int32 V10 = -2147483647; + const int32 V10 = -2147483648; const int32 V11 = -1; const int32 V12 = 0; const int32 V13 = 1234567890; diff --git a/mojo/public/js/bindings.js b/mojo/public/js/bindings.js new file mode 100644 index 0000000..5f85860 --- /dev/null +++ b/mojo/public/js/bindings.js @@ -0,0 +1,100 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +define("mojo/public/js/bindings", [ + "mojo/public/js/router", +], function(router) { + + var Router = router.Router; + + var kProxyProperties = Symbol("proxyProperties"); + var kStubProperties = Symbol("stubProperties"); + + // Public proxy class properties that are managed at runtime by the JS + // bindings. See ProxyBindings below. + function ProxyProperties(receiver) { + this.receiver = receiver; + } + + ProxyProperties.prototype.getLocalDelegate = function() { + return this.local && StubBindings(this.local).delegate; + } + + ProxyProperties.prototype.setLocalDelegate = function(impl) { + if (this.local) + StubBindings(this.local).delegate = impl; + else + throw new Error("no stub object"); + } + + // Public stub class properties that are managed at runtime by the JS + // bindings. See StubBindings below. + function StubProperties(delegate) { + this.delegate = delegate; + } + + // The base class for generated proxy classes. + function ProxyBase(receiver) { + this[kProxyProperties] = new ProxyProperties(receiver); + + // TODO(hansmuller): Temporary, for Chrome backwards compatibility. + if (receiver instanceof Router) + this.receiver_ = receiver; + } + + // The base class for generated stub classes. + function StubBase(delegate) { + this[kStubProperties] = new StubProperties(delegate); + } + + // Provides access to properties added to a proxy object without risking + // Mojo interface name collisions. Unless otherwise specified, the initial + // value of all properties is undefined. + // + // ProxyBindings(proxy).connection - The Connection object that links the + // proxy for a remote Mojo service to an optional local stub for a local + // service. The value of ProxyBindings(proxy).connection.remote == proxy. + // + // ProxyBindings(proxy).local - The "local" stub object whose delegate + // implements the proxy's Mojo client interface. + // + // ProxyBindings(proxy).setLocalDelegate(impl) - Sets the implementation + // delegate of the proxy's client stub object. This is just shorthand + // for |StubBindings(ProxyBindings(proxy).local).delegate = impl|. + // + // ProxyBindings(proxy).getLocalDelegate() - Returns the implementation + // delegate of the proxy's client stub object. This is just shorthand + // for |StubBindings(ProxyBindings(proxy).local).delegate|. + + function ProxyBindings(proxy) { + return (proxy instanceof ProxyBase) ? proxy[kProxyProperties] : proxy; + } + + // Provides access to properties added to a stub object without risking + // Mojo interface name collisions. Unless otherwise specified, the initial + // value of all properties is undefined. + // + // StubBindings(stub).delegate - The optional implementation delegate for + // the Mojo interface stub. + // + // StubBindings(stub).connection - The Connection object that links an + // optional proxy for a remote service to this stub. The value of + // StubBindings(stub).connection.local == stub. + // + // StubBindings(stub).remote - A proxy for the the stub's Mojo client + // service. + + function StubBindings(stub) { + return stub instanceof StubBase ? stub[kStubProperties] : stub; + } + + var exports = {}; + exports.EmptyProxy = ProxyBase; + exports.EmptyStub = StubBase; + exports.ProxyBase = ProxyBase; + exports.ProxyBindings = ProxyBindings; + exports.StubBase = StubBase; + exports.StubBindings = StubBindings; + return exports; +});
\ No newline at end of file diff --git a/mojo/public/js/connection.js b/mojo/public/js/connection.js index 21c31e0..3976efd 100644 --- a/mojo/public/js/connection.js +++ b/mojo/public/js/connection.js @@ -3,12 +3,17 @@ // found in the LICENSE file. define("mojo/public/js/connection", [ + "mojo/public/js/bindings", "mojo/public/js/connector", "mojo/public/js/core", "mojo/public/js/router", -], function(connector, core, router) { +], function(bindings, connector, core, router) { var Router = router.Router; + var EmptyProxy = bindings.EmptyProxy; + var EmptyStub = bindings.EmptyStub; + var ProxyBindings = bindings.ProxyBindings; + var StubBindings = bindings.StubBindings; var TestConnector = connector.TestConnector; var TestRouter = router.TestRouter; @@ -68,46 +73,25 @@ define("mojo/public/js/connection", [ TestConnection.prototype = Object.create(Connection.prototype); - // Called by the generated interface Proxy constructor classes. - function initProxyInstance(proxy, proxyInterface, receiver) { - Object.defineProperty(proxy, 'local$', { - get: function() { - return proxy.connection$ && - proxy.connection$.local && proxy.connection$.local.delegate$ - }, - set: function(value) { - // TODO: what if the connection hasn't been created yet? - if (proxy.connection$ && proxy.connection$.local) { - proxy.connection$.local.delegate$ = value; - value.remote$ = proxy; - } - } - }); - // TODO(hansmuller): Temporary, for Chrome backwards compatibility. - if (receiver instanceof Router) - proxy.receiver_ = receiver; - } - - function createEmptyProxy() { - var proxy = {}; - initProxyInstance(proxy); - return proxy; - } - function createOpenConnection( - messagePipeHandle, clientImpl, localInterface, remoteInterface) { - var stubClass = localInterface && localInterface.stubClass - var proxyClass = remoteInterface && remoteInterface.proxyClass; - var stub = stubClass && - (clientImpl ? new stubClass(clientImpl) : new stubClass); - var proxy = proxyClass ? new proxyClass : createEmptyProxy(); + messagePipeHandle, client, localInterface, remoteInterface) { + var stubClass = (localInterface && localInterface.stubClass) || EmptyStub; + var proxyClass = + (remoteInterface && remoteInterface.proxyClass) || EmptyProxy; + var proxy = new proxyClass; + var stub = new stubClass; var router = new Router(messagePipeHandle); var connection = new BaseConnection(stub, proxy, router); - proxy.connection$ = connection; - if (clientImpl) { - clientImpl.connection$ = connection; - clientImpl.remote$ = proxy; - } + + ProxyBindings(proxy).connection = connection; + ProxyBindings(proxy).local = connection.local; + StubBindings(stub).connection = connection; + StubBindings(proxy).remote = connection.remote; + + var clientImpl = client instanceof Function ? client(proxy) : client; + if (clientImpl) + StubBindings(stub).delegate = clientImpl; + return connection; } @@ -137,6 +121,5 @@ define("mojo/public/js/connection", [ exports.TestConnection = TestConnection; exports.bindProxyHandle = bindProxyHandle; exports.bindProxyClient = bindProxyClient; - exports.initProxyInstance = initProxyInstance; return exports; }); diff --git a/mojo/public/js/constants.cc b/mojo/public/js/constants.cc index 4f98cc8..d29f5cb 100644 --- a/mojo/public/js/constants.cc +++ b/mojo/public/js/constants.cc @@ -6,6 +6,7 @@ namespace mojo { +const char kBindingsModuleName[] = "mojo/public/js/bindings"; const char kBufferModuleName[] = "mojo/public/js/buffer"; const char kCodecModuleName[] = "mojo/public/js/codec"; const char kConnectionModuleName[] = "mojo/public/js/connection"; diff --git a/mojo/public/js/constants.h b/mojo/public/js/constants.h index 9927c8e..de75a90 100644 --- a/mojo/public/js/constants.h +++ b/mojo/public/js/constants.h @@ -8,6 +8,7 @@ namespace mojo { // JavaScript module names: +extern const char kBindingsModuleName[]; extern const char kBufferModuleName[]; extern const char kCodecModuleName[]; extern const char kConnectionModuleName[]; diff --git a/mojo/public/js/struct_unittests.js b/mojo/public/js/struct_unittests.js index d91ff4d..39a8978 100644 --- a/mojo/public/js/struct_unittests.js +++ b/mojo/public/js/struct_unittests.js @@ -189,9 +189,7 @@ define([ } function testIntegerNumberValues() { - var minInt32 = -2147483648; // See crbug.com/445618 - var decodedStruct = structEncodeDecode( - new testStructs.IntegerNumberValues({f10: minInt32})); + var decodedStruct = structEncodeDecode(new testStructs.IntegerNumberValues); expect(decodedStruct.f0).toEqual(testStructs.IntegerNumberValues.V0); expect(decodedStruct.f1).toEqual(testStructs.IntegerNumberValues.V1); expect(decodedStruct.f2).toEqual(testStructs.IntegerNumberValues.V2); @@ -202,7 +200,7 @@ define([ expect(decodedStruct.f7).toEqual(testStructs.IntegerNumberValues.V7); expect(decodedStruct.f8).toEqual(testStructs.IntegerNumberValues.V8); expect(decodedStruct.f9).toEqual(testStructs.IntegerNumberValues.V9); - expect(decodedStruct.f10).toEqual(minInt32); + expect(decodedStruct.f10).toEqual(testStructs.IntegerNumberValues.V10); expect(decodedStruct.f11).toEqual(testStructs.IntegerNumberValues.V11); expect(decodedStruct.f12).toEqual(testStructs.IntegerNumberValues.V12); expect(decodedStruct.f13).toEqual(testStructs.IntegerNumberValues.V13); diff --git a/mojo/public/sky/BUILD.gn b/mojo/public/sky/BUILD.gn index a24dde4..c7019be 100644 --- a/mojo/public/sky/BUILD.gn +++ b/mojo/public/sky/BUILD.gn @@ -5,6 +5,7 @@ action_foreach("sky") { script = "convert_amd_modules_to_sky.py" sources = [ + "../js/bindings.js", "../js/buffer.js", "../js/codec.js", "../js/connection.js", diff --git a/mojo/public/tools/bindings/generators/js_templates/interface_definition.tmpl b/mojo/public/tools/bindings/generators/js_templates/interface_definition.tmpl index ca95e97..1b5cafa 100644 --- a/mojo/public/tools/bindings/generators/js_templates/interface_definition.tmpl +++ b/mojo/public/tools/bindings/generators/js_templates/interface_definition.tmpl @@ -3,8 +3,9 @@ {%- endfor %} function {{interface.name}}Proxy(receiver) { - connection.initProxyInstance(this, {{interface.name}}, receiver); + bindings.ProxyBase.call(this, receiver); } + {{interface.name}}Proxy.prototype = Object.create(bindings.ProxyBase.prototype); {%- for method in interface.methods %} {{interface.name}}Proxy.prototype.{{method.name|stylize_method}} = function( @@ -46,18 +47,15 @@ {%- endfor %} function {{interface.name}}Stub(delegate) { - this.delegate$ = delegate; + bindings.StubBase.call(this, delegate); } + {{interface.name}}Stub.prototype = Object.create(bindings.StubBase.prototype); {%- for method in interface.methods %} -{% macro stub_method_parameters() -%} -{%- for parameter in method.parameters -%} - {{parameter.name}}{% if not loop.last %}, {% endif %} -{%- endfor %} -{%- endmacro %} - {{interface.name}}Stub.prototype.{{method.name|stylize_method}} = function({{stub_method_parameters()}}) { - if (this.delegate$.{{method.name|stylize_method}}) - return this.delegate$.{{method.name|stylize_method}}({{method.parameters|map('js_stub_method_parameter_value')|join(',')}}); +{%- set js_method_name = method.name|stylize_method %} +{%- set delegate_expr = "bindings.StubBindings(this).delegate" %} + {{interface.name}}Stub.prototype.{{js_method_name}} = function({{method.parameters|map(attribute='name')|join(', ')}}) { + return {{delegate_expr}} && {{delegate_expr}}.{{js_method_name}} && {{delegate_expr}}.{{js_method_name}}({{method.parameters|map('js_stub_method_parameter_value')|join(', ')}}); } {%- endfor %} diff --git a/mojo/public/tools/bindings/generators/js_templates/module.amd.tmpl b/mojo/public/tools/bindings/generators/js_templates/module.amd.tmpl index 2565f6a..6d7a1a2 100644 --- a/mojo/public/tools/bindings/generators/js_templates/module.amd.tmpl +++ b/mojo/public/tools/bindings/generators/js_templates/module.amd.tmpl @@ -3,6 +3,7 @@ // found in the LICENSE file. define("{{module.path}}", [ + "mojo/public/js/bindings", "mojo/public/js/codec", "mojo/public/js/connection", "mojo/public/js/core", @@ -10,7 +11,7 @@ define("{{module.path}}", [ {%- for import in imports %} "{{import.module.path}}", {%- endfor %} -], function(codec, connection, core, validator +], function(bindings, codec, connection, core, validator {%- for import in imports -%} , {{import.unique_name}} {%- endfor -%} diff --git a/mojo/public/tools/bindings/generators/js_templates/module.sky.tmpl b/mojo/public/tools/bindings/generators/js_templates/module.sky.tmpl index e4757ee..78cdf3f 100644 --- a/mojo/public/tools/bindings/generators/js_templates/module.sky.tmpl +++ b/mojo/public/tools/bindings/generators/js_templates/module.sky.tmpl @@ -2,6 +2,7 @@ Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. --> +<import src="/mojo/public/sky/bindings.sky" as="bindings" /> <import src="/mojo/public/sky/codec.sky" as="codec" /> <import src="/mojo/public/sky/connection.sky" as="connection" /> <import src="/mojo/public/sky/core.sky" as="core" /> diff --git a/mojo/public/tools/bindings/generators/mojom_cpp_generator.py b/mojo/public/tools/bindings/generators/mojom_cpp_generator.py index a2618a4..34bba30 100644 --- a/mojo/public/tools/bindings/generators/mojom_cpp_generator.py +++ b/mojo/public/tools/bindings/generators/mojom_cpp_generator.py @@ -254,6 +254,21 @@ def TranslateConstants(token, kind): if (kind is not None and mojom.IsFloatKind(kind)): return token if token.isdigit() else token + "f"; + # Per C++11, 2.14.2, the type of an integer literal is the first of the + # corresponding list in Table 6 in which its value can be represented. In this + # case, the list for decimal constants with no suffix is: + # int, long int, long long int + # The standard considers a program ill-formed if it contains an integer + # literal that cannot be represented by any of the allowed types. + # + # As it turns out, MSVC doesn't bother trying to fall back to long long int, + # so the integral constant -2147483648 causes it grief: it decides to + # represent 2147483648 as an unsigned integer, and then warns that the unary + # minus operator doesn't make sense on unsigned types. Doh! + if kind == mojom.INT32 and token == '-2147483648': + return '(-%d - 1) /* %s */' % ( + 2**31 - 1, 'Workaround for MSVC bug; see https://crbug.com/445618') + return '%s%s' % (token, _kind_to_cpp_literal_suffix.get(kind, '')) def ExpressionToText(value, kind=None): diff --git a/mojo/services/public/js/service_provider.js b/mojo/services/public/js/service_provider.js index 9ad0c5d..e8d491f 100644 --- a/mojo/services/public/js/service_provider.js +++ b/mojo/services/public/js/service_provider.js @@ -3,10 +3,13 @@ // found in the LICENSE file. define("mojo/services/public/js/service_provider", [ + "mojo/public/js/bindings", "mojo/public/interfaces/application/service_provider.mojom", "mojo/public/js/connection", -], function(serviceProviderMojom, connection) { +], function(bindings, serviceProviderMojom, connection) { + const ProxyBindings = bindings.ProxyBindings; + const StubBindings = bindings.StubBindings; const ServiceProviderInterface = serviceProviderMojom.ServiceProvider; function checkServiceProvider(sp) { @@ -18,7 +21,8 @@ define("mojo/services/public/js/service_provider", [ constructor(service) { if (!(service instanceof ServiceProviderInterface.proxyClass)) throw new Error("service must be a ServiceProvider proxy"); - service.local$ = this; // Implicitly sets this.remote$ to service. + this.proxy = service; + ProxyBindings(this.proxy).setLocalDelegate(this); this.providers_ = new Map(); // serviceName => see provideService() below this.pendingRequests_ = new Map(); // serviceName => serviceHandle } @@ -35,8 +39,9 @@ define("mojo/services/public/js/service_provider", [ } var proxy = connection.bindProxyHandle( serviceHandle, provider.service, provider.service.client); - proxy.local$ = new provider.factory(proxy); - provider.connections.push(proxy.connection$); + if (ProxyBindings(proxy).local) + ProxyBindings(proxy).setLocalDelegate(new provider.factory(proxy)); + provider.connections.push(ProxyBindings(proxy).connection); } provideService(service, factory) { @@ -64,12 +69,12 @@ define("mojo/services/public/js/service_provider", [ if (!clientImpl && interfaceObject.client) throw new Error("Client implementation must be provided"); - if (!clientImpl) - clientImpl = {}; + var remoteProxy; + var clientFactory = function(x) {remoteProxy = x; return clientImpl;}; var messagePipeHandle = connection.bindProxyClient( - clientImpl, interfaceObject.client, interfaceObject); - this.remote$.connectToService(interfaceObject.name, messagePipeHandle); - return clientImpl.remote$; + clientFactory, interfaceObject.client, interfaceObject); + this.proxy.connectToService(interfaceObject.name, messagePipeHandle); + return remoteProxy; }; close() { diff --git a/mojo/services/public/js/shell.js b/mojo/services/public/js/shell.js index fdec4b1..338de5e 100644 --- a/mojo/services/public/js/shell.js +++ b/mojo/services/public/js/shell.js @@ -3,17 +3,21 @@ // found in the LICENSE file. define("mojo/services/public/js/shell", [ + "mojo/public/js/bindings", "mojo/public/js/core", "mojo/public/js/connection", "mojo/public/interfaces/application/shell.mojom", "mojo/public/interfaces/application/service_provider.mojom", - "mojo/services/public/js/service_provider" -], function(core, + "mojo/services/public/js/service_provider", +], function(bindings, + core, connection, shellMojom, serviceProviderMojom, serviceProvider) { + const ProxyBindings = bindings.ProxyBindings; + const StubBindings = bindings.StubBindings; const ServiceProvider = serviceProvider.ServiceProvider; const ServiceProviderInterface = serviceProviderMojom.ServiceProvider; const ShellInterface = shellMojom.Shell; @@ -23,7 +27,8 @@ define("mojo/services/public/js/shell", [ this.shellHandle = shellHandle; this.proxy = connection.bindProxyHandle( shellHandle, ShellInterface.client, ShellInterface); - this.proxy.local$ = app; // The app is the shell's client. + + ProxyBindings(this.proxy).setLocalDelegate(app); // TODO: call this serviceProviders_ this.applications_ = new Map(); } @@ -33,9 +38,9 @@ define("mojo/services/public/js/shell", [ if (application) return application; - var returnValue = {}; - this.proxy.connectToApplication(url, returnValue); - application = new ServiceProvider(returnValue.remote$); + this.proxy.connectToApplication(url, function(sp) { + application = new ServiceProvider(sp); + }); this.applications_.set(url, application); return application; } |