Support invoking and returning arbitrary types from Java sync hooks

Reviewed By: mhorowitz

Differential Revision: D4409900

fbshipit-source-id: 347e33c442b32f64355d343308c218c15cf5a70f
This commit is contained in:
Pieter De Baets
2017-01-31 05:17:33 -08:00
committed by Facebook Github Bot
parent cfb90284d6
commit f8c72f5441
13 changed files with 318 additions and 52 deletions

View File

@@ -18,6 +18,7 @@ require('ViewRenderingTestModule');
require('TestJavaToJSArgumentsModule');
require('TestJSLocaleModule');
require('TestJSToJavaParametersModule');
require('TestJavaToJSReturnValuesModule');
require('UIManagerTestModule');
require('CatalystRootViewTestModule');

View File

@@ -18,6 +18,9 @@ var TestJSToJavaParametersModule = {
returnBasicTypes: function() {
Recording.receiveBasicTypes('foo', 3.14, true, null);
},
returnBoxedTypes: function() {
Recording.receiveBoxedTypes(42, 3.14, true);
},
returnDynamicTypes: function() {
Recording.receiveDynamic('foo');
Recording.receiveDynamic(3.14);

View File

@@ -0,0 +1,40 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule TestJavaToJSReturnValuesModule
*/
'use strict';
const BatchedBridge = require('BatchedBridge');
const {assertEquals, assertTrue} = require('Asserts');
const {TestModule} = require('NativeModules');
var TestJavaToJSReturnValuesModule = {
callMethod: function(methodName, expectedType, expectedJSON) {
const result = TestModule[methodName]();
assertEquals(expectedType, typeof result);
assertEquals(expectedJSON, JSON.stringify(result));
},
triggerException: function() {
try {
TestModule.triggerException();
} catch (ex) {
assertTrue(ex.message.indexOf('Exception triggered') !== -1);
}
}
};
BatchedBridge.registerCallableModule(
'TestJavaToJSReturnValuesModule',
TestJavaToJSReturnValuesModule
);
module.exports = TestJavaToJSReturnValuesModule;