Skip to content

Commit

Permalink
Updates for NativeScript support
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanaelA committed Sep 19, 2017
1 parent 1a8d575 commit e3606d6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
18 changes: 17 additions & 1 deletion lib/v8-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,27 @@
// Notes:
// The reason we are calling the functions twice before running optimizeFunctionOnNextCall, is
// because 2 calls are needed to go from uninitialized -> pre-monomorphic -> monomorphic

// The global/global.android/global.java check is for NativeScript, it doesn't have a process.execArgv like Node.

var v8;
if (process.execArgv.indexOf('--allow-natives-syntax') >= 0) {
if ((global && global.android && global.java) || (process && process.execArgv && process.execArgv.indexOf('--allow-natives-syntax') >= 0)) {
v8 = require('./v8-native-calls.js').v8;

// NativeScript does not have this function, so we need to polyfil it.
if (global && global.android && global.java) {
if (!global.process) { global.process = {}; }
if (!global.process.hrtime) {
global.process.hrtime = function(startTime) {
var now = java.lang.System.nanoTime() / 1000000;
if (Array.isArray(startTime)) {
return [0, now-startTime[1]];
}
return [0, now];
};
}
}

// This code just allows me to make sure the shim javascript has the same functions as the real thing, but it doesn't need to be active in production
/*
v8Dummy = require('./v8-native-dummy.js');
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"name" : "v8-natives",
"description" : "A simple API for accessing v8 native instructions",
"url" : "http://github.com/Nathanaela/v8-natives",
"keywords" : ["v8", "chrome", "chromium", "optimize", "optimization", "v8-natives", "speed", "performance"],
"keywords" : ["v8", "chrome", "chromium", "optimize", "optimization", "v8-natives", "speed", "performance", "nativescript"],
"author" : "Nathanael Anderson <[email protected]> (http://github.com/Nathanaela)",
"licenses" : "MIT",
"lib" : "lib",
"bugs" : {"url": "http://github.com/Nathanaela/v8-natives/issues"},
"repository" : {"type": "git", "url": "http://github.com/Nathanaela/v8-natives.git"},
"main" : "lib/v8-node",
"version" : "1.0.1",
"version" : "1.0.2",
"engines" : {"node": ">= 0.6.0" },
"directories" : {
"lib" : "lib",
Expand Down

0 comments on commit e3606d6

Please sign in to comment.