From 8635dab4c38fcd67962819224093d0be95f5ed43 Mon Sep 17 00:00:00 2001 From: Chris Loer Date: Thu, 8 Feb 2018 15:23:29 -0800 Subject: [core] Implement Expression::serialize() Issue #10714 - Each expression stores its operator as a string, and default serialization is [operator, serialize(child1), ...] - Custom implementations of `serialize` for Expression types that don't follow the pattern - expression::Value -> mbgl::Value converter - node_expression bindings to expose `serialize` --- platform/node/src/node_expression.cpp | 27 +++++++++++++++++++-------- platform/node/src/node_expression.hpp | 3 +++ platform/node/test/expression.test.js | 4 +++- 3 files changed, 25 insertions(+), 9 deletions(-) (limited to 'platform/node') diff --git a/platform/node/src/node_expression.cpp b/platform/node/src/node_expression.cpp index 8958d5c6c7..84515060a3 100644 --- a/platform/node/src/node_expression.cpp +++ b/platform/node/src/node_expression.cpp @@ -1,5 +1,6 @@ #include "node_conversion.hpp" #include "node_expression.hpp" +#include "node_feature.hpp" #include #include @@ -24,6 +25,8 @@ void NodeExpression::Init(v8::Local target) { Nan::SetPrototypeMethod(tpl, "isFeatureConstant", IsFeatureConstant); Nan::SetPrototypeMethod(tpl, "isZoomConstant", IsZoomConstant); + Nan::SetPrototypeMethod(tpl, "serialize", Serialize); + Nan::SetMethod(tpl, "parse", Parse); constructor.Reset(tpl->GetFunction()); // what is this doing? @@ -39,31 +42,31 @@ type::Type parseType(v8::Local type) { {"color", type::Color}, {"value", type::Value} }; - + v8::Local v8kind = Nan::Get(type, Nan::New("kind").ToLocalChecked()).ToLocalChecked(); std::string kind(*v8::String::Utf8Value(v8kind)); - + if (kind == "array") { type::Type itemType = parseType(Nan::Get(type, Nan::New("itemType").ToLocalChecked()).ToLocalChecked()->ToObject()); mbgl::optional N; - + v8::Local Nkey = Nan::New("N").ToLocalChecked(); if (Nan::Has(type, Nkey).FromMaybe(false)) { N = Nan::Get(type, Nkey).ToLocalChecked()->ToInt32()->Value(); } return type::Array(itemType, N); } - + return types[kind]; } void NodeExpression::Parse(const Nan::FunctionCallbackInfo& info) { v8::Local cons = Nan::New(constructor); - + if (info.Length() < 1 || info[0]->IsUndefined()) { return Nan::ThrowTypeError("Requires a JSON style expression argument."); } - + mbgl::optional expected; if (info.Length() > 1 && info[1]->IsObject()) { expected = parseType(info[1]->ToObject()); @@ -84,7 +87,7 @@ void NodeExpression::Parse(const Nan::FunctionCallbackInfo& info) { info.GetReturnValue().Set(wrapped); return; } - + v8::Local result = Nan::New(); for (std::size_t i = 0; i < ctx.getErrors().size(); i++) { const auto& error = ctx.getErrors()[i]; @@ -140,7 +143,7 @@ struct ToValue { } return scope.Escape(result); } - + v8::Local operator()(const mbgl::Color& color) { return operator()(std::vector { static_cast(color.r), @@ -227,4 +230,12 @@ void NodeExpression::IsZoomConstant(const Nan::FunctionCallbackInfo& info.GetReturnValue().Set(Nan::New(isZoomConstant(*expression))); } +void NodeExpression::Serialize(const Nan::FunctionCallbackInfo& info) { + NodeExpression* nodeExpr = ObjectWrap::Unwrap(info.Holder()); + const std::unique_ptr& expression = nodeExpr->expression; + + const mbgl::Value serialized = expression->serialize(); + info.GetReturnValue().Set(toJS(serialized)); +} + } // namespace node_mbgl diff --git a/platform/node/src/node_expression.hpp b/platform/node/src/node_expression.hpp index 7af5b7ab51..05af217bde 100644 --- a/platform/node/src/node_expression.hpp +++ b/platform/node/src/node_expression.hpp @@ -32,6 +32,9 @@ private: static void GetType(const Nan::FunctionCallbackInfo&); static void IsFeatureConstant(const Nan::FunctionCallbackInfo&); static void IsZoomConstant(const Nan::FunctionCallbackInfo&); + + static void Serialize(const Nan::FunctionCallbackInfo&); + static Nan::Persistent constructor; std::unique_ptr expression; diff --git a/platform/node/test/expression.test.js b/platform/node/test/expression.test.js index aac039ce18..d7a44abbaa 100644 --- a/platform/node/test/expression.test.js +++ b/platform/node/test/expression.test.js @@ -45,6 +45,9 @@ suite.run('native', {ignores: ignores, tests: tests}, (fixture) => { compiled.isZoomConstant = expression.isZoomConstant(); compiled.type = expression.getType(); + console.log("input: " + JSON.stringify(fixture.expression)); + console.log("output: " + JSON.stringify(expression.serialize())); + const evaluate = fixture.inputs || []; const evaluateResults = []; for (const input of evaluate) { @@ -68,4 +71,3 @@ suite.run('native', {ignores: ignores, tests: tests}, (fixture) => { return result; }); - -- cgit v1.2.1 From e771210d13ab7fe1cf3816b1eeaee18a7bed85bd Mon Sep 17 00:00:00 2001 From: Chris Loer Date: Fri, 9 Feb 2018 17:21:58 -0800 Subject: [test] Native expression test support for: - Round-tripping expressions through serialization and checking that outputs don't change - Checking expression serialization against expected value from fixture --- platform/node/test/expression.test.js | 60 +++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 24 deletions(-) (limited to 'platform/node') diff --git a/platform/node/test/expression.test.js b/platform/node/test/expression.test.js index d7a44abbaa..ffd1c68ff2 100644 --- a/platform/node/test/expression.test.js +++ b/platform/node/test/expression.test.js @@ -32,41 +32,53 @@ function getExpectedType(spec) { suite.run('native', {ignores: ignores, tests: tests}, (fixture) => { const compiled = {}; + const recompiled = {}; const result = { - compiled + compiled, + recompiled }; const spec = fixture.propertySpec || {}; const expression = mbgl.Expression.parse(fixture.expression, getExpectedType(spec)); - if (expression instanceof mbgl.Expression) { - compiled.result = 'success'; - compiled.isFeatureConstant = expression.isFeatureConstant(); - compiled.isZoomConstant = expression.isZoomConstant(); - compiled.type = expression.getType(); + const evaluateExpression = (expression, compilationResult) => { + if (expression instanceof mbgl.Expression) { + compilationResult.result = 'success'; + compilationResult.isFeatureConstant = expression.isFeatureConstant(); + compilationResult.isZoomConstant = expression.isZoomConstant(); + compilationResult.type = expression.getType(); - console.log("input: " + JSON.stringify(fixture.expression)); - console.log("output: " + JSON.stringify(expression.serialize())); + const evaluate = fixture.inputs || []; + const evaluateResults = []; + for (const input of evaluate) { + const feature = Object.assign({ + type: 'Feature', + properties: {}, + geometry: { type: 'Point', coordinates: [0, 0] } + }, input[1]) - const evaluate = fixture.inputs || []; - const evaluateResults = []; - for (const input of evaluate) { - const feature = Object.assign({ - type: 'Feature', - properties: {}, - geometry: { type: 'Point', coordinates: [0, 0] } - }, input[1]) + const output = expression.evaluate(input[0], feature); + evaluateResults.push(output); + } - const output = expression.evaluate(input[0], feature); - evaluateResults.push(output); + if (fixture.inputs) { + return evaluateResults; + } + } else { + compilationResult.result = 'error'; + compilationResult.errors = expression; } + } - if (fixture.inputs) { - result.outputs = evaluateResults; - } - } else { - compiled.result = 'error'; - compiled.errors = expression; + result.outputs = evaluateExpression(expression, compiled); + if (expression instanceof mbgl.Expression) { + result.serialized = expression.serialize(); + const recompiledExpression = mbgl.Expression.parse(result.serialized, getExpectedType(spec)); + result.roundTripOutputs = evaluateExpression(recompiledExpression, recompiled); + // Type is allowed to change through serialization + // (eg "array" -> "array") + // Override the round-tripped type here so that the equality check passes + recompiled.type = compiled.type; } return result; -- cgit v1.2.1 From d3e6fc5eff6b50490cf7e10c87a09c5eff7cda35 Mon Sep 17 00:00:00 2001 From: Chris Loer Date: Fri, 16 Feb 2018 13:14:41 -0800 Subject: [test] Native ignore for GL JS issue #6160 --- platform/node/test/ignores.json | 1 + 1 file changed, 1 insertion(+) (limited to 'platform/node') diff --git a/platform/node/test/ignores.json b/platform/node/test/ignores.json index 42751da30f..50e2aa1d61 100644 --- a/platform/node/test/ignores.json +++ b/platform/node/test/ignores.json @@ -34,6 +34,7 @@ "render-tests/regressions/mapbox-gl-js#5599": "https://github.com/mapbox/mapbox-gl-native/issues/10399", "render-tests/regressions/mapbox-gl-js#5740": "https://github.com/mapbox/mapbox-gl-native/issues/10619", "render-tests/regressions/mapbox-gl-js#5982": "https://github.com/mapbox/mapbox-gl-native/issues/10619", + "render-tests/regressions/mapbox-gl-js#6160": "https://github.com/mapbox/mapbox-gl-native/pull/11206", "render-tests/regressions/mapbox-gl-native#7357": "https://github.com/mapbox/mapbox-gl-native/issues/7357", "render-tests/runtime-styling/image-add-sdf": "https://github.com/mapbox/mapbox-gl-native/issues/9847", "render-tests/runtime-styling/paint-property-fill-flat-to-extrude": "https://github.com/mapbox/mapbox-gl-native/issues/6745", -- cgit v1.2.1 From ebb72b9002f9d497e696a08030fcec2f489c273c Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 21 Feb 2018 11:36:40 -0500 Subject: [core] don't hide icons if text is an empty string --- platform/node/test/ignores.json | 1 - 1 file changed, 1 deletion(-) (limited to 'platform/node') diff --git a/platform/node/test/ignores.json b/platform/node/test/ignores.json index 50e2aa1d61..42751da30f 100644 --- a/platform/node/test/ignores.json +++ b/platform/node/test/ignores.json @@ -34,7 +34,6 @@ "render-tests/regressions/mapbox-gl-js#5599": "https://github.com/mapbox/mapbox-gl-native/issues/10399", "render-tests/regressions/mapbox-gl-js#5740": "https://github.com/mapbox/mapbox-gl-native/issues/10619", "render-tests/regressions/mapbox-gl-js#5982": "https://github.com/mapbox/mapbox-gl-native/issues/10619", - "render-tests/regressions/mapbox-gl-js#6160": "https://github.com/mapbox/mapbox-gl-native/pull/11206", "render-tests/regressions/mapbox-gl-native#7357": "https://github.com/mapbox/mapbox-gl-native/issues/7357", "render-tests/runtime-styling/image-add-sdf": "https://github.com/mapbox/mapbox-gl-native/issues/9847", "render-tests/runtime-styling/paint-property-fill-flat-to-extrude": "https://github.com/mapbox/mapbox-gl-native/issues/6745", -- cgit v1.2.1 From 7097e04fb359e8351e330e248bb876bc84c4513b Mon Sep 17 00:00:00 2001 From: Chris Loer Date: Fri, 23 Feb 2018 16:24:29 -0800 Subject: [core, node] Hold on to map handle during NodeMap::request. Avoids a potential crash if garbage collection happens in the middle of a call to NodeMap::request from a map that's eligible for GC. Fixes issue #11281 --- platform/node/src/node_map.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'platform/node') diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index ac14df0228..0fe69e8ac9 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -1154,6 +1154,10 @@ NodeMap::~NodeMap() { std::unique_ptr NodeMap::request(const mbgl::Resource& resource, mbgl::FileSource::Callback callback_) { Nan::HandleScope scope; + // Because this method may be called while this NodeMap is already eligible for garbage collection, + // we need to explicitly hold onto our own handle here so that GC during a v8 call doesn't destroy + // *this while we're still executing code. + handle(); v8::Local argv[] = { Nan::New(this), -- cgit v1.2.1 From 05d24448bdea29e302f788f050829459adba8e83 Mon Sep 17 00:00:00 2001 From: Anand Thakker Date: Thu, 5 Apr 2018 11:14:55 -0400 Subject: Remove unused lambda capture (#11600) Fixes #11588 --- platform/node/src/node_thread_pool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'platform/node') diff --git a/platform/node/src/node_thread_pool.cpp b/platform/node/src/node_thread_pool.cpp index fd6df575fc..1f37565e8a 100644 --- a/platform/node/src/node_thread_pool.cpp +++ b/platform/node/src/node_thread_pool.cpp @@ -6,7 +6,7 @@ namespace node_mbgl { NodeThreadPool::NodeThreadPool() - : queue(new util::AsyncQueue>(uv_default_loop(), [this](std::weak_ptr mailbox) { + : queue(new util::AsyncQueue>(uv_default_loop(), [](std::weak_ptr mailbox) { Worker* worker = new Worker(mailbox); Nan::AsyncQueueWorker(worker); })) { -- cgit v1.2.1 From a62745edf9ee2da1f6ebda07acfd8260f3696e50 Mon Sep 17 00:00:00 2001 From: Chris Loer Date: Wed, 18 Apr 2018 16:33:37 -0700 Subject: Port global symbol query from GL JS: - Symbol querying is now global instead of per-tile - Symbols that bleed over tile boundaries no longer missed in queries - Symbol results now sorted based on rendering order (ie overlapping symbols change their sort order when a bearing change causes their render order to change) - Placement::retainedQueryData now responsible for maintaining symbol querying data for buckets that may no longer be in the TilePyramid. --- platform/node/test/ignores.json | 2 -- 1 file changed, 2 deletions(-) (limited to 'platform/node') diff --git a/platform/node/test/ignores.json b/platform/node/test/ignores.json index e0c2475b75..b7ca72cee0 100644 --- a/platform/node/test/ignores.json +++ b/platform/node/test/ignores.json @@ -6,8 +6,6 @@ "query-tests/geometry/multilinestring": "needs investigation", "query-tests/geometry/multipolygon": "needs investigation", "query-tests/geometry/polygon": "needs investigation", - "query-tests/symbol/panned-after-insert": "https://github.com/mapbox/mapbox-gl-native/issues/10408", - "query-tests/symbol/rotated-after-insert": "https://github.com/mapbox/mapbox-gl-native/issues/10408", "query-tests/world-wrapping/box": "skip - needs issue", "query-tests/world-wrapping/point": "skip - needs issue", "render-tests/background-color/transition": "https://github.com/mapbox/mapbox-gl-native/issues/10619", -- cgit v1.2.1 From 60cce56d46cb52c73fcb14d3917c1c47c328b72e Mon Sep 17 00:00:00 2001 From: Chris Loer Date: Thu, 19 Apr 2018 13:06:42 -0700 Subject: Bump GL JS pin to get tests for global symbol querying. - Pulls over an update to line.vertex.glsl (looks like a no-op?) - Add test ignores for collator, is-supported-script, line-gradient - Exclude collator, is-supported-script, line-gradient from code generation. --- platform/node/test/ignores.json | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'platform/node') diff --git a/platform/node/test/ignores.json b/platform/node/test/ignores.json index b7ca72cee0..195c9161fb 100644 --- a/platform/node/test/ignores.json +++ b/platform/node/test/ignores.json @@ -1,4 +1,22 @@ { + "expression-tests/collator/accent-equals-de": "https://github.com/mapbox/mapbox-gl-native/issues/11692", + "expression-tests/collator/accent-lt-en": "https://github.com/mapbox/mapbox-gl-native/issues/11692", + "expression-tests/collator/accent-not-equals-en": "https://github.com/mapbox/mapbox-gl-native/issues/11692", + "expression-tests/collator/base-default-locale": "https://github.com/mapbox/mapbox-gl-native/issues/11692", + "expression-tests/collator/base-equals-en": "https://github.com/mapbox/mapbox-gl-native/issues/11692", + "expression-tests/collator/base-gt-en": "https://github.com/mapbox/mapbox-gl-native/issues/11692", + "expression-tests/collator/case-lteq-en": "https://github.com/mapbox/mapbox-gl-native/issues/11692", + "expression-tests/collator/case-not-equals-en": "https://github.com/mapbox/mapbox-gl-native/issues/11692", + "expression-tests/collator/case-omitted-en": "https://github.com/mapbox/mapbox-gl-native/issues/11692", + "expression-tests/collator/comparison-number-error": "https://github.com/mapbox/mapbox-gl-native/issues/11692", + "expression-tests/collator/diacritic-omitted-en": "https://github.com/mapbox/mapbox-gl-native/issues/11692", + "expression-tests/collator/equals-non-string-error": "https://github.com/mapbox/mapbox-gl-native/issues/11692", + "expression-tests/collator/non-object-error": "https://github.com/mapbox/mapbox-gl-native/issues/11692", + "expression-tests/collator/variant-equals-en": "https://github.com/mapbox/mapbox-gl-native/issues/11692", + "expression-tests/collator/variant-gteq-en": "https://github.com/mapbox/mapbox-gl-native/issues/11692", + "expression-tests/is-supported-script/default": "https://github.com/mapbox/mapbox-gl-native/issues/11693", + "expression-tests/resolved-locale/basic": "https://github.com/mapbox/mapbox-gl-native/issues/11692", + "expression-tests/to-string/basic": "https://github.com/mapbox/mapbox-gl-native/issues/11719", "query-tests/circle-pitch-scale/viewport-inside-align-map": "https://github.com/mapbox/mapbox-gl-native/issues/10615", "query-tests/circle-pitch-scale/viewport-inside-align-viewport": "https://github.com/mapbox/mapbox-gl-native/issues/10615", "query-tests/edge-cases/box-cutting-antimeridian-z0": "https://github.com/mapbox/mapbox-gl-native/issues/11607", @@ -25,6 +43,10 @@ "render-tests/fill-extrusion-pattern/opacity": "https://github.com/mapbox/mapbox-gl-js/issues/3327", "render-tests/geojson/inline-linestring-fill": "current behavior is arbitrary", "render-tests/geojson/inline-polygon-symbol": "behavior needs reconciliation with gl-js", + "render-tests/is-supported-script/filter": "https://github.com/mapbox/mapbox-gl-native/issues/11693", + "render-tests/is-supported-script/layout": "https://github.com/mapbox/mapbox-gl-native/issues/11693", + "render-tests/line-gradient/gradient": "https://github.com/mapbox/mapbox-gl-native/issues/11718", + "render-tests/line-gradient/translucent": "https://github.com/mapbox/mapbox-gl-native/issues/11718", "render-tests/mixed-zoom/z10-z11": "https://github.com/mapbox/mapbox-gl-native/issues/10397", "render-tests/raster-masking/overlapping-zoom": "https://github.com/mapbox/mapbox-gl-native/issues/10195", "render-tests/real-world/bangkok": "https://github.com/mapbox/mapbox-gl-native/issues/10412", -- cgit v1.2.1 From 1a39d7db483a26cd846c7875f3ccc9d54d5a0982 Mon Sep 17 00:00:00 2001 From: Chris Loer Date: Mon, 2 Apr 2018 18:03:13 -0700 Subject: [core] Remove circle-pitch-scale test ignores. --- platform/node/test/ignores.json | 4 ---- 1 file changed, 4 deletions(-) (limited to 'platform/node') diff --git a/platform/node/test/ignores.json b/platform/node/test/ignores.json index 195c9161fb..98d7e016bc 100644 --- a/platform/node/test/ignores.json +++ b/platform/node/test/ignores.json @@ -17,10 +17,6 @@ "expression-tests/is-supported-script/default": "https://github.com/mapbox/mapbox-gl-native/issues/11693", "expression-tests/resolved-locale/basic": "https://github.com/mapbox/mapbox-gl-native/issues/11692", "expression-tests/to-string/basic": "https://github.com/mapbox/mapbox-gl-native/issues/11719", - "query-tests/circle-pitch-scale/viewport-inside-align-map": "https://github.com/mapbox/mapbox-gl-native/issues/10615", - "query-tests/circle-pitch-scale/viewport-inside-align-viewport": "https://github.com/mapbox/mapbox-gl-native/issues/10615", - "query-tests/edge-cases/box-cutting-antimeridian-z0": "https://github.com/mapbox/mapbox-gl-native/issues/11607", - "query-tests/edge-cases/null-island": "https://github.com/mapbox/mapbox-gl-native/issues/11607", "query-tests/geometry/multilinestring": "needs investigation", "query-tests/geometry/multipolygon": "needs investigation", "query-tests/geometry/polygon": "needs investigation", -- cgit v1.2.1 From 65a4ee2373d053ac5b8d179123fdc51b320a1bb7 Mon Sep 17 00:00:00 2001 From: Chris Loer Date: Thu, 26 Apr 2018 13:41:19 -0700 Subject: [core] Port is-supported-script to native. Native port is much simpler because RTL text support is always enabled. --- platform/node/test/ignores.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'platform/node') diff --git a/platform/node/test/ignores.json b/platform/node/test/ignores.json index 98d7e016bc..a1d4d68511 100644 --- a/platform/node/test/ignores.json +++ b/platform/node/test/ignores.json @@ -14,7 +14,7 @@ "expression-tests/collator/non-object-error": "https://github.com/mapbox/mapbox-gl-native/issues/11692", "expression-tests/collator/variant-equals-en": "https://github.com/mapbox/mapbox-gl-native/issues/11692", "expression-tests/collator/variant-gteq-en": "https://github.com/mapbox/mapbox-gl-native/issues/11692", - "expression-tests/is-supported-script/default": "https://github.com/mapbox/mapbox-gl-native/issues/11693", + "expression-tests/is-supported-script/default": "This tests RTL text plugin behavior specific to GL JS", "expression-tests/resolved-locale/basic": "https://github.com/mapbox/mapbox-gl-native/issues/11692", "expression-tests/to-string/basic": "https://github.com/mapbox/mapbox-gl-native/issues/11719", "query-tests/geometry/multilinestring": "needs investigation", @@ -39,8 +39,6 @@ "render-tests/fill-extrusion-pattern/opacity": "https://github.com/mapbox/mapbox-gl-js/issues/3327", "render-tests/geojson/inline-linestring-fill": "current behavior is arbitrary", "render-tests/geojson/inline-polygon-symbol": "behavior needs reconciliation with gl-js", - "render-tests/is-supported-script/filter": "https://github.com/mapbox/mapbox-gl-native/issues/11693", - "render-tests/is-supported-script/layout": "https://github.com/mapbox/mapbox-gl-native/issues/11693", "render-tests/line-gradient/gradient": "https://github.com/mapbox/mapbox-gl-native/issues/11718", "render-tests/line-gradient/translucent": "https://github.com/mapbox/mapbox-gl-native/issues/11718", "render-tests/mixed-zoom/z10-z11": "https://github.com/mapbox/mapbox-gl-native/issues/10397", -- cgit v1.2.1 From 9a4b806fa84bd3d2d1adb57eae4f9fdb5f79d9f9 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Sun, 29 Apr 2018 15:27:49 -0700 Subject: [docs] Make per-platform installation docs self-contained I've seen several issues where users followed platform-specific install docs, but were unaware of additional prerequisites spelled out in the top-level INSTALL.md. So let's try making each platform's installation documentation self contained. --- platform/node/DEVELOPING.md | 8 +++++--- platform/node/README.md | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'platform/node') diff --git a/platform/node/DEVELOPING.md b/platform/node/DEVELOPING.md index b313d75c13..215b06c7bf 100644 --- a/platform/node/DEVELOPING.md +++ b/platform/node/DEVELOPING.md @@ -4,11 +4,13 @@ This document explains how to build the [Node.js](https://nodejs.org/) bindings ## Building -To develop these bindings, you’ll need to build them from source. Building requires [installing all of the basic dependencies needed for Mapbox GL Native](../../INSTALL.md), then running: +To develop these bindings, you’ll need to build them from source. Building requires the prerequisites listed in either +the [macOS](../macos/INSTALL.md#requirements) or [Linux](../linux/README.md#prerequisites) install documentation, depending +on the target platform. - npm install --build-from-source +To compile the Node.js bindings and install module dependencies, from the repository root directory, run: -From the root directory. This will compile the Node.js bindings and install module dependencies. + npm install --build-from-source To recompile just the C++ code while developing, run `make node`. diff --git a/platform/node/README.md b/platform/node/README.md index d19b2a9343..ac5bcd7e8d 100644 --- a/platform/node/README.md +++ b/platform/node/README.md @@ -17,7 +17,8 @@ Run: npm install @mapbox/mapbox-gl-native ``` -Other platforms will fall back to a source compile with `make node`; see INSTALL.md in the repository root directory for prequisites. +Other platforms will fall back to a source compile with `make node`; see [DEVELOPING.md](DEVELOPING.md) for details on +building from source. ## Testing -- cgit v1.2.1 From 62c875e01b07197024e3806e8b2882160ce1195c Mon Sep 17 00:00:00 2001 From: Lauren Budorick Date: Mon, 14 May 2018 12:38:14 -0700 Subject: [core] Rework spec function/expression taxonomy Ports https://github.com/mapbox/mapbox-gl-js/pull/6521, updating codegen scripts to parse new expression taxonomy. --- platform/node/test/ignores.json | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'platform/node') diff --git a/platform/node/test/ignores.json b/platform/node/test/ignores.json index a1d4d68511..47cb07c85a 100644 --- a/platform/node/test/ignores.json +++ b/platform/node/test/ignores.json @@ -22,6 +22,9 @@ "query-tests/geometry/polygon": "needs investigation", "query-tests/world-wrapping/box": "skip - needs issue", "query-tests/world-wrapping/point": "skip - needs issue", + "query-tests/circle-radius/feature-state": "skip - port https://github.com/mapbox/mapbox-gl-js/pull/6263 - needs issue", + "query-tests/feature-state/default": "skip - port https://github.com/mapbox/mapbox-gl-js/pull/6263 - needs issue", + "query-tests/regressions/mapbox-gl-js#6555": "skip - no querySourceFeatures in mbgl-node; needs issue", "render-tests/background-color/transition": "https://github.com/mapbox/mapbox-gl-native/issues/10619", "render-tests/debug/collision": "https://github.com/mapbox/mapbox-gl-native/issues/3841", "render-tests/debug/collision-lines": "https://github.com/mapbox/mapbox-gl-native/issues/10412", @@ -106,5 +109,8 @@ "render-tests/combinations/fill-translucent--fill-extrusion-translucent": "needs investigation", "render-tests/combinations/line-translucent--fill-extrusion-translucent": "needs investigation", "render-tests/combinations/raster-translucent--fill-extrusion-translucent": "needs investigation", - "render-tests/combinations/symbol-translucent--fill-extrusion-translucent": "needs investigation" + "render-tests/combinations/symbol-translucent--fill-extrusion-translucent": "needs investigation", + "render-tests/feature-state/composite-expression": "skip - port https://github.com/mapbox/mapbox-gl-js/pull/6263 - needs issue", + "render-tests/feature-state/data-expression": "skip - port https://github.com/mapbox/mapbox-gl-js/pull/6263 - needs issue", + "render-tests/feature-state/vector-source": "skip - port https://github.com/mapbox/mapbox-gl-js/pull/6263 - needs issue" } -- cgit v1.2.1 From b2fabe5eefc81cc38866a4856d6db37f4471d6ae Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 17 May 2018 09:55:15 -0700 Subject: [core] Align match behavior with case/== Makes `["match", ["get", k], label, match, otherwise]` equivalent to `["case", ["==", ["get", k], label], match, otherwise]`. This changes the behavior of match expressions where the runtime type of the input does not match the type of the labels: previously such expressions produced a runtime type error and then fell back to the property default value; now they produce the fallback value from the match expression. --- platform/node/test/ignores.json | 3 +++ 1 file changed, 3 insertions(+) (limited to 'platform/node') diff --git a/platform/node/test/ignores.json b/platform/node/test/ignores.json index 47cb07c85a..ac00235702 100644 --- a/platform/node/test/ignores.json +++ b/platform/node/test/ignores.json @@ -42,6 +42,7 @@ "render-tests/fill-extrusion-pattern/opacity": "https://github.com/mapbox/mapbox-gl-js/issues/3327", "render-tests/geojson/inline-linestring-fill": "current behavior is arbitrary", "render-tests/geojson/inline-polygon-symbol": "behavior needs reconciliation with gl-js", + "render-tests/icon-rotate/with-offset": "https://github.com/mapbox/mapbox-gl-native/issues/11872", "render-tests/line-gradient/gradient": "https://github.com/mapbox/mapbox-gl-native/issues/11718", "render-tests/line-gradient/translucent": "https://github.com/mapbox/mapbox-gl-native/issues/11718", "render-tests/mixed-zoom/z10-z11": "https://github.com/mapbox/mapbox-gl-native/issues/10397", @@ -57,6 +58,7 @@ "render-tests/regressions/mapbox-gl-js#5370": "skip - https://github.com/mapbox/mapbox-gl-native/pull/9439", "render-tests/regressions/mapbox-gl-js#5740": "https://github.com/mapbox/mapbox-gl-native/issues/10619", "render-tests/regressions/mapbox-gl-js#5982": "https://github.com/mapbox/mapbox-gl-native/issues/10619", + "render-tests/regressions/mapbox-gl-js#6655": "skip - port https://github.com/mapbox/mapbox-gl-js/pull/6263 - needs issue", "render-tests/regressions/mapbox-gl-native#7357": "https://github.com/mapbox/mapbox-gl-native/issues/7357", "render-tests/runtime-styling/image-add-sdf": "https://github.com/mapbox/mapbox-gl-native/issues/9847", "render-tests/runtime-styling/paint-property-fill-flat-to-extrude": "https://github.com/mapbox/mapbox-gl-native/issues/6745", @@ -67,6 +69,7 @@ "render-tests/text-pitch-alignment/map-text-rotation-alignment-map": "https://github.com/mapbox/mapbox-gl-native/issues/9732", "render-tests/text-pitch-alignment/viewport-text-rotation-alignment-map": "https://github.com/mapbox/mapbox-gl-native/issues/9732", "render-tests/text-pitch-scaling/line-half": "https://github.com/mapbox/mapbox-gl-native/issues/9732", + "render-tests/text-rotate/with-offset": "https://github.com/mapbox/mapbox-gl-native/issues/11872", "render-tests/video/default": "skip - https://github.com/mapbox/mapbox-gl-native/issues/601", "render-tests/background-color/colorSpace-hcl": "needs issue", "render-tests/combinations/background-opaque--heatmap-translucent": "https://github.com/mapbox/mapbox-gl-native/issues/10146", -- cgit v1.2.1 From d5aff7182d6caca9c69514df5fa90bfc203cb5e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Fri, 18 May 2018 17:44:59 +0200 Subject: [node] prevent race condition for renderFinished --- platform/node/src/node_map.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'platform/node') diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index 9b76f0f542..521cca1a51 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -447,6 +447,12 @@ void NodeMap::startRender(NodeMap::RenderOptions options) { } void NodeMap::renderFinished() { + if (!callback) { + // In some situations, the render finishes at the same time as we call cancel. Make sure + // we are only finishing a render once. + return; + } + Nan::HandleScope scope; // We're done with this render call, so we're unrefing so that the loop could close. -- cgit v1.2.1 From 973aa963f917df2c20a05dfea1b3af7314677e06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Fri, 20 Apr 2018 16:40:17 +0300 Subject: [node] move to Nan 2.10.0 --- platform/node/src/node_expression.cpp | 2 +- platform/node/src/node_map.cpp | 38 +++++++++++++++++++++++++---------- platform/node/src/node_map.hpp | 4 +++- platform/node/src/node_request.cpp | 3 ++- 4 files changed, 33 insertions(+), 14 deletions(-) (limited to 'platform/node') diff --git a/platform/node/src/node_expression.cpp b/platform/node/src/node_expression.cpp index 27866ccbed..9faa41d8b8 100644 --- a/platform/node/src/node_expression.cpp +++ b/platform/node/src/node_expression.cpp @@ -52,7 +52,7 @@ type::Type parseType(v8::Local type) { v8::Local Nkey = Nan::New("N").ToLocalChecked(); if (Nan::Has(type, Nkey).FromMaybe(false)) { - N = Nan::Get(type, Nkey).ToLocalChecked()->ToInt32()->Value(); + N = Nan::To(Nan::Get(type, Nkey).ToLocalChecked()).ToLocalChecked()->Value(); } return type::Array(itemType, N); } diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index 521cca1a51..bc40d56f44 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -353,6 +353,18 @@ NodeMap::RenderOptions NodeMap::ParseOptions(v8::Local obj) { return options; } +class RenderRequest : public Nan::AsyncResource { +public: + RenderRequest(v8::Local callback_) : AsyncResource("mbgl:RenderRequest") { + callback.Reset(callback_); + } + ~RenderRequest() { + callback.Reset(); + } + + Nan::Persistent callback; +}; + /** * Render an image from the currently-loaded style * @@ -385,15 +397,16 @@ void NodeMap::Render(const Nan::FunctionCallbackInfo& info) { return Nan::ThrowTypeError("Style is not loaded"); } - if (nodeMap->callback) { + if (nodeMap->req) { return Nan::ThrowError("Map is currently rendering an image"); } try { auto options = ParseOptions(Nan::To(info[0]).ToLocalChecked()); - assert(!nodeMap->callback); + assert(!nodeMap->req); assert(!nodeMap->image.data); - nodeMap->callback = std::make_unique(info[1].As()); + nodeMap->req = std::make_unique(Nan::To(info[1]).ToLocalChecked()); + nodeMap->startRender(std::move(options)); } catch (mbgl::style::conversion::Error& err) { return Nan::ThrowTypeError(err.message.c_str()); @@ -463,14 +476,17 @@ void NodeMap::renderFinished() { Unref(); // Move the callback and image out of the way so that the callback can start a new render call. - auto cb = std::move(callback); + auto request = std::move(req); auto img = std::move(image); - assert(cb); + assert(request); // These have to be empty to be prepared for the next render call. - assert(!callback); + assert(!req); assert(!image.data); + v8::Local callback = Nan::New(request->callback); + v8::Local target = Nan::New(); + if (error) { std::string errorMessage; @@ -488,7 +504,7 @@ void NodeMap::renderFinished() { error = nullptr; assert(!error); - cb->Call(1, argv); + request->runInAsyncScope(target, callback, 1, argv); } else if (img.data) { v8::Local pixels = Nan::NewBuffer( reinterpret_cast(img.data.get()), img.bytes(), @@ -504,12 +520,12 @@ void NodeMap::renderFinished() { Nan::Null(), pixels }; - cb->Call(2, argv); + request->runInAsyncScope(target, callback, 2, argv); } else { v8::Local argv[] = { Nan::Error("Didn't get an image") }; - cb->Call(1, argv); + request->runInAsyncScope(target, callback, 1, argv); } } @@ -552,7 +568,7 @@ void NodeMap::Cancel(const Nan::FunctionCallbackInfo& info) { auto nodeMap = Nan::ObjectWrap::Unwrap(info.Holder()); if (!nodeMap->map) return Nan::ThrowError(releasedMessage()); - if (!nodeMap->callback) return Nan::ThrowError("No render in progress"); + if (!nodeMap->req) return Nan::ThrowError("No render in progress"); try { nodeMap->cancel(); @@ -1198,7 +1214,7 @@ std::unique_ptr NodeMap::request(const mbgl::Resource& resou Nan::New(&callback_) }; - auto instance = Nan::New(NodeRequest::constructor)->NewInstance(2, argv); + auto instance = Nan::NewInstance(Nan::New(NodeRequest::constructor), 2, argv).ToLocalChecked(); Nan::Set(instance, Nan::New("url").ToLocalChecked(), Nan::New(resource.url).ToLocalChecked()); Nan::Set(instance, Nan::New("kind").ToLocalChecked(), Nan::New(resource.kind)); diff --git a/platform/node/src/node_map.hpp b/platform/node/src/node_map.hpp index 7fe23ad86a..19df095481 100644 --- a/platform/node/src/node_map.hpp +++ b/platform/node/src/node_map.hpp @@ -25,6 +25,8 @@ class NodeMapObserver : public mbgl::MapObserver { void onDidFailLoadingMap(std::exception_ptr) override; }; +class RenderRequest; + class NodeMap : public Nan::ObjectWrap, public mbgl::FileSource { public: @@ -84,7 +86,7 @@ public: std::exception_ptr error; mbgl::PremultipliedImage image; - std::unique_ptr callback; + std::unique_ptr req; // Async for delivering the notifications of render completion. uv_async_t *async; diff --git a/platform/node/src/node_request.cpp b/platform/node/src/node_request.cpp index de16710f78..8c26d44583 100644 --- a/platform/node/src/node_request.cpp +++ b/platform/node/src/node_request.cpp @@ -124,7 +124,8 @@ void NodeRequest::HandleCallback(const Nan::FunctionCallbackInfo& inf void NodeRequest::Execute() { v8::Local argv[] = { handle() }; - Nan::MakeCallback(Nan::To(target->handle()->GetInternalField(1)).ToLocalChecked(), "request", 1, argv); + Nan::AsyncResource res("mbgl:execute"); + res.runInAsyncScope(Nan::To(target->handle()->GetInternalField(1)).ToLocalChecked(), "request", 1, argv); } NodeRequest::NodeAsyncRequest::NodeAsyncRequest(NodeRequest* request_) : request(request_) { -- cgit v1.2.1 From d1a266b3e68d052d1478382795598bf2ff28da6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Fri, 20 Apr 2018 16:40:17 +0300 Subject: [node] allow building all ABIs at once --- platform/node/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'platform/node') diff --git a/platform/node/index.js b/platform/node/index.js index 5944a0a27d..6f6b33058a 100644 --- a/platform/node/index.js +++ b/platform/node/index.js @@ -2,9 +2,8 @@ // Shim to wrap req.respond while preserving callback-passing API -var mbgl = require('../../lib/mapbox_gl_native.node'); +var mbgl = require('../../lib/mbgl-node.abi-' + process.versions.modules); var constructor = mbgl.Map.prototype.constructor; -var process = require('process'); var Map = function(options) { if (!(options instanceof Object)) { -- cgit v1.2.1 From 162ee6f4e888050f36f23997eaa5fc215b80e75a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Tue, 22 May 2018 12:19:40 +0200 Subject: [node] fixup bad merge --- platform/node/src/node_map.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'platform/node') diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index bc40d56f44..4d89077d64 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -460,7 +460,7 @@ void NodeMap::startRender(NodeMap::RenderOptions options) { } void NodeMap::renderFinished() { - if (!callback) { + if (!req) { // In some situations, the render finishes at the same time as we call cancel. Make sure // we are only finishing a render once. return; -- cgit v1.2.1