diff --git a/javascript/binding.gyp b/javascript/binding.gyp index e7be7a1d..a453164b 100644 --- a/javascript/binding.gyp +++ b/javascript/binding.gyp @@ -6,7 +6,7 @@ ], "sources": [ - "sources/yoga/Yoga.cpp", + " { +module.exports = (bind: any, lib: any): Yoga => { function patch(prototype, name, fn) { let original = prototype[name]; diff --git a/javascript/sources/entry-node.js b/javascript/sources/entry-node.js index 7f5b43b1..c5f2efc8 100644 --- a/javascript/sources/entry-node.js +++ b/javascript/sources/entry-node.js @@ -10,7 +10,7 @@ * @format */ -import Yoga from './entry-common'; +const Yoga = require('./entry-common'); const nbind = require('nbind'); const {bind, lib} = nbind.init(__dirname + '/../'); module.exports = Yoga(bind, lib); diff --git a/javascript/tests/Benchmarks/YGBenchmark.js b/javascript/tests/Benchmarks/YGBenchmark.js index 9839c01c..093be3bb 100644 --- a/javascript/tests/Benchmarks/YGBenchmark.js +++ b/javascript/tests/Benchmarks/YGBenchmark.js @@ -7,7 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -var Yoga = Yoga || require("../../sources/entry-" + process.env.TEST_ENTRY); +var Yoga = Yoga || require("../../dist/entry-" + process.env.TEST_ENTRY); var ITERATIONS = 2000; diff --git a/javascript/tests/run-bench.js b/javascript/tests/run-bench.js index 027fb0de..df36df04 100644 --- a/javascript/tests/run-bench.js +++ b/javascript/tests/run-bench.js @@ -5,6 +5,8 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. + * + * @format */ require(`./tools`); @@ -16,58 +18,52 @@ let WARMUP_ITERATIONS = 3; let BENCHMARK_ITERATIONS = 10; let testFiles = process.argv.slice(2).map(file => { - return fs.readFileSync(file).toString(); + return fs.readFileSync(file).toString(); }); let testResults = new Map(); -for (let type of [ `node`, `browser` ]) { +for (let type of [`node`, `browser`]) { + for (let file of testFiles) { + vm.runInNewContext( + file, + Object.assign(Object.create(global), { + Yoga: require(`../dist/entry-${type}`), + YGBENCHMARK: function(name, fn) { + let testEntry = testResults.get(name); - for (let file of testFiles) { + if (testEntry === undefined) + testResults.set(name, (testEntry = new Map())); - vm.runInNewContext(file, Object.assign(Object.create(global), { + for (let t = 0; t < WARMUP_ITERATIONS; ++t) fn(); - Yoga: require(`../sources/entry-${type}`), + let start = Date.now(); - YGBENCHMARK: function (name, fn) { + for (let t = 0; t < BENCHMARK_ITERATIONS; ++t) fn(); - let testEntry = testResults.get(name); - - if (testEntry === undefined) - testResults.set(name, testEntry = new Map()); - - for (let t = 0; t < WARMUP_ITERATIONS; ++t) - fn(); - - let start = Date.now(); - - for (let t = 0; t < BENCHMARK_ITERATIONS; ++t) - fn(); - - let end = Date.now(); - - testEntry.set(type, (end - start) / BENCHMARK_ITERATIONS); - - } - - })); - - } + let end = Date.now(); + testEntry.set(type, (end - start) / BENCHMARK_ITERATIONS); + }, + }), + ); + } } -console.log(`Note: those tests are independants; there is no time relation to be expected between them`); +console.log( + `Note: those tests are independants; there is no time relation to be expected between them`, +); -for (let [ name, results ] of testResults) { +for (let [name, results] of testResults) { + console.log(); - console.log(); + let min = Math.min(Infinity, ...results.values()); - let min = Math.min(Infinity, ... results.values()); - - console.log(name); - - for (let [ type, result ] of results) { - console.log(` - ${type}: ${result}ms (${Math.round(result / min * 10000) / 100}%)`); - } + console.log(name); + for (let [type, result] of results) { + console.log( + ` - ${type}: ${result}ms (${Math.round(result / min * 10000) / 100}%)`, + ); + } } diff --git a/javascript/tests/tools.js b/javascript/tests/tools.js index f31e3f0e..1d8b1f94 100644 --- a/javascript/tests/tools.js +++ b/javascript/tests/tools.js @@ -5,56 +5,63 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. + * + * @format */ -var target = typeof global !== "undefined" ? global : window; +var target = typeof global !== 'undefined' ? global : window; -target.getMeasureCounter = function (Yoga, cb, staticWidth, staticHeight) { +target.getMeasureCounter = function(Yoga, cb, staticWidth, staticHeight) { + var counter = 0; - var counter = 0; + return { + inc: function(width, widthMode, height, heightMode) { + counter += 1; - return { - - inc: function (width, widthMode, height, heightMode) { - - counter += 1; - - return cb ? cb(width, widthMode, height, heightMode) : { width: staticWidth, height: staticHeight }; - - }, - - get: function () { - - return counter; - - } - - }; - -} - -target.getMeasureCounterMax = function (Yoga) { - - return getMeasureCounter(Yoga, function (width, widthMode, height, heightMode) { - - var measuredWidth = widthMode === Yoga.MEASURE_MODE_UNDEFINED ? 10 : width; - var measuredHeight = heightMode === Yoga.MEASURE_MODE_UNDEFINED ? 10 : height; - - return { width: measuredWidth, height: measuredHeight }; - - }); + return cb + ? cb(width, widthMode, height, heightMode) + : {width: staticWidth, height: staticHeight}; + }, + get: function() { + return counter; + }, + }; }; -target.getMeasureCounterMin = function (Yoga) { - - return getMeasureCounter(Yoga, function (width, widthMode, height, heightMode) { - - var measuredWidth = widthMode === Yoga.MEASURE_MODE_UNDEFINED || (widthMode == Yoga.MEASURE_MODE_AT_MOST && width > 10) ? 10 : width; - var measuredHeight = heightMode === Yoga.MEASURE_MODE_UNDEFINED || (heightMode == Yoga.MEASURE_MODE_AT_MOST && height > 10) ? 10 : height; - - return { width: measuredWidth, height: measuredHeight }; - - }); +target.getMeasureCounterMax = function(Yoga) { + return getMeasureCounter(Yoga, function( + width, + widthMode, + height, + heightMode, + ) { + var measuredWidth = widthMode === Yoga.MEASURE_MODE_UNDEFINED ? 10 : width; + var measuredHeight = + heightMode === Yoga.MEASURE_MODE_UNDEFINED ? 10 : height; + return {width: measuredWidth, height: measuredHeight}; + }); +}; + +target.getMeasureCounterMin = function(Yoga) { + return getMeasureCounter(Yoga, function( + width, + widthMode, + height, + heightMode, + ) { + var measuredWidth = + widthMode === Yoga.MEASURE_MODE_UNDEFINED || + (widthMode == Yoga.MEASURE_MODE_AT_MOST && width > 10) + ? 10 + : width; + var measuredHeight = + heightMode === Yoga.MEASURE_MODE_UNDEFINED || + (heightMode == Yoga.MEASURE_MODE_AT_MOST && height > 10) + ? 10 + : height; + + return {width: measuredWidth, height: measuredHeight}; + }); }; diff --git a/javascript/yarn.lock b/javascript/yarn.lock index 238d1b01..84e1ad2a 100644 --- a/javascript/yarn.lock +++ b/javascript/yarn.lock @@ -46,13 +46,6 @@ arr-flatten@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/arr-flatten/-/arr-flatten-1.0.1.tgz#e5ffe54d45e19f32f216e91eb99c8ce892bb604b" -array-index@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/array-index/-/array-index-1.0.0.tgz#ec56a749ee103e4e08c790b9c353df16055b97f9" - dependencies: - debug "^2.2.0" - es6-symbol "^3.0.2" - array-unique@^0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/array-unique/-/array-unique-0.2.1.tgz#a1d97ccafcbc2625cc70fadceb36a50c58b01a53" @@ -850,12 +843,6 @@ cryptiles@2.x.x: dependencies: boom "2.x.x" -d@^0.1.1, d@~0.1.1: - version "0.1.1" - resolved "https://registry.yarnpkg.com/d/-/d-0.1.1.tgz#da184c535d18d8ee7ba2aa229b914009fae11309" - dependencies: - es5-ext "~0.10.2" - dashdash@^1.12.0: version "1.14.1" resolved "https://registry.yarnpkg.com/dashdash/-/dashdash-1.14.1.tgz#853cfa0f7cbe2fed5de20326b8dd581035f6e2f0" @@ -916,28 +903,6 @@ error-ex@^1.2.0: dependencies: is-arrayish "^0.2.1" -es5-ext@^0.10.7, es5-ext@~0.10.11, es5-ext@~0.10.2: - version "0.10.12" - resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.12.tgz#aa84641d4db76b62abba5e45fd805ecbab140047" - dependencies: - es6-iterator "2" - es6-symbol "~3.1" - -es6-iterator@2: - version "2.0.0" - resolved "https://registry.yarnpkg.com/es6-iterator/-/es6-iterator-2.0.0.tgz#bd968567d61635e33c0b80727613c9cb4b096bac" - dependencies: - d "^0.1.1" - es5-ext "^0.10.7" - es6-symbol "3" - -es6-symbol@3, es6-symbol@^3.0.2, es6-symbol@~3.1: - version "3.1.0" - resolved "https://registry.yarnpkg.com/es6-symbol/-/es6-symbol-3.1.0.tgz#94481c655e7a7cad82eba832d97d5433496d7ffa" - dependencies: - d "~0.1.1" - es5-ext "~0.10.11" - escape-string-regexp@1.0.5, escape-string-regexp@^1.0.2: version "1.0.5" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" @@ -1076,20 +1041,6 @@ fstream@^1.0.0, fstream@^1.0.2, fstream@~1.0.10: mkdirp ">=0.5 0" rimraf "2" -gauge@~2.6.0: - version "2.6.0" - resolved "https://registry.yarnpkg.com/gauge/-/gauge-2.6.0.tgz#d35301ad18e96902b4751dcbbe40f4218b942a46" - dependencies: - aproba "^1.0.3" - console-control-strings "^1.0.0" - has-color "^0.1.7" - has-unicode "^2.0.0" - object-assign "^4.1.0" - signal-exit "^3.0.0" - string-width "^1.0.1" - strip-ansi "^3.0.1" - wide-align "^1.1.0" - gauge@~2.7.1: version "2.7.2" resolved "https://registry.yarnpkg.com/gauge/-/gauge-2.7.2.tgz#15cecc31b02d05345a5d6b0e171cdb3ad2307774" @@ -1104,6 +1055,19 @@ gauge@~2.7.1: supports-color "^0.2.0" wide-align "^1.1.0" +gauge@~2.7.3: + version "2.7.4" + resolved "https://registry.yarnpkg.com/gauge/-/gauge-2.7.4.tgz#2c03405c7538c39d7eb37b317022e325fb018bf7" + dependencies: + aproba "^1.0.3" + console-control-strings "^1.0.0" + has-unicode "^2.0.0" + object-assign "^4.1.0" + signal-exit "^3.0.0" + string-width "^1.0.1" + strip-ansi "^3.0.1" + wide-align "^1.1.0" + generate-function@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/generate-function/-/generate-function-2.0.0.tgz#6858fe7c0969b7d4e9093337647ac79f60dfbe74" @@ -1194,10 +1158,6 @@ has-ansi@^2.0.0: dependencies: ansi-regex "^2.0.0" -has-color@^0.1.7: - version "0.1.7" - resolved "https://registry.yarnpkg.com/has-color/-/has-color-0.1.7.tgz#67144a5260c34fc3cca677d041daf52fe7b78b2f" - has-flag@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-1.0.0.tgz#9d9e793165ce017a00f00418c43f942a7b1d11fa" @@ -1624,21 +1584,25 @@ ms@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" -nan@^2.3.0, nan@^2.6.2: +nan@^2.3.0: version "2.6.2" resolved "https://registry.yarnpkg.com/nan/-/nan-2.6.2.tgz#e4ff34e6c95fdfb5aecc08de6596f43605a7db45" -nbind@^0.3.8: - version "0.3.12" - resolved "https://registry.yarnpkg.com/nbind/-/nbind-0.3.12.tgz#5b022d45950c1d664b360b54e6c29fa2fa5b8a59" +nan@^2.7.0: + version "2.8.0" + resolved "https://registry.yarnpkg.com/nan/-/nan-2.8.0.tgz#ed715f3fe9de02b57a5e6252d90a96675e1f085a" + +nbind@^0.3.14: + version "0.3.14" + resolved "https://registry.yarnpkg.com/nbind/-/nbind-0.3.14.tgz#ea85b685ae86801012509062f6ce4d639a19b864" dependencies: emscripten-library-decorator "~0.2.2" mkdirp "~0.5.1" - nan "^2.6.2" + nan "^2.7.0" -node-gyp@^3.4.0: - version "3.4.0" - resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-3.4.0.tgz#dda558393b3ecbbe24c9e6b8703c71194c63fa36" +node-gyp@^3.6.2: + version "3.6.2" + resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-3.6.2.tgz#9bfbe54562286284838e750eac05295853fa1c60" dependencies: fstream "^1.0.0" glob "^7.0.3" @@ -1646,12 +1610,11 @@ node-gyp@^3.4.0: minimatch "^3.0.2" mkdirp "^0.5.0" nopt "2 || 3" - npmlog "0 || 1 || 2 || 3" + npmlog "0 || 1 || 2 || 3 || 4" osenv "0" - path-array "^1.0.0" request "2" rimraf "2" - semver "2.x || 3.x || 4 || 5" + semver "~5.3.0" tar "^2.0.0" which "1" @@ -1694,13 +1657,13 @@ npm-run-path@^2.0.0: dependencies: path-key "^2.0.0" -"npmlog@0 || 1 || 2 || 3": - version "3.1.2" - resolved "https://registry.yarnpkg.com/npmlog/-/npmlog-3.1.2.tgz#2d46fa874337af9498a2f12bb43d8d0be4a36873" +"npmlog@0 || 1 || 2 || 3 || 4": + version "4.1.2" + resolved "https://registry.yarnpkg.com/npmlog/-/npmlog-4.1.2.tgz#08a7f2a8bf734604779a9efa4ad5cc717abb954b" dependencies: are-we-there-yet "~1.1.2" console-control-strings "~1.1.0" - gauge "~2.6.0" + gauge "~2.7.3" set-blocking "~2.0.0" npmlog@^4.0.1: @@ -1809,12 +1772,6 @@ parse-json@^2.2.0: dependencies: error-ex "^1.2.0" -path-array@^1.0.0: - version "1.0.1" - resolved "https://registry.yarnpkg.com/path-array/-/path-array-1.0.1.tgz#7e2f0f35f07a2015122b868b7eac0eb2c4fec271" - dependencies: - array-index "^1.0.0" - path-exists@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-3.0.0.tgz#ce0ebeaa5f78cb18925ea7d810d7b59b010fd515" @@ -2041,7 +1998,7 @@ rimraf@2, rimraf@~2.5.1, rimraf@~2.5.4: version "5.5.0" resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.0.tgz#dc4bbc7a6ca9d916dee5d43516f0092b58f7b8ab" -"semver@2.x || 3.x || 4 || 5", semver@~5.3.0: +semver@~5.3.0: version "5.3.0" resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f"