Skip to content
This repository has been archived by the owner on Aug 4, 2018. It is now read-only.

Commit

Permalink
Fix detection for server-side environments.
Browse files Browse the repository at this point in the history
  • Loading branch information
bnjmnt4n committed Dec 29, 2017
1 parent 36e0921 commit a5092fd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
language: node_js
sudo: false
node_js:
- 7
- 8

cache:
directories:
- ~/.npm
- ~/.yarn-cache
- travis_phantomjs
- travis_ringojs

Expand Down Expand Up @@ -48,12 +47,12 @@ before_install:
# Install RingoJS.
- |
export RINGOJS_VERSION=0.11
export RINGOJS_VERSION=1.2.1
export PATH=$PWD/travis_ringojs/ringojs-$RINGOJS_VERSION/bin:$PATH
if [ ! -f "$(which ringo)" ]; then
if [ ! -f "$(which ringo)" ] || [ $(ringo --version | grep -Eo '[0-9.]+') != $RINGOJS_VERSION ]; then
rm -rf $PWD/travis_ringojs
mkdir -p $PWD/travis_ringojs
wget https://github.com/ringo/ringojs/releases/download/v$RINGOJS_VERSION.0/ringojs-$RINGOJS_VERSION.tar.gz
wget https://github.com/ringo/ringojs/releases/download/v$RINGOJS_VERSION/ringojs-$RINGOJS_VERSION.tar.gz
tar -xvf ringojs-$RINGOJS_VERSION.tar.gz -C $PWD/travis_ringojs
fi
ringo -v
Expand Down
17 changes: 8 additions & 9 deletions platform.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* Platform.js <https://mths.be/platform>
* Copyright 2014-2016 Benjamin Tan <https://demoneaux.github.io/>
* Copyright 2014-2018 Benjamin Tan <https://bnjmnt4n.now.sh/>
* Copyright 2011-2013 John-David Dalton <http://allyoucanleet.com/>
* Available under MIT license <https://mths.be/mit>
*/
Expand Down Expand Up @@ -742,17 +742,19 @@
arch = data.getProperty('os.arch');
os = os || data.getProperty('os.name') + ' ' + data.getProperty('os.version');
}
if (isModuleScope && isHostType(context, 'system') && (data = [context.system])[0]) {
os || (os = data[0].os || null);
if (rhino) {
try {
data[1] = context.require('ringo/engine').version;
version = data[1].join('.');
version = context.require('ringo/engine').version.join('.');
name = 'RingoJS';
} catch(e) {
if (data[0].global.system == context.system) {
if ((data = context.system) && data.global.system == context.system) {
name = 'Narwhal';
os || (os = data[0].os || null);
}
}
if (!name) {
name = 'Rhino';
}
}
else if (
typeof context.process == 'object' && !context.process.browser &&
Expand All @@ -777,9 +779,6 @@
version = version ? version[0] : null;
}
}
else if (rhino) {
name = 'Rhino';
}
}
// Detect Adobe AIR.
else if (getClassOf((data = context.runtime)) == airRuntimeClass) {
Expand Down
33 changes: 26 additions & 7 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1714,12 +1714,15 @@
'version': '1.19'
},

'Narwhal': (function() {
'Narwhal on Mac OS X 64-bit': (function() {
var object = {
'environment': {},
'exports': {},
'java': { 'lang': { 'System': { 'getProperty': function(property) { return /name/.test(property) ? 'Mac OS X' : 'x86_64'; } } } },
'name': 'Narwhal',
'os': 'Mac OS X 64-bit',
'require': function() {},
'system': {}
'system': { 'os': 'Mac OS X' }
};
object.global = object.system.global = object;
return object;
Expand Down Expand Up @@ -2022,18 +2025,21 @@
'os': 'Linux i686'
},

'Rhino on OS X 64-bit': {
'Rhino on Mac OS X 64-bit': {
'environment': {},
'global': {},
'java': { 'lang': { 'System': { 'getProperty': function(property) { return /name/.test(property) ? 'OS X' : 'x86_64'; } } } },
'java': { 'lang': { 'System': { 'getProperty': function(property) { return /name/.test(property) ? 'Mac OS X' : 'x86_64'; } } } },
'name': 'Rhino',
'os': 'OS X 64-bit'
'os': 'Mac OS X 64-bit'
},

'RingoJS 0.7': (function() {
'RingoJS 0.7 on Mac OS X 64-bit': (function() {
var object = {
'environment': {},
'exports': {},
'java': { 'lang': { 'System': { 'getProperty': function(property) { return /name/.test(property) ? 'Mac OS X' : 'x86_64'; } } } },
'name': 'RingoJS',
'os': 'Mac OS X 64-bit',
'require': function() { return { 'version': [0, 7] }; },
'system': {},
'version': '0.7'
Expand All @@ -2042,6 +2048,20 @@
return object;
}()),

'RingoJS 1.2.1 on Mac OS X 64-bit': (function() {
var object = {
'environment': {},
'exports': {},
'java': { 'lang': { 'System': { 'getProperty': function(property) { return /name/.test(property) ? 'Mac OS X' : 'x86_64'; } } } },
'name': 'RingoJS',
'os': 'Mac OS X 64-bit',
'require': function() { return { 'version': [1, 2, 1] }; },
'version': '1.2.1'
};
object.global = object;
return object;
}()),

'RockMelt 0.8.34.820 (like Chrome 6.0.472.63) on OS X 10.5.8': {
'ua': 'Mozilla/5.0(Macintosh; U; Intel Mac OS X 10_5_8; en-US)AppleWebKit/534.3(KHTML,like Gecko)RockMelt/0.8.34.820 Chrome/6.0.472.63 Safari/534.3',
'layout': 'WebKit',
Expand Down Expand Up @@ -2587,7 +2607,6 @@
};

/*--------------------------------------------------------------------------*/

QUnit.module('platform' + (document ? '' : ': ' + platform));

(function() {
Expand Down

0 comments on commit a5092fd

Please sign in to comment.