1
0
mirror of synced 2025-12-08 14:54:02 +08:00

Fix: Uc browser worker #62

This commit is contained in:
surunzi
2018-05-27 19:38:49 +08:00
parent 8227abe686
commit e6342d9b3f
8 changed files with 1844 additions and 1495 deletions

View File

@@ -198,14 +198,14 @@ Insert content to the end of elements.
```javascript
// <div id="test"><div class="mark"></div></div>
$insert.before('#test', '<div>eris</div>');
// -> <div>eris</div><div id="test"><div class="mark"></div></div>
$insert.after('#test', '<div>eris</div>');
// -> <div id="test"><div class="mark"></div></div><div>eris</div>
$insert.prepend('#test', '<div>eris</div>');
// -> <div id="test"><div>eris</div><div class="mark"></div></div>
$insert.append('#test', '<div>eris</div>');
// -> <div id="test"><div class="mark"></div><div>eris</div></div>
$insert.before('#test', '<div>licia</div>');
// -> <div>licia</div><div id="test"><div class="mark"></div></div>
$insert.after('#test', '<div>licia</div>');
// -> <div id="test"><div class="mark"></div></div><div>licia</div>
$insert.prepend('#test', '<div>licia</div>');
// -> <div id="test"><div>licia</div><div class="mark"></div></div>
$insert.append('#test', '<div>licia</div>');
// -> <div id="test"><div class="mark"></div><div>licia</div></div>
```
## $offset
@@ -241,8 +241,8 @@ Get the current value of the first element in the set of matched elements or
set the value of every matched element.
```javascript
$property.html('#test', 'eris');
$property.html('#test'); // -> eris
$property.html('#test', 'licia');
$property.html('#test'); // -> licia
```
## $remove
@@ -412,8 +412,8 @@ Extend from Store.
|data|object|Default data |
```javascript
var store = new LocalStore('eris');
store.set('name', 'eris');
var store = new LocalStore('licia');
store.set('name', 'licia');
```
## Logger
@@ -446,7 +446,7 @@ Logging methods.
TRACE, DEBUG, INFO, WARN, ERROR and SILENT.
```javascript
var logger = new Logger('eris', Logger.level.ERROR);
var logger = new Logger('licia', Logger.level.ERROR);
logger.trace('test');
// Format output.
@@ -582,8 +582,8 @@ Iterate over values.
```javascript
var store = new Store('test');
store.set('user', {name: 'eris'});
store.get('user').name; // -> 'eris'
store.set('user', {name: 'licia'});
store.get('user').name; // -> 'licia'
store.clear();
store.each(function (val, key)
{
@@ -601,9 +601,9 @@ Simple url manipulator.
### constructor
|Name |Type |Desc |
|---------------------|------|----------|
|[url=window.location]|string|Url string|
|Name |Type |Desc |
|------------|------|----------|
|url=location|string|Url string|
### setQuery
@@ -1039,6 +1039,14 @@ if (browser.name === 'ie' && browser.version < 9)
}
```
## detectMocha
Detect if mocha is running.
```javascript
detectMocha(); // -> True if mocha is running.
```
## detectOs
Detect operating system using ua.
@@ -1127,7 +1135,7 @@ Escape special chars to be used as literals in RegExp constructors.
|return|string|Escaped string |
```javascript
escapeRegExp('[eris]'); // -> '\\[eris\\]'
escapeRegExp('[licia]'); // -> '\\[licia\\]'
```
## evalCss
@@ -1458,6 +1466,14 @@ Check if keys and values in src are contained in obj.
isMatch({a: 1, b: 2}, {a: 1}); // -> true
```
## isMiniProgram
Check if running in wechat mini program.
```javascript
console.log(isMiniProgram); // -> true if running in mini program.
```
## isMobile
Check whether client is using a mobile browser using ua.
@@ -1586,7 +1602,7 @@ Check if value is a string primitive.
|return|boolean|True if value is a string primitive|
```javascript
isStr('eris'); // -> true
isStr('licia'); // -> true
```
## isUndef
@@ -1735,7 +1751,7 @@ A replacement for environments where localStorage or sessionStorage is not avail
```javascript
var localStorage = window.localStorage || memStorage;
localStorage.setItem('test', 'eris');
localStorage.setItem('test', 'licia');
```
## memoize
@@ -2272,6 +2288,25 @@ trim('_abc_', '_'); // -> 'abc'
trim('_abc_', ['a', 'c', '_']); // -> 'b'
```
## tryIt
Run function in a try catch.
|Name|Type |Desc |
|----|--------|---------------------|
|fn |function|Function to try catch|
|[cb]|function|Callback |
```javascript
tryIt(function ()
{
// Do something that might cause an error.
}, function (err, result)
{
if (err) console.log(err);
});
```
## type
Determine the internal JavaScript [[Class]] of an object.

View File

@@ -1,6 +1,6 @@
import stringify from '../lib/stringify';
import StringifyWorker from '../lib/stringifyWorker';
import {nextTick, uniqId} from '../lib/util';
import {nextTick, uniqId, tryIt} from '../lib/util';
let isWorkerSupported = !!window.Worker;
@@ -9,21 +9,27 @@ let callbacks = {},
if (isWorkerSupported)
{
worker = new StringifyWorker();
worker.onmessage = function (e)
tryIt(function ()
{
let [id, result] = e.data;
if (callbacks[id])
/* Some browsers like uc mobile doesn't destroy worker properly after refreshing.
* After a few times of visiting, it reaches the maximum number of workers per site.
*/
worker = new StringifyWorker();
worker.onmessage = function (e)
{
callbacks[id](result);
delete callbacks[id];
}
};
let [id, result] = e.data;
if (callbacks[id])
{
callbacks[id](result);
delete callbacks[id];
}
};
});
}
function exports(obj, options, cb)
{
let useWorker = exports.useWorker && isWorkerSupported;
let useWorker = exports.useWorker && isWorkerSupported && worker;
if (useWorker)
{

View File

@@ -1,4 +1,4 @@
import {each} from '../lib/util';
import {each, has} from '../lib/util';
function formatStyle(style)
{
@@ -47,7 +47,7 @@ export default class CssStore
each(document.styleSheets, (styleSheet) =>
{
// Started with version 64, Chrome does not allow cross origin script to access this property.
if (!styleSheet.hasOwnProperty('cssRules')) return;
if (!has(styleSheet, 'cssRules')) return;
each(styleSheet.cssRules, (cssRule) =>
{

View File

@@ -46,11 +46,11 @@ export var idxOf = _.idxOf = (function ()
{
/* Get the index at which the first occurrence of value.
*
* |Name |Type |Desc |
* |-----------|------|--------------------|
* |arr |array |Array to search |
* |val |* |Value to search for |
* |[fromIdx=0]|number|Index to search from|
* |Name |Type |Desc |
* |---------|------|--------------------|
* |arr |array |Array to search |
* |val |* |Value to search for |
* |fromIdx=0|number|Index to search from|
*
* ```javascript
* idxOf([1, 2, 1, 2], 2, 2); // -> 3
@@ -133,7 +133,7 @@ export var optimizeCb = _.optimizeCb = (function ()
case 4: return function (accumulator, val, idx, collection)
{
return fn.call(ctx, accumulator, val, idx, collection);
}
};
}
return function ()
@@ -312,46 +312,6 @@ export var has = _.has = (function ()
return exports;
})();
/* ------------------------------ keys ------------------------------ */
export var keys = _.keys = (function (exports)
{
/* Create an array of the own enumerable property names of object.
*
* |Name |Type |Desc |
* |------|------|-----------------------|
* |obj |object|Object to query |
* |return|array |Array of property names|
*
* ```javascript
* keys({a: 1}); // -> ['a']
* ```
*/
/* module
* env: all
* test: all
*/
/* dependencies
* has
*/
exports = Object.keys || function (obj)
{
var ret = [], key;
for (key in obj)
{
if (has(obj, key)) ret.push(key);
}
return ret;
};
return exports;
})({});
/* ------------------------------ identity ------------------------------ */
export var identity = _.identity = (function ()
@@ -597,6 +557,132 @@ export var isArrLike = _.isArrLike = (function ()
return exports;
})();
/* ------------------------------ isBrowser ------------------------------ */
export var isBrowser = _.isBrowser = (function (exports)
{
/* Check if running in a browser.
*
* ```javascript
* console.log(isBrowser); // -> true if running in a browser
* ```
*/
/* module
* env: all
* test: all
*/
exports = typeof window === 'object' &&
typeof document === 'object' &&
document.nodeType === 9;
return exports;
})({});
/* ------------------------------ root ------------------------------ */
export var root = _.root = (function (exports)
{
/* Root object reference, `global` in nodeJs, `window` in browser. */
/* module
* env: all
* test: all
*/
/* dependencies
* isBrowser
*/
exports = isBrowser ? window : global;
return exports;
})({});
/* ------------------------------ detectMocha ------------------------------ */
export var detectMocha = _.detectMocha = (function ()
{
/* Detect if mocha is running.
*
* ```javascript
* detectMocha(); // -> True if mocha is running.
* ```
*/
/* module
* env: all
* test: all
*/
/* dependencies
* root
*/
function exports()
{
for (var i = 0, len = methods.length; i < len; i++)
{
var method = methods[i];
if (typeof root[method] !== 'function') return false;
}
return true;
}
var methods = ['afterEach','after','beforeEach','before','describe','it'];
return exports;
})();
/* ------------------------------ keys ------------------------------ */
export var keys = _.keys = (function (exports)
{
/* Create an array of the own enumerable property names of object.
*
* |Name |Type |Desc |
* |------|------|-----------------------|
* |obj |object|Object to query |
* |return|array |Array of property names|
*
* ```javascript
* keys({a: 1}); // -> ['a']
* ```
*/
/* module
* env: all
* test: all
*/
/* dependencies
* has detectMocha
*/
if (Object.keys && !detectMocha())
{
exports = Object.keys;
} else
{
exports = function (obj)
{
var ret = [], key;
for (key in obj)
{
if (has(obj, key)) ret.push(key);
}
return ret;
};
}
return exports;
})({});
/* ------------------------------ each ------------------------------ */
export var each = _.each = (function ()
@@ -723,37 +809,6 @@ export var extend = _.extend = (function (exports)
return exports;
})({});
/* ------------------------------ extendOwn ------------------------------ */
export var extendOwn = _.extendOwn = (function (exports)
{
/* Like extend, but only copies own properties over to the destination object.
*
* |Name |Type |Desc |
* |------|------|------------------|
* |obj |object|Destination object|
* |*src |object|Sources objects |
* |return|object|Destination object|
*
* ```javascript
* extendOwn({name: 'RedHood'}, {age: 24}); // -> {name: 'RedHood', age: 24}
* ```
*/
/* module
* env: all
* test: all
*/
/* dependencies
* keys createAssigner
*/
exports = createAssigner(keys);
return exports;
})({});
/* ------------------------------ values ------------------------------ */
export var values = _.values = (function ()
@@ -783,7 +838,7 @@ export var values = _.values = (function ()
{
var ret = [];
each(obj, function (val) { ret.push(val) });
each(obj, function (val) { ret.push(val); });
return ret;
}
@@ -828,6 +883,37 @@ export var contain = _.contain = (function ()
return exports;
})();
/* ------------------------------ extendOwn ------------------------------ */
export var extendOwn = _.extendOwn = (function (exports)
{
/* Like extend, but only copies own properties over to the destination object.
*
* |Name |Type |Desc |
* |------|------|------------------|
* |obj |object|Destination object|
* |*src |object|Sources objects |
* |return|object|Destination object|
*
* ```javascript
* extendOwn({name: 'RedHood'}, {age: 24}); // -> {name: 'RedHood', age: 24}
* ```
*/
/* module
* env: all
* test: all
*/
/* dependencies
* keys createAssigner
*/
exports = createAssigner(keys);
return exports;
})({});
/* ------------------------------ isStr ------------------------------ */
export var isStr = _.isStr = (function ()
@@ -840,7 +926,7 @@ export var isStr = _.isStr = (function ()
* |return|boolean|True if value is a string primitive|
*
* ```javascript
* isStr('eris'); // -> true
* isStr('licia'); // -> true
* ```
*/
@@ -1119,7 +1205,7 @@ export var safeCb = _.safeCb = (function (exports)
return function (obj)
{
return obj == null ? undefined : obj[key];
}
};
};
};

File diff suppressed because it is too large Load Diff

View File

@@ -9,7 +9,13 @@ function boot(name, cb)
options.tool = name === 'settings' ? [] : name;
}
eruda.init(options);
try
{
eruda.init(options);
} catch (e)
{
alert(e);
}
eruda.show().get().config.set('displaySize', 50);
cb && cb();

View File

@@ -48,7 +48,13 @@
var el = document.createElement('div');
document.body.appendChild(el);
setTimeout(function () {
eruda.init({container: el});
try
{
eruda.init({container: el});
} catch (e)
{
alert(e);
}
eruda.show().get().config.set('displaySize', 50);
}, 1000);
})();

File diff suppressed because it is too large Load Diff