From 725e9855fedb30474d819051b96f7eec571c2a10 Mon Sep 17 00:00:00 2001 From: Scott Kyle Date: Tue, 20 Oct 2015 23:59:02 -0700 Subject: [PATCH] Update RPC JS to use originalXMLHttpRequest React Native now leaves the original object accessible when it "polyfills" objects. So we check for that, but still have the previous logic in place in case they change their minds. --- lib/.eslintrc | 3 +++ lib/rpc.js | 12 ++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/.eslintrc b/lib/.eslintrc index 5e03e21c..fb4738fd 100644 --- a/lib/.eslintrc +++ b/lib/.eslintrc @@ -6,6 +6,9 @@ "browser": true, "es6": true, }, + "globals": { + "global": true + }, "rules": { "comma-dangle": 0, "no-unused-vars": 1, diff --git a/lib/rpc.js b/lib/rpc.js index 7a0a1d8d..c92d287b 100644 --- a/lib/rpc.js +++ b/lib/rpc.js @@ -5,16 +5,16 @@ let constants = require('./constants'); let DEVICE_HOST = 'localhost:8082'; let {keys, objectTypes, propTypes} = constants; +let XMLHttpRequest = global.originalXMLHttpRequest || global.XMLHttpRequest; let typeConverters = {}; -let XMLHttpRequest = window.XMLHttpRequest; let sessionId; // Check if XMLHttpRequest has been overridden, and get the native one if that's the case. -if (XMLHttpRequest.__proto__ != window.XMLHttpRequestEventTarget) { - let override = XMLHttpRequest; - delete window.XMLHttpRequest; - XMLHttpRequest = window.XMLHttpRequest; - window.XMLHttpRequest = override; +if (XMLHttpRequest.__proto__ != global.XMLHttpRequestEventTarget) { + let fakeXMLHttpRequest = XMLHttpRequest; + delete global.XMLHttpRequest; + XMLHttpRequest = global.XMLHttpRequest; + global.XMLHttpRequest = fakeXMLHttpRequest; } module.exports = {