Skip to content

Commit

Permalink
minor cleanup (emscripten-core#5296)
Browse files Browse the repository at this point in the history
  • Loading branch information
buu700 committed Jun 14, 2017
1 parent 6ebbef4 commit 5c334b8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
4 changes: 3 additions & 1 deletion emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1605,7 +1605,7 @@ def get_final():

with ToolchainProfiler.profile_block('memory initializer'):
memfile = None
embed_memfile = shared.Settings.MEM_INIT_METHOD == 0 and (not shared.Settings.MAIN_MODULE and not shared.Settings.SIDE_MODULE and options.debug_level < 4)
embed_memfile = (Settings.SINGLE_FILE or shared.Settings.MEM_INIT_METHOD == 0) and (not shared.Settings.MAIN_MODULE and not shared.Settings.SIDE_MODULE and options.debug_level < 4)

if shared.Settings.MEM_INIT_METHOD > 0 or embed_memfile:
memfile = target + '.mem'
Expand Down Expand Up @@ -1634,6 +1634,8 @@ def repl(m):
final += '.mem.js'
src = None
js_transform_tempfiles[-1] = final # simple text substitution preserves comment line number mappings
if embed_memfile:
os.remove(memfile)
if DEBUG:
if os.path.exists(memfile):
save_intermediate('meminit')
Expand Down
14 changes: 7 additions & 7 deletions src/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ if (ENVIRONMENT_IS_NODE) {
var nodePath;

Module['read'] = function shell_read(filename, binary) {
var ret = parseDataURI(filename);
var ret = tryParseAsDataURI(filename);
if (!ret) {
if (!nodeFS) nodeFS = require('fs');
if (!nodePath) nodePath = require('path');
Expand Down Expand Up @@ -137,7 +137,7 @@ else if (ENVIRONMENT_IS_SHELL) {

if (typeof read != 'undefined') {
Module['read'] = function shell_read(f) {
var data = parseDataURI(f);
var data = tryParseAsDataURI(f);
if (data) {
return sodiumUtil.to_string(data);
}
Expand All @@ -148,7 +148,7 @@ else if (ENVIRONMENT_IS_SHELL) {
}

Module['readBinary'] = function readBinary(f) {
var data = parseDataURI(f);
var data = tryParseAsDataURI(f);
if (data) {
return data;
}
Expand Down Expand Up @@ -178,7 +178,7 @@ else if (ENVIRONMENT_IS_SHELL) {
}
else if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
Module['read'] = function shell_read(url) {
var data = parseDataURI(url);
var data = tryParseAsDataURI(url);
if (data) {
return sodiumUtil.to_string(data);
}
Expand All @@ -190,7 +190,7 @@ else if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {

if (ENVIRONMENT_IS_WORKER) {
Module['readBinary'] = function readBinary(url) {
var data = parseDataURI(f);
var data = tryParseAsDataURI(f);
if (data) {
return data;
}
Expand All @@ -204,7 +204,7 @@ else if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {

Module['readAsync'] = function readAsync(url, onload, onerror) {
try {
var data = parseDataURI(url);
var data = tryParseAsDataURI(url);
if (data) {
setTimeout(function () { onload(data.buffer); }, 0);
return;
Expand Down Expand Up @@ -264,7 +264,7 @@ else {

// If filename is a base64 data URI, parses and returns data (Buffer on node,
// Uint8Array otherwise). If filename is not a base64 data URI, returns undefined.
function parseDataURI(filename) {
function tryParseAsDataURI(filename) {
var dataURIPrefix = 'data:application/octet-stream;base64,';

if (!(
Expand Down
4 changes: 2 additions & 2 deletions tools/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -2279,8 +2279,8 @@ def to_nice_ident(ident): # limited version of the JS function toNiceIdent

# Returns the subresource location for run-time access
@staticmethod
def get_subresource_location(path, force_data_uri=False):
if Settings.SINGLE_FILE or force_data_uri:
def get_subresource_location(path, data_uri=Settings.SINGLE_FILE):
if data_uri:
f = open(path, 'rb')
data = base64.b64encode(f.read())
f.close()
Expand Down

0 comments on commit 5c334b8

Please sign in to comment.