Skip to content

Commit a483f80

Browse files
motiz88facebook-github-bot
authored andcommitted
Remove framesToPop from bridge
Summary: Removes the use of `framesToPop` from method wrappers in the RN bridge. Reviewed By: rubennorte Differential Revision: D17764986 fbshipit-source-id: f2fac0c33a9a7c821bb920fa65b92a4672150a38
1 parent 6140398 commit a483f80

File tree

3 files changed

+3
-72
lines changed

3 files changed

+3
-72
lines changed

Libraries/BatchedBridge/MessageQueue.js

+1-13
Original file line numberDiff line numberDiff line change
@@ -190,19 +190,7 @@ class MessageQueue {
190190
);
191191
}
192192
this.processCallbacks(moduleID, methodID, params, onFail, onSucc);
193-
try {
194-
return global.nativeCallSyncHook(moduleID, methodID, params);
195-
} catch (e) {
196-
if (
197-
typeof e === 'object' &&
198-
e != null &&
199-
typeof e.framesToPop === 'undefined' &&
200-
/^Exception in HostFunction: /.test(e.message)
201-
) {
202-
e.framesToPop = 2;
203-
}
204-
throw e;
205-
}
193+
return global.nativeCallSyncHook(moduleID, methodID, params);
206194
}
207195

208196
processCallbacks(

Libraries/BatchedBridge/NativeModules.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,9 @@ function loadModule(name: string, moduleID: number): ?Object {
9494
function genMethod(moduleID: number, methodID: number, type: MethodType) {
9595
let fn = null;
9696
if (type === 'promise') {
97-
fn = function(...args: Array<any>) {
97+
fn = function promiseMethodWrapper(...args: Array<any>) {
9898
// In case we reject, capture a useful stack trace here.
9999
const enqueueingFrameError: ExtendedError = new Error();
100-
enqueueingFrameError.framesToPop = 1;
101100
return new Promise((resolve, reject) => {
102101
BatchedBridge.enqueueNativeCall(
103102
moduleID,
@@ -110,7 +109,7 @@ function genMethod(moduleID: number, methodID: number, type: MethodType) {
110109
});
111110
};
112111
} else {
113-
fn = function(...args: Array<any>) {
112+
fn = function nonPromiseMethodWrapper(...args: Array<any>) {
114113
const lastArg = args.length > 0 ? args[args.length - 1] : null;
115114
const secondLastArg = args.length > 1 ? args[args.length - 2] : null;
116115
const hasSuccessCallback = typeof lastArg === 'function';

Libraries/BatchedBridge/__tests__/NativeModules-test.js

-56
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,6 @@ describe('MessageQueue', function() {
167167
}).toThrow();
168168
await expect(promise1).rejects.toBeInstanceOf(Error);
169169
await expect(promise1).rejects.toMatchObject({message: 'firstFailure'});
170-
// Check that we get a useful stack trace from failures.
171-
const error = await promise1.catch(x => x);
172-
expect(getLineFromFrame(parseErrorStack(error)[0])).toContain(
173-
'NativeModules.RemoteModule1.promiseReturningMethod(',
174-
);
175170

176171
// Handle the second remote invocation by signaling success.
177172
BatchedBridge.__invokeCallback(secondSuccCBID, ['secondSucc']);
@@ -211,36 +206,6 @@ describe('MessageQueue', function() {
211206
});
212207
});
213208

214-
it('throwing a "native" exception gets framesToPop = 2', function() {
215-
global.nativeCallSyncHook = () => {
216-
throw new Error('Exception in HostFunction: foo');
217-
};
218-
let error;
219-
try {
220-
NativeModules.RemoteModule1.syncMethod('paloAlto', 'menloPark');
221-
} catch (e) {
222-
error = e;
223-
}
224-
// We can't test this behaviour with `getLineFromFrame` because our mock
225-
// function adds an extra frame, so check `framesToPop` directly instead.
226-
expect(error.framesToPop).toBe(2);
227-
});
228-
229-
it('throwing a "native" exception preserves framesToPop if set', function() {
230-
global.nativeCallSyncHook = () => {
231-
const e = new Error('Exception in HostFunction: foo');
232-
e.framesToPop = 42;
233-
throw e;
234-
};
235-
let error;
236-
try {
237-
NativeModules.RemoteModule1.syncMethod('paloAlto', 'menloPark');
238-
} catch (e) {
239-
error = e;
240-
}
241-
expect(error.framesToPop).toBe(42);
242-
});
243-
244209
it('returning a value', function() {
245210
global.nativeCallSyncHook = jest.fn(() => {
246211
return 'secondSucc';
@@ -259,24 +224,3 @@ describe('MessageQueue', function() {
259224
});
260225
});
261226
});
262-
263-
const linesByFile = new Map();
264-
265-
function getLineFromFrame({lineNumber /* 1-based */, file}) {
266-
if (file == null) {
267-
return null;
268-
}
269-
const cleanedFile = cleanFileName(file);
270-
const lines =
271-
linesByFile.get(cleanedFile) ||
272-
fs.readFileSync(cleanedFile, 'utf8').split('\n');
273-
if (!linesByFile.has(cleanedFile)) {
274-
linesByFile.set(cleanedFile, lines);
275-
}
276-
return (lines[lineNumber - 1] || '').trim();
277-
}
278-
279-
// Works around a parseErrorStack bug involving `new X` stack frames.
280-
function cleanFileName(file) {
281-
return file.replace(/^.+? \((?=\/)/, '');
282-
}

0 commit comments

Comments
 (0)