Skip to content

Commit 949ab72

Browse files
author
Arindam Bose
authored
Switch back to using host url instead of a blob-url to load rtl-text-plugin on the worker (#9122) (#9123)
(cherry picked from commit 26a47e4)
1 parent 1b1f474 commit 949ab72

File tree

4 files changed

+14
-30
lines changed

4 files changed

+14
-30
lines changed

src/source/rtl_text_plugin.js

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import {Event, Evented} from '../util/evented';
44
import {getArrayBuffer} from '../util/ajax';
55
import browser from '../util/browser';
6-
import window from '../util/window';
76
import assert from 'assert';
87
import {isWorker} from '../util/util';
98

@@ -17,8 +16,7 @@ const status = {
1716

1817
export type PluginState = {
1918
pluginStatus: $Values<typeof status>;
20-
pluginURL: ?string,
21-
pluginBlobURL: ?string
19+
pluginURL: ?string
2220
};
2321

2422
type ErrorCallback = (error: ?Error) => void;
@@ -28,7 +26,6 @@ let _completionCallback = null;
2826
//Variables defining the current state of the plugin
2927
let pluginStatus = status.unavailable;
3028
let pluginURL = null;
31-
let pluginBlobURL = null;
3229

3330
export const triggerPluginCompletionEvent = function(error: ?Error) {
3431
if (_completionCallback) {
@@ -37,7 +34,7 @@ export const triggerPluginCompletionEvent = function(error: ?Error) {
3734
};
3835

3936
function sendPluginStateToWorker() {
40-
evented.fire(new Event('pluginStateChange', {pluginStatus, pluginURL, pluginBlobURL}));
37+
evented.fire(new Event('pluginStateChange', {pluginStatus, pluginURL}));
4138
}
4239

4340
export const evented = new Evented();
@@ -48,7 +45,7 @@ export const getRTLTextPluginStatus = function () {
4845

4946
export const registerForPluginStateChange = function(callback: PluginStateSyncCallback) {
5047
// Do an initial sync of the state
51-
callback({pluginStatus, pluginURL, pluginBlobURL});
48+
callback({pluginStatus, pluginURL});
5249
// Listen for all future state changes
5350
evented.on('pluginStateChange', callback);
5451
return callback;
@@ -57,10 +54,6 @@ export const registerForPluginStateChange = function(callback: PluginStateSyncCa
5754
export const clearRTLTextPlugin = function() {
5855
pluginStatus = status.unavailable;
5956
pluginURL = null;
60-
if (pluginBlobURL) {
61-
window.URL.revokeObjectURL(pluginBlobURL);
62-
}
63-
pluginBlobURL = null;
6457
};
6558

6659
export const setRTLTextPlugin = function(url: string, callback: ?ErrorCallback, deferred: boolean = false) {
@@ -85,12 +78,10 @@ export const downloadRTLTextPlugin = function() {
8578
pluginStatus = status.loading;
8679
sendPluginStateToWorker();
8780
if (pluginURL) {
88-
getArrayBuffer({url: pluginURL}, (error, data) => {
81+
getArrayBuffer({url: pluginURL}, (error) => {
8982
if (error) {
9083
triggerPluginCompletionEvent(error);
9184
} else {
92-
const rtlBlob = new window.Blob([data], {type: 'application/javascript'});
93-
pluginBlobURL = window.URL.createObjectURL(rtlBlob);
9485
pluginStatus = status.loaded;
9586
sendPluginStateToWorker();
9687
}
@@ -106,7 +97,7 @@ export const plugin: {
10697
isLoading: () => boolean,
10798
setState: (state: PluginState) => void,
10899
isParsed: () => boolean,
109-
getURLs: () => { blob: ?string, host: ?string }
100+
getPluginURL: () => ?string
110101
} = {
111102
applyArabicShaping: null,
112103
processBidirectionalText: null,
@@ -123,7 +114,6 @@ export const plugin: {
123114

124115
pluginStatus = state.pluginStatus;
125116
pluginURL = state.pluginURL;
126-
pluginBlobURL = state.pluginBlobURL;
127117
},
128118
isParsed(): boolean {
129119
assert(isWorker(), 'rtl-text-plugin is only parsed on the worker-threads');
@@ -132,13 +122,9 @@ export const plugin: {
132122
plugin.processBidirectionalText != null &&
133123
plugin.processStyledBidirectionalText != null;
134124
},
135-
getURLs(): { blob: ?string, host: ?string } {
136-
assert(isWorker(), 'rtl-text-plugin urls can only be queried from the worker threads');
137-
138-
return {
139-
blob: pluginBlobURL,
140-
host: pluginURL,
141-
};
125+
getPluginURL(): ?string {
126+
assert(isWorker(), 'rtl-text-plugin url can only be queried from the worker threads');
127+
return pluginURL;
142128
}
143129
};
144130

src/source/worker.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,15 @@ export default class Worker {
156156
syncRTLPluginState(map: string, state: PluginState, callback: Callback<boolean>) {
157157
try {
158158
globalRTLTextPlugin.setState(state);
159-
const {blob, host} = globalRTLTextPlugin.getURLs();
159+
const pluginURL = globalRTLTextPlugin.getPluginURL();
160160
if (
161161
globalRTLTextPlugin.isLoaded() &&
162162
!globalRTLTextPlugin.isParsed() &&
163-
blob != null && host != null // Not possible when `isLoaded` is true, but keeps flow happy
163+
pluginURL != null // Not possible when `isLoaded` is true, but keeps flow happy
164164
) {
165-
this.self.importScripts(blob);
165+
this.self.importScripts(pluginURL);
166166
const complete = globalRTLTextPlugin.isParsed();
167-
const error = complete ? undefined : new Error(`RTL Text Plugin failed to import scripts from ${host}`);
167+
const error = complete ? undefined : new Error(`RTL Text Plugin failed to import scripts from ${pluginURL}`);
168168
callback(error, complete);
169169
}
170170
} catch (e) {

src/style/style.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ class Style extends Evented {
159159
this._rtlTextPluginCallback = Style.registerForPluginStateChange((event) => {
160160
const state = {
161161
pluginStatus: event.pluginStatus,
162-
pluginURL: event.pluginURL,
163-
pluginBlobURL: event.pluginBlobURL
162+
pluginURL: event.pluginURL
164163
};
165164
self.dispatcher.broadcast('syncRTLPluginState', state, (err, results) => {
166165
triggerPluginCompletionEvent(err);

test/unit/style/style.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ test('Style', (t) => {
7474
setRTLTextPlugin("/plugin.js",);
7575
t.ok(style.dispatcher.broadcast.calledWith('syncRTLPluginState', {
7676
pluginStatus: 'deferred',
77-
pluginURL: "/plugin.js",
78-
pluginBlobURL: null
77+
pluginURL: "/plugin.js"
7978
}));
8079
window.clearFakeWorkerPresence();
8180
t.end();

0 commit comments

Comments
 (0)