upgrade to JUCE 5.4.3. Remove (probably) unused JUCE modules. Remove VST2 target (it's been end-of-life'd by Steinberg and by JUCE)
This commit is contained in:
@ -348,7 +348,16 @@ struct JSONFormatter
|
||||
}
|
||||
else if (v.isDouble())
|
||||
{
|
||||
out << String (static_cast<double> (v), maximumDecimalPlaces);
|
||||
auto d = static_cast<double> (v);
|
||||
|
||||
if (juce_isfinite (d))
|
||||
{
|
||||
out << serialiseDouble (d);
|
||||
}
|
||||
else
|
||||
{
|
||||
out << "null";
|
||||
}
|
||||
}
|
||||
else if (v.isArray())
|
||||
{
|
||||
@ -617,31 +626,57 @@ public:
|
||||
|
||||
void runTest() override
|
||||
{
|
||||
beginTest ("JSON");
|
||||
Random r = getRandom();
|
||||
|
||||
expect (JSON::parse (String()) == var());
|
||||
expect (JSON::parse ("{}").isObject());
|
||||
expect (JSON::parse ("[]").isArray());
|
||||
expect (JSON::parse ("[ 1234 ]")[0].isInt());
|
||||
expect (JSON::parse ("[ 12345678901234 ]")[0].isInt64());
|
||||
expect (JSON::parse ("[ 1.123e3 ]")[0].isDouble());
|
||||
expect (JSON::parse ("[ -1234]")[0].isInt());
|
||||
expect (JSON::parse ("[-12345678901234]")[0].isInt64());
|
||||
expect (JSON::parse ("[-1.123e3]")[0].isDouble());
|
||||
|
||||
for (int i = 100; --i >= 0;)
|
||||
{
|
||||
var v;
|
||||
beginTest ("JSON");
|
||||
|
||||
if (i > 0)
|
||||
v = createRandomVar (r, 0);
|
||||
Random r = getRandom();
|
||||
|
||||
const bool oneLine = r.nextBool();
|
||||
String asString (JSON::toString (v, oneLine));
|
||||
var parsed = JSON::parse ("[" + asString + "]")[0];
|
||||
String parsedString (JSON::toString (parsed, oneLine));
|
||||
expect (asString.isNotEmpty() && parsedString == asString);
|
||||
expect (JSON::parse (String()) == var());
|
||||
expect (JSON::parse ("{}").isObject());
|
||||
expect (JSON::parse ("[]").isArray());
|
||||
expect (JSON::parse ("[ 1234 ]")[0].isInt());
|
||||
expect (JSON::parse ("[ 12345678901234 ]")[0].isInt64());
|
||||
expect (JSON::parse ("[ 1.123e3 ]")[0].isDouble());
|
||||
expect (JSON::parse ("[ -1234]")[0].isInt());
|
||||
expect (JSON::parse ("[-12345678901234]")[0].isInt64());
|
||||
expect (JSON::parse ("[-1.123e3]")[0].isDouble());
|
||||
|
||||
for (int i = 100; --i >= 0;)
|
||||
{
|
||||
var v;
|
||||
|
||||
if (i > 0)
|
||||
v = createRandomVar (r, 0);
|
||||
|
||||
const bool oneLine = r.nextBool();
|
||||
String asString (JSON::toString (v, oneLine));
|
||||
var parsed = JSON::parse ("[" + asString + "]")[0];
|
||||
String parsedString (JSON::toString (parsed, oneLine));
|
||||
expect (asString.isNotEmpty() && parsedString == asString);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
beginTest ("Float formatting");
|
||||
|
||||
std::map<double, String> tests;
|
||||
tests[1] = "1.0";
|
||||
tests[1.1] = "1.1";
|
||||
tests[1.01] = "1.01";
|
||||
tests[0.76378] = "0.76378";
|
||||
tests[-10] = "-10.0";
|
||||
tests[10.01] = "10.01";
|
||||
tests[0.0123] = "0.0123";
|
||||
tests[-3.7e-27] = "-3.7e-27";
|
||||
tests[1e+40] = "1.0e40";
|
||||
tests[-12345678901234567.0] = "-1.234567890123457e16";
|
||||
tests[192000] = "192000.0";
|
||||
tests[1234567] = "1.234567e6";
|
||||
tests[0.00006] = "0.00006";
|
||||
tests[0.000006] = "6.0e-6";
|
||||
|
||||
for (auto& test : tests)
|
||||
expectEquals (JSON::toString (test.first), test.second);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -92,12 +92,13 @@ public:
|
||||
/** Returns a string which contains a JSON-formatted representation of the var object.
|
||||
If allOnOneLine is true, the result will be compacted into a single line of text
|
||||
with no carriage-returns. If false, it will be laid-out in a more human-readable format.
|
||||
The maximumDecimalPlaces parameter determines the precision of floating point numbers.
|
||||
The maximumDecimalPlaces parameter determines the precision of floating point numbers
|
||||
in scientific notation.
|
||||
@see writeToStream
|
||||
*/
|
||||
static String toString (const var& objectToFormat,
|
||||
bool allOnOneLine = false,
|
||||
int maximumDecimalPlaces = 20);
|
||||
int maximumDecimalPlaces = 15);
|
||||
|
||||
/** Parses a string that was created with the toString() method.
|
||||
This is slightly different to the parse() methods because they will reject primitive
|
||||
@ -109,13 +110,14 @@ public:
|
||||
/** Writes a JSON-formatted representation of the var object to the given stream.
|
||||
If allOnOneLine is true, the result will be compacted into a single line of text
|
||||
with no carriage-returns. If false, it will be laid-out in a more human-readable format.
|
||||
The maximumDecimalPlaces parameter determines the precision of floating point numbers.
|
||||
The maximumDecimalPlaces parameter determines the precision of floating point numbers
|
||||
in scientific notation.
|
||||
@see toString
|
||||
*/
|
||||
static void writeToStream (OutputStream& output,
|
||||
const var& objectToFormat,
|
||||
bool allOnOneLine = false,
|
||||
int maximumDecimalPlaces = 20);
|
||||
int maximumDecimalPlaces = 15);
|
||||
|
||||
/** Returns a version of a string with any extended characters escaped. */
|
||||
static String escapeString (StringRef);
|
||||
|
@ -81,13 +81,13 @@ struct JavascriptEngine::RootObject : public DynamicObject
|
||||
void execute (const String& code)
|
||||
{
|
||||
ExpressionTreeBuilder tb (code);
|
||||
std::unique_ptr<BlockStatement> (tb.parseStatementList())->perform (Scope (nullptr, this, this), nullptr);
|
||||
std::unique_ptr<BlockStatement> (tb.parseStatementList())->perform (Scope ({}, *this, *this), nullptr);
|
||||
}
|
||||
|
||||
var evaluate (const String& code)
|
||||
{
|
||||
ExpressionTreeBuilder tb (code);
|
||||
return ExpPtr (tb.parseExpression())->getResult (Scope (nullptr, this, this));
|
||||
return ExpPtr (tb.parseExpression())->getResult (Scope ({}, *this, *this));
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
@ -103,7 +103,7 @@ struct JavascriptEngine::RootObject : public DynamicObject
|
||||
static bool isNumericOrUndefined (const var& v) noexcept { return isNumeric (v) || v.isUndefined(); }
|
||||
static int64 getOctalValue (const String& s) { BigInteger b; b.parseString (s.initialSectionContainingOnly ("01234567"), 8); return b.toInt64(); }
|
||||
static Identifier getPrototypeIdentifier() { static const Identifier i ("prototype"); return i; }
|
||||
static var* getPropertyPointer (DynamicObject* o, const Identifier& i) noexcept { return o->getProperties().getVarPointer (i); }
|
||||
static var* getPropertyPointer (DynamicObject& o, const Identifier& i) noexcept { return o.getProperties().getVarPointer (i); }
|
||||
|
||||
//==============================================================================
|
||||
struct CodeLocation
|
||||
@ -131,9 +131,11 @@ struct JavascriptEngine::RootObject : public DynamicObject
|
||||
//==============================================================================
|
||||
struct Scope
|
||||
{
|
||||
Scope (const Scope* p, RootObject* r, DynamicObject* s) noexcept : parent (p), root (r), scope (s) {}
|
||||
Scope (const Scope* p, ReferenceCountedObjectPtr<RootObject> rt, DynamicObject::Ptr scp) noexcept
|
||||
: parent (p), root (std::move (rt)),
|
||||
scope (std::move (scp)) {}
|
||||
|
||||
const Scope* parent;
|
||||
const Scope* const parent;
|
||||
ReferenceCountedObjectPtr<RootObject> root;
|
||||
DynamicObject::Ptr scope;
|
||||
|
||||
@ -141,13 +143,13 @@ struct JavascriptEngine::RootObject : public DynamicObject
|
||||
{
|
||||
if (auto* o = targetObject.getDynamicObject())
|
||||
{
|
||||
if (auto* prop = getPropertyPointer (o, functionName))
|
||||
if (auto* prop = getPropertyPointer (*o, functionName))
|
||||
return *prop;
|
||||
|
||||
for (auto* p = o->getProperty (getPrototypeIdentifier()).getDynamicObject(); p != nullptr;
|
||||
p = p->getProperty (getPrototypeIdentifier()).getDynamicObject())
|
||||
{
|
||||
if (auto* prop = getPropertyPointer (p, functionName))
|
||||
if (auto* prop = getPropertyPointer (*p, functionName))
|
||||
return *prop;
|
||||
}
|
||||
|
||||
@ -174,14 +176,14 @@ struct JavascriptEngine::RootObject : public DynamicObject
|
||||
var* findRootClassProperty (const Identifier& className, const Identifier& propName) const
|
||||
{
|
||||
if (auto* cls = root->getProperty (className).getDynamicObject())
|
||||
return getPropertyPointer (cls, propName);
|
||||
return getPropertyPointer (*cls, propName);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
var findSymbolInParentScopes (const Identifier& name) const
|
||||
{
|
||||
if (auto* v = getPropertyPointer (scope, name))
|
||||
if (auto v = getPropertyPointer (*scope, name))
|
||||
return *v;
|
||||
|
||||
return parent != nullptr ? parent->findSymbolInParentScopes (name)
|
||||
@ -192,9 +194,9 @@ struct JavascriptEngine::RootObject : public DynamicObject
|
||||
{
|
||||
auto* target = args.thisObject.getDynamicObject();
|
||||
|
||||
if (target == nullptr || target == scope)
|
||||
if (target == nullptr || target == scope.get())
|
||||
{
|
||||
if (auto* m = getPropertyPointer (scope, function))
|
||||
if (auto* m = getPropertyPointer (*scope, function))
|
||||
{
|
||||
if (auto fo = dynamic_cast<FunctionObject*> (m->getObject()))
|
||||
{
|
||||
@ -208,7 +210,7 @@ struct JavascriptEngine::RootObject : public DynamicObject
|
||||
|
||||
for (int i = 0; i < props.size(); ++i)
|
||||
if (auto* o = props.getValueAt (i).getDynamicObject())
|
||||
if (Scope (this, root, o).findAndInvokeMethod (function, args, result))
|
||||
if (Scope (this, *root, *o).findAndInvokeMethod (function, args, result))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
@ -220,7 +222,7 @@ struct JavascriptEngine::RootObject : public DynamicObject
|
||||
{
|
||||
auto* target = args.thisObject.getDynamicObject();
|
||||
|
||||
if (target == nullptr || target == scope)
|
||||
if (target == nullptr || target == scope.get())
|
||||
{
|
||||
if (auto fo = dynamic_cast<FunctionObject*> (m.getObject()))
|
||||
{
|
||||
@ -238,6 +240,8 @@ struct JavascriptEngine::RootObject : public DynamicObject
|
||||
if (Time::getCurrentTime() > root->timeout)
|
||||
location.throwError (root->timeout == Time() ? "Interrupted" : "Execution timed-out");
|
||||
}
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Scope)
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
@ -378,7 +382,7 @@ struct JavascriptEngine::RootObject : public DynamicObject
|
||||
|
||||
void assign (const Scope& s, const var& newValue) const override
|
||||
{
|
||||
if (auto* v = getPropertyPointer (s.scope, name))
|
||||
if (auto* v = getPropertyPointer (*s.scope, name))
|
||||
*v = newValue;
|
||||
else
|
||||
s.root->setProperty (name, newValue);
|
||||
@ -403,7 +407,7 @@ struct JavascriptEngine::RootObject : public DynamicObject
|
||||
}
|
||||
|
||||
if (auto* o = p.getDynamicObject())
|
||||
if (auto* v = getPropertyPointer (o, child))
|
||||
if (auto* v = getPropertyPointer (*o, child))
|
||||
return *v;
|
||||
|
||||
return var::undefined();
|
||||
@ -436,7 +440,7 @@ struct JavascriptEngine::RootObject : public DynamicObject
|
||||
|
||||
if (auto* o = arrayVar.getDynamicObject())
|
||||
if (key.isString())
|
||||
if (auto* v = getPropertyPointer (o, Identifier (key)))
|
||||
if (auto* v = getPropertyPointer (*o, Identifier (key)))
|
||||
return *v;
|
||||
|
||||
return var::undefined();
|
||||
@ -829,7 +833,7 @@ struct JavascriptEngine::RootObject : public DynamicObject
|
||||
tb.parseFunctionParamsAndBody (*this);
|
||||
}
|
||||
|
||||
DynamicObject::Ptr clone() override { return new FunctionObject (*this); }
|
||||
DynamicObject::Ptr clone() override { return *new FunctionObject (*this); }
|
||||
|
||||
void writeAsJSON (OutputStream& out, int /*indentLevel*/, bool /*allOnOneLine*/, int /*maximumDecimalPlaces*/) override
|
||||
{
|
||||
@ -1092,6 +1096,9 @@ struct JavascriptEngine::RootObject : public DynamicObject
|
||||
if (matchIf (TokenTypes::assign)) { ExpPtr rhs (parseExpression()); return new Assignment (location, lhs, rhs); }
|
||||
if (matchIf (TokenTypes::plusEquals)) return parseInPlaceOpExpression<AdditionOp> (lhs);
|
||||
if (matchIf (TokenTypes::minusEquals)) return parseInPlaceOpExpression<SubtractionOp> (lhs);
|
||||
if (matchIf (TokenTypes::timesEquals)) return parseInPlaceOpExpression<MultiplyOp> (lhs);
|
||||
if (matchIf (TokenTypes::divideEquals)) return parseInPlaceOpExpression<DivideOp> (lhs);
|
||||
if (matchIf (TokenTypes::moduloEquals)) return parseInPlaceOpExpression<ModuloOp> (lhs);
|
||||
if (matchIf (TokenTypes::leftShiftEquals)) return parseInPlaceOpExpression<LeftShiftOp> (lhs);
|
||||
if (matchIf (TokenTypes::rightShiftEquals)) return parseInPlaceOpExpression<RightShiftOp> (lhs);
|
||||
|
||||
@ -1105,7 +1112,7 @@ struct JavascriptEngine::RootObject : public DynamicObject
|
||||
Expression* parseInPlaceOpExpression (ExpPtr& lhs)
|
||||
{
|
||||
ExpPtr rhs (parseExpression());
|
||||
Expression* bareLHS = lhs.get(); // careful - bare pointer is deliberately alised
|
||||
Expression* bareLHS = lhs.get(); // careful - bare pointer is deliberately aliased
|
||||
return new SelfAssignment (location, bareLHS, new OpType (location, lhs, rhs));
|
||||
}
|
||||
|
||||
@ -1862,13 +1869,13 @@ var JavascriptEngine::evaluate (const String& code, Result* result)
|
||||
|
||||
var JavascriptEngine::callFunction (const Identifier& function, const var::NativeFunctionArgs& args, Result* result)
|
||||
{
|
||||
var returnVal (var::undefined());
|
||||
auto returnVal = var::undefined();
|
||||
|
||||
try
|
||||
{
|
||||
prepareTimeout();
|
||||
if (result != nullptr) *result = Result::ok();
|
||||
RootObject::Scope (nullptr, root, root).findAndInvokeMethod (function, args, returnVal);
|
||||
RootObject::Scope ({}, *root, *root).findAndInvokeMethod (function, args, returnVal);
|
||||
}
|
||||
catch (String& error)
|
||||
{
|
||||
@ -1881,14 +1888,15 @@ var JavascriptEngine::callFunction (const Identifier& function, const var::Nativ
|
||||
var JavascriptEngine::callFunctionObject (DynamicObject* objectScope, const var& functionObject,
|
||||
const var::NativeFunctionArgs& args, Result* result)
|
||||
{
|
||||
var returnVal (var::undefined());
|
||||
auto returnVal = var::undefined();
|
||||
|
||||
try
|
||||
{
|
||||
prepareTimeout();
|
||||
if (result != nullptr) *result = Result::ok();
|
||||
RootObject::Scope rootScope (nullptr, root, root);
|
||||
RootObject::Scope (&rootScope, root, objectScope).invokeMethod (functionObject, args, returnVal);
|
||||
RootObject::Scope rootScope ({}, *root, *root);
|
||||
RootObject::Scope (&rootScope, *root, DynamicObject::Ptr (objectScope))
|
||||
.invokeMethod (functionObject, args, returnVal);
|
||||
}
|
||||
catch (String& error)
|
||||
{
|
||||
|
Reference in New Issue
Block a user