diff options
author | Ander Conselvan de Oliveira <ander.deoliveira@mapbox.com> | 2019-04-02 10:51:24 +0300 |
---|---|---|
committer | Ander Conselvan de Oliveira <ander.deoliveira@mapbox.com> | 2019-05-21 12:14:22 +0300 |
commit | 80edc3b821e1303dc6872b5d8b04be27b89d50fd (patch) | |
tree | eb509b413bef5ad163c1d14163989ba7f08fb7dd | |
parent | 29140f5b119c3c9cbe7348ecb0f89f05282821a5 (diff) | |
download | qtlocation-mapboxgl-80edc3b821e1303dc6872b5d8b04be27b89d50fd.tar.gz |
[node] Convert legacy functions to expressions in NodeExpression::Parse
In order to test the conversion from function to expressions using the
legacy tests in the expression test suite, parse function objects into
expressions in NodeExpression::Parse.
v2: Coding style fixes.
-rw-r--r-- | platform/node/src/node_expression.cpp | 52 | ||||
-rw-r--r-- | platform/node/test/ignores.json | 13 |
2 files changed, 35 insertions, 30 deletions
diff --git a/platform/node/src/node_expression.cpp b/platform/node/src/node_expression.cpp index e980c464d8..4ea66124f8 100644 --- a/platform/node/src/node_expression.cpp +++ b/platform/node/src/node_expression.cpp @@ -4,6 +4,7 @@ #include <mbgl/style/expression/parsing_context.hpp> #include <mbgl/style/expression/is_constant.hpp> +#include <mbgl/style/conversion/function.hpp> #include <mbgl/style/conversion/geojson.hpp> #include <mbgl/util/geojson.hpp> #include <nan.h> @@ -73,25 +74,19 @@ void NodeExpression::Parse(const Nan::FunctionCallbackInfo<v8::Value>& info) { expected = parseType(info[1]->ToObject()); } - auto expr = info[0]; - - try { - ParsingContext ctx = expected ? ParsingContext(*expected) : ParsingContext(); - ParseResult parsed = ctx.parseLayerPropertyExpression(mbgl::style::conversion::Convertible(expr)); - if (parsed) { - assert(ctx.getErrors().size() == 0); - auto nodeExpr = new NodeExpression(std::move(*parsed)); - const int argc = 0; - v8::Local<v8::Value> argv[0] = {}; - auto wrapped = Nan::NewInstance(cons, argc, argv).ToLocalChecked(); - nodeExpr->Wrap(wrapped); - info.GetReturnValue().Set(wrapped); - return; - } + auto success = [&cons, &info](std::unique_ptr<Expression> result) { + auto nodeExpr = new NodeExpression(std::move(result)); + const int argc = 0; + v8::Local<v8::Value> argv[0] = {}; + auto wrapped = Nan::NewInstance(cons, argc, argv).ToLocalChecked(); + nodeExpr->Wrap(wrapped); + info.GetReturnValue().Set(wrapped); + }; + auto fail = [&info](const std::vector<ParsingError>& errors) { v8::Local<v8::Array> result = Nan::New<v8::Array>(); - for (std::size_t i = 0; i < ctx.getErrors().size(); i++) { - const auto& error = ctx.getErrors()[i]; + for (std::size_t i = 0; i < errors.size(); ++i) { + const auto& error = errors[i]; v8::Local<v8::Object> err = Nan::New<v8::Object>(); Nan::Set(err, Nan::New("key").ToLocalChecked(), @@ -102,6 +97,29 @@ void NodeExpression::Parse(const Nan::FunctionCallbackInfo<v8::Value>& info) { Nan::Set(result, Nan::New((uint32_t)i), err); } info.GetReturnValue().Set(result); + }; + + auto expr = info[0]; + + try { + mbgl::style::conversion::Convertible convertible(expr); + + if (expr->IsObject() && !expr->IsArray() && expected) { + mbgl::style::conversion::Error error; + auto func = convertFunctionToExpression(*expected, convertible, error, false); + if (func) { + return success(std::move(*func)); + } + return fail({ { error.message, "" } }); + } + + ParsingContext ctx = expected ? ParsingContext(*expected) : ParsingContext(); + ParseResult parsed = ctx.parseLayerPropertyExpression(mbgl::style::conversion::Convertible(expr)); + if (parsed) { + assert(ctx.getErrors().empty()); + return success(std::move(*parsed)); + } + return fail(ctx.getErrors()); } catch(std::exception &ex) { return Nan::ThrowError(ex.what()); } diff --git a/platform/node/test/ignores.json b/platform/node/test/ignores.json index acc8724a29..287211f388 100644 --- a/platform/node/test/ignores.json +++ b/platform/node/test/ignores.json @@ -15,30 +15,17 @@ "expression-tests/legacy/categorical/string": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/categorical/string-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/categorical/tokens": "https://github.com/mapbox/mapbox-gl-native/issues/12747", - "expression-tests/legacy/exponential/array": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/exponential/array-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747", - "expression-tests/legacy/exponential/base": "https://github.com/mapbox/mapbox-gl-native/issues/12747", - "expression-tests/legacy/exponential/color": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/exponential/color-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/exponential/color-hcl": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/exponential/color-lab": "https://github.com/mapbox/mapbox-gl-native/issues/12747", - "expression-tests/legacy/exponential/composite": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/exponential/composite-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747", - "expression-tests/legacy/exponential/duplicate-stops": "https://github.com/mapbox/mapbox-gl-native/issues/12747", - "expression-tests/legacy/exponential/implicit": "https://github.com/mapbox/mapbox-gl-native/issues/12747", - "expression-tests/legacy/exponential/number": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/exponential/number-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747", - "expression-tests/legacy/identity/array": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/identity/array-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747", - "expression-tests/legacy/identity/boolean": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/identity/boolean-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747", - "expression-tests/legacy/identity/color": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/identity/color-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747", - "expression-tests/legacy/identity/enum": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/identity/enum-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747", - "expression-tests/legacy/identity/number": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/identity/number-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747", - "expression-tests/legacy/identity/string": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/identity/string-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/interval/array": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/interval/array-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747", |