@geastack/compiler 1.0.18 → 1.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1433,6 +1433,13 @@ inline constexpr std::uint32_t cycleMature = std::uint32_t{1} << 29;
|
|
|
1433
1433
|
// full collection -- the only pass that could ever free it -- examines it.
|
|
1434
1434
|
inline constexpr std::uint32_t cyclePermanent = std::uint32_t{1} << 28;
|
|
1435
1435
|
inline void dropNativeExpando(const void* object, RefCounts* counts);
|
|
1436
|
+
#if defined(GEA_RUNTIME_COMPACT_CODE) && GEA_RUNTIME_COMPACT_CODE
|
|
1437
|
+
// Only creating an expando should retain its registry's erase machinery.
|
|
1438
|
+
inline void (*nativeExpandoDropper)(const void*, RefCounts*) = nullptr;
|
|
1439
|
+
inline void dropTaggedExpando(const void* object, RefCounts* counts) { nativeExpandoDropper(object, counts); }
|
|
1440
|
+
#else
|
|
1441
|
+
inline void dropTaggedExpando(const void* object, RefCounts* counts) { dropNativeExpando(object, counts); }
|
|
1442
|
+
#endif
|
|
1436
1443
|
template <typename T>
|
|
1437
1444
|
inline RefCounts* refCountsOf(T* object);
|
|
1438
1445
|
|
|
@@ -1992,7 +1999,7 @@ struct RefOperationsFor {
|
|
|
1992
1999
|
profileRefDestroyed<T>(refBlockSize<T>, cycleState().collecting, object);
|
|
1993
2000
|
#endif
|
|
1994
2001
|
RefCounts* counts = refCountsOf(static_cast<T*>(object));
|
|
1995
|
-
if ((counts->weak & expandoTagged) != 0) [[unlikely]]
|
|
2002
|
+
if ((counts->weak & expandoTagged) != 0) [[unlikely]] dropTaggedExpando(object, counts);
|
|
1996
2003
|
// Unlike `expandoTagged`, `cycleMature` has no side table to notify -- an
|
|
1997
2004
|
// unconditional clear is as cheap as the branch would be. Without this,
|
|
1998
2005
|
// an object that died mature (as most steady-state objects do) would
|
|
@@ -2004,7 +2011,8 @@ struct RefOperationsFor {
|
|
|
2004
2011
|
}
|
|
2005
2012
|
static void release(void* block) { AllocationPool<refBlockSize<T>, refBlockAlign<T>>::give(block); }
|
|
2006
2013
|
static void trace(const void* object, RefVisitor& visitor) { traceRefs(*static_cast<const T*>(object), visitor); }
|
|
2007
|
-
|
|
2014
|
+
// Constant initialization lets the linker discard unused type operations.
|
|
2015
|
+
static constexpr const RefOperations* classBase() {
|
|
2008
2016
|
using Base = typename ClassRefBase<T>::type;
|
|
2009
2017
|
if constexpr (std::is_void_v<Base>) return nullptr;
|
|
2010
2018
|
else return &RefOperationsFor<Base>::table;
|
|
@@ -2271,8 +2279,20 @@ struct Ref {
|
|
|
2271
2279
|
* the branch is a property of the type, so the non-final path is not even
|
|
2272
2280
|
* emitted for a final one.
|
|
2273
2281
|
*/
|
|
2274
|
-
|
|
2282
|
+
#if !defined(GEA_RUNTIME_COMPACT_CODE) || !GEA_RUNTIME_COMPACT_CODE
|
|
2283
|
+
[[gnu::always_inline]]
|
|
2284
|
+
#endif
|
|
2285
|
+
void release() {
|
|
2275
2286
|
if (pointer_ == nullptr) return;
|
|
2287
|
+
#if defined(GEA_RUNTIME_COMPACT_CODE) && GEA_RUNTIME_COMPACT_CODE
|
|
2288
|
+
releaseOutOfLine(pointer_);
|
|
2289
|
+
#else
|
|
2290
|
+
releasePointer(pointer_);
|
|
2291
|
+
#endif
|
|
2292
|
+
}
|
|
2293
|
+
// Keep handles in registers while sharing their release body on small targets.
|
|
2294
|
+
[[gnu::noinline]] static void releaseOutOfLine(T* pointer) { releasePointer(pointer); }
|
|
2295
|
+
[[gnu::always_inline]] static void releasePointer(T* pointer_) {
|
|
2276
2296
|
detail::RefCounts* counts = detail::refCountsOf(pointer_);
|
|
2277
2297
|
// A cycle collection marks its whole unreachable subgraph dead before
|
|
2278
2298
|
// destroying any node. These are its internal edges, not another owner.
|
|
@@ -2304,12 +2324,18 @@ struct Ref {
|
|
|
2304
2324
|
// `CallableObject` built inline for a closure-table store carried two empty
|
|
2305
2325
|
// handles whose null-ness clang had just written and then had to re-test,
|
|
2306
2326
|
// because this call had taken their address on the previous iteration.
|
|
2307
|
-
|
|
2327
|
+
#if defined(GEA_RUNTIME_COMPACT_CODE) && GEA_RUNTIME_COMPACT_CODE
|
|
2328
|
+
// releaseOutOfLine already shares the complete body in compact builds.
|
|
2329
|
+
[[gnu::always_inline]]
|
|
2330
|
+
#else
|
|
2331
|
+
[[gnu::noinline]]
|
|
2332
|
+
#endif
|
|
2333
|
+
static void releaseLast(T* pointer, detail::RefCounts* counts) {
|
|
2308
2334
|
if constexpr (std::is_final_v<T>) {
|
|
2309
2335
|
#if defined(GEA_PROFILE_ALLOCATIONS)
|
|
2310
2336
|
detail::profileRefDestroyed<T>(detail::refBlockSize<T>, detail::cycleState().collecting, pointer);
|
|
2311
2337
|
#endif
|
|
2312
|
-
if ((counts->weak & detail::expandoTagged) != 0) [[unlikely]] detail::
|
|
2338
|
+
if ((counts->weak & detail::expandoTagged) != 0) [[unlikely]] detail::dropTaggedExpando(pointer, counts);
|
|
2313
2339
|
// See `RefOperationsFor::destroy`: an object that died `cycleMature`
|
|
2314
2340
|
// must not carry the bit into the `weak == 0` check just below.
|
|
2315
2341
|
counts->weak &= ~(detail::cycleMature | detail::cyclePermanent);
|
|
@@ -3871,6 +3897,25 @@ struct CallableObject<Result(Arguments...)> {
|
|
|
3871
3897
|
}
|
|
3872
3898
|
};
|
|
3873
3899
|
|
|
3900
|
+
// Header-only builtins must not register dynamic initializers: taking every
|
|
3901
|
+
// thunk's address at startup keeps all of libm in even a math-free program.
|
|
3902
|
+
// Materialize the shared callable only on a value read, preserving its identity.
|
|
3903
|
+
template <typename Signature, auto Entry>
|
|
3904
|
+
struct HostFunction;
|
|
3905
|
+
|
|
3906
|
+
template <typename Result, typename... Arguments, Result (*Entry)(void*, Arguments...)>
|
|
3907
|
+
struct HostFunction<Result(Arguments...), Entry> {
|
|
3908
|
+
using Carrier = CallableObject<Result(Arguments...)>;
|
|
3909
|
+
static const Carrier& carrier() {
|
|
3910
|
+
static const Carrier value{Entry, nullptr};
|
|
3911
|
+
return value;
|
|
3912
|
+
}
|
|
3913
|
+
operator const Carrier&() const { return carrier(); }
|
|
3914
|
+
const Carrier& identified() const { return carrier().identified(); }
|
|
3915
|
+
[[gnu::always_inline]] Result call(Arguments... arguments) const { return Entry(nullptr, std::forward<Arguments>(arguments)...); }
|
|
3916
|
+
[[gnu::always_inline]] Result operator()(Arguments... arguments) const { return Entry(nullptr, std::forward<Arguments>(arguments)...); }
|
|
3917
|
+
};
|
|
3918
|
+
|
|
3874
3919
|
namespace detail {
|
|
3875
3920
|
template <typename>
|
|
3876
3921
|
struct IsNativeCallableObject : std::false_type {};
|
|
@@ -13862,6 +13907,9 @@ inline gea::Ref<DynamicObject> expandoFor(const gea::Ref<void>& payload, bool cr
|
|
|
13862
13907
|
fresh.table->markNativeExpando();
|
|
13863
13908
|
entries[address] = fresh;
|
|
13864
13909
|
refCountsOf(payload.get())->weak |= expandoTagged;
|
|
13910
|
+
#if defined(GEA_RUNTIME_COMPACT_CODE) && GEA_RUNTIME_COMPACT_CODE
|
|
13911
|
+
nativeExpandoDropper = &dropNativeExpando;
|
|
13912
|
+
#endif
|
|
13865
13913
|
return fresh.table;
|
|
13866
13914
|
}
|
|
13867
13915
|
|
|
@@ -22214,47 +22262,47 @@ inline double imul_invoke(void*, double a, double b) {
|
|
|
22214
22262
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22215
22263
|
extern const gea::CallableObject<double(double)> floor;
|
|
22216
22264
|
#else
|
|
22217
|
-
inline
|
|
22265
|
+
inline constexpr gea::HostFunction<double(double), &detail::floor_invoke> floor{};
|
|
22218
22266
|
#endif
|
|
22219
22267
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22220
22268
|
extern const gea::CallableObject<double(double)> round;
|
|
22221
22269
|
#else
|
|
22222
|
-
inline
|
|
22270
|
+
inline constexpr gea::HostFunction<double(double), &detail::round_invoke> round{};
|
|
22223
22271
|
#endif
|
|
22224
22272
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22225
22273
|
extern const gea::CallableObject<double(double)> sin;
|
|
22226
22274
|
#else
|
|
22227
|
-
inline
|
|
22275
|
+
inline constexpr gea::HostFunction<double(double), &detail::sin_invoke> sin{};
|
|
22228
22276
|
#endif
|
|
22229
22277
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22230
22278
|
extern const gea::CallableObject<double(double)> cos;
|
|
22231
22279
|
#else
|
|
22232
|
-
inline
|
|
22280
|
+
inline constexpr gea::HostFunction<double(double), &detail::cos_invoke> cos{};
|
|
22233
22281
|
#endif
|
|
22234
22282
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22235
22283
|
extern const gea::CallableObject<double(double)> sqrt;
|
|
22236
22284
|
#else
|
|
22237
|
-
inline
|
|
22285
|
+
inline constexpr gea::HostFunction<double(double), &detail::sqrt_invoke> sqrt{};
|
|
22238
22286
|
#endif
|
|
22239
22287
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22240
22288
|
extern const gea::CallableObject<double(double)> abs;
|
|
22241
22289
|
#else
|
|
22242
|
-
inline
|
|
22290
|
+
inline constexpr gea::HostFunction<double(double), &detail::abs_invoke> abs{};
|
|
22243
22291
|
#endif
|
|
22244
22292
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22245
22293
|
extern const gea::CallableObject<double(double)> ceil;
|
|
22246
22294
|
#else
|
|
22247
|
-
inline
|
|
22295
|
+
inline constexpr gea::HostFunction<double(double), &detail::ceil_invoke> ceil{};
|
|
22248
22296
|
#endif
|
|
22249
22297
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22250
22298
|
extern const gea::CallableObject<double(double, double)> pow;
|
|
22251
22299
|
#else
|
|
22252
|
-
inline
|
|
22300
|
+
inline constexpr gea::HostFunction<double(double, double), &detail::pow_invoke> pow{};
|
|
22253
22301
|
#endif
|
|
22254
22302
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22255
22303
|
extern const gea::CallableObject<double(double, double)> atan2;
|
|
22256
22304
|
#else
|
|
22257
|
-
inline
|
|
22305
|
+
inline constexpr gea::HostFunction<double(double, double), &detail::atan2_invoke> atan2{};
|
|
22258
22306
|
#endif
|
|
22259
22307
|
// The rest of the transcendentals the corpus reaches. Each is ECMA-262's own
|
|
22260
22308
|
// definition and each is `<cmath>`'s function of the same name -- 21.3.2.2
|
|
@@ -22263,47 +22311,47 @@ inline const gea::CallableObject<double(double, double)> atan2{detail::atan2_inv
|
|
|
22263
22311
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22264
22312
|
extern const gea::CallableObject<double(double)> tan;
|
|
22265
22313
|
#else
|
|
22266
|
-
inline
|
|
22314
|
+
inline constexpr gea::HostFunction<double(double), &detail::tan_invoke> tan{};
|
|
22267
22315
|
#endif
|
|
22268
22316
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22269
22317
|
extern const gea::CallableObject<double(double)> asin;
|
|
22270
22318
|
#else
|
|
22271
|
-
inline
|
|
22319
|
+
inline constexpr gea::HostFunction<double(double), &detail::asin_invoke> asin{};
|
|
22272
22320
|
#endif
|
|
22273
22321
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22274
22322
|
extern const gea::CallableObject<double(double)> acos;
|
|
22275
22323
|
#else
|
|
22276
|
-
inline
|
|
22324
|
+
inline constexpr gea::HostFunction<double(double), &detail::acos_invoke> acos{};
|
|
22277
22325
|
#endif
|
|
22278
22326
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22279
22327
|
extern const gea::CallableObject<double(double)> atan;
|
|
22280
22328
|
#else
|
|
22281
|
-
inline
|
|
22329
|
+
inline constexpr gea::HostFunction<double(double), &detail::atan_invoke> atan{};
|
|
22282
22330
|
#endif
|
|
22283
22331
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22284
22332
|
extern const gea::CallableObject<double(double)> sinh;
|
|
22285
22333
|
#else
|
|
22286
|
-
inline
|
|
22334
|
+
inline constexpr gea::HostFunction<double(double), &detail::sinh_invoke> sinh{};
|
|
22287
22335
|
#endif
|
|
22288
22336
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22289
22337
|
extern const gea::CallableObject<double(double)> log;
|
|
22290
22338
|
#else
|
|
22291
|
-
inline
|
|
22339
|
+
inline constexpr gea::HostFunction<double(double), &detail::log_invoke> log{};
|
|
22292
22340
|
#endif
|
|
22293
22341
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22294
22342
|
extern const gea::CallableObject<double()> random;
|
|
22295
22343
|
#else
|
|
22296
|
-
inline
|
|
22344
|
+
inline constexpr gea::HostFunction<double(), &detail::random_invoke> random{};
|
|
22297
22345
|
#endif
|
|
22298
22346
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22299
22347
|
extern const gea::CallableObject<double(gea::Ref<gea::ArrayObject<double>>)> max;
|
|
22300
22348
|
#else
|
|
22301
|
-
inline
|
|
22349
|
+
inline constexpr gea::HostFunction<double(gea::Ref<gea::ArrayObject<double>>), &detail::max_invoke> max{};
|
|
22302
22350
|
#endif
|
|
22303
22351
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22304
22352
|
extern const gea::CallableObject<double(gea::Ref<gea::ArrayObject<double>>)> min;
|
|
22305
22353
|
#else
|
|
22306
|
-
inline
|
|
22354
|
+
inline constexpr gea::HostFunction<double(gea::Ref<gea::ArrayObject<double>>), &detail::min_invoke> min{};
|
|
22307
22355
|
#endif
|
|
22308
22356
|
// A direct call's already-evaluated numeric operands need no JS array identity.
|
|
22309
22357
|
// The initializer list borrows native stack storage for this synchronous call.
|
|
@@ -22320,7 +22368,7 @@ inline double minDirect(std::initializer_list<double> values) {
|
|
|
22320
22368
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22321
22369
|
extern const gea::CallableObject<double(gea::Ref<gea::ArrayObject<double>>)> hypot;
|
|
22322
22370
|
#else
|
|
22323
|
-
inline
|
|
22371
|
+
inline constexpr gea::HostFunction<double(gea::Ref<gea::ArrayObject<double>>), &detail::hypot_invoke> hypot{};
|
|
22324
22372
|
#endif
|
|
22325
22373
|
// The sixteen members `lib.es2015.core.d.ts` adds to `Math` beyond the ES5 set
|
|
22326
22374
|
// plus `cbrt`, each over the same exact scalar ABI as the row above. `imul` is
|
|
@@ -22328,82 +22376,82 @@ inline const gea::CallableObject<double(gea::Ref<gea::ArrayObject<double>>)> hyp
|
|
|
22328
22376
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22329
22377
|
extern const gea::CallableObject<double(double)> cbrt;
|
|
22330
22378
|
#else
|
|
22331
|
-
inline
|
|
22379
|
+
inline constexpr gea::HostFunction<double(double), &detail::cbrt_invoke> cbrt{};
|
|
22332
22380
|
#endif
|
|
22333
22381
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22334
22382
|
extern const gea::CallableObject<double(double)> sign;
|
|
22335
22383
|
#else
|
|
22336
|
-
inline
|
|
22384
|
+
inline constexpr gea::HostFunction<double(double), &detail::sign_invoke> sign{};
|
|
22337
22385
|
#endif
|
|
22338
22386
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22339
22387
|
extern const gea::CallableObject<double(double)> trunc;
|
|
22340
22388
|
#else
|
|
22341
|
-
inline
|
|
22389
|
+
inline constexpr gea::HostFunction<double(double), &detail::trunc_invoke> trunc{};
|
|
22342
22390
|
#endif
|
|
22343
22391
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22344
22392
|
extern const gea::CallableObject<double(double)> exp;
|
|
22345
22393
|
#else
|
|
22346
|
-
inline
|
|
22394
|
+
inline constexpr gea::HostFunction<double(double), &detail::exp_invoke> exp{};
|
|
22347
22395
|
#endif
|
|
22348
22396
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22349
22397
|
extern const gea::CallableObject<double(double)> expm1;
|
|
22350
22398
|
#else
|
|
22351
|
-
inline
|
|
22399
|
+
inline constexpr gea::HostFunction<double(double), &detail::expm1_invoke> expm1{};
|
|
22352
22400
|
#endif
|
|
22353
22401
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22354
22402
|
extern const gea::CallableObject<double(double)> log10;
|
|
22355
22403
|
#else
|
|
22356
|
-
inline
|
|
22404
|
+
inline constexpr gea::HostFunction<double(double), &detail::log10_invoke> log10{};
|
|
22357
22405
|
#endif
|
|
22358
22406
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22359
22407
|
extern const gea::CallableObject<double(double)> log1p;
|
|
22360
22408
|
#else
|
|
22361
|
-
inline
|
|
22409
|
+
inline constexpr gea::HostFunction<double(double), &detail::log1p_invoke> log1p{};
|
|
22362
22410
|
#endif
|
|
22363
22411
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22364
22412
|
extern const gea::CallableObject<double(double)> log2;
|
|
22365
22413
|
#else
|
|
22366
|
-
inline
|
|
22414
|
+
inline constexpr gea::HostFunction<double(double), &detail::log2_invoke> log2{};
|
|
22367
22415
|
#endif
|
|
22368
22416
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22369
22417
|
extern const gea::CallableObject<double(double)> cosh;
|
|
22370
22418
|
#else
|
|
22371
|
-
inline
|
|
22419
|
+
inline constexpr gea::HostFunction<double(double), &detail::cosh_invoke> cosh{};
|
|
22372
22420
|
#endif
|
|
22373
22421
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22374
22422
|
extern const gea::CallableObject<double(double)> tanh;
|
|
22375
22423
|
#else
|
|
22376
|
-
inline
|
|
22424
|
+
inline constexpr gea::HostFunction<double(double), &detail::tanh_invoke> tanh{};
|
|
22377
22425
|
#endif
|
|
22378
22426
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22379
22427
|
extern const gea::CallableObject<double(double)> acosh;
|
|
22380
22428
|
#else
|
|
22381
|
-
inline
|
|
22429
|
+
inline constexpr gea::HostFunction<double(double), &detail::acosh_invoke> acosh{};
|
|
22382
22430
|
#endif
|
|
22383
22431
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22384
22432
|
extern const gea::CallableObject<double(double)> asinh;
|
|
22385
22433
|
#else
|
|
22386
|
-
inline
|
|
22434
|
+
inline constexpr gea::HostFunction<double(double), &detail::asinh_invoke> asinh{};
|
|
22387
22435
|
#endif
|
|
22388
22436
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22389
22437
|
extern const gea::CallableObject<double(double)> atanh;
|
|
22390
22438
|
#else
|
|
22391
|
-
inline
|
|
22439
|
+
inline constexpr gea::HostFunction<double(double), &detail::atanh_invoke> atanh{};
|
|
22392
22440
|
#endif
|
|
22393
22441
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22394
22442
|
extern const gea::CallableObject<double(double)> fround;
|
|
22395
22443
|
#else
|
|
22396
|
-
inline
|
|
22444
|
+
inline constexpr gea::HostFunction<double(double), &detail::fround_invoke> fround{};
|
|
22397
22445
|
#endif
|
|
22398
22446
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22399
22447
|
extern const gea::CallableObject<double(double)> clz32;
|
|
22400
22448
|
#else
|
|
22401
|
-
inline
|
|
22449
|
+
inline constexpr gea::HostFunction<double(double), &detail::clz32_invoke> clz32{};
|
|
22402
22450
|
#endif
|
|
22403
22451
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22404
22452
|
extern const gea::CallableObject<double(double, double)> imul;
|
|
22405
22453
|
#else
|
|
22406
|
-
inline
|
|
22454
|
+
inline constexpr gea::HostFunction<double(double, double), &detail::imul_invoke> imul{};
|
|
22407
22455
|
#endif
|
|
22408
22456
|
|
|
22409
22457
|
/** `readonly PI: number` -- a data property, not a method; no `CallableObject`. */
|
|
@@ -22698,7 +22746,7 @@ inline double now_invoke(void*) {
|
|
|
22698
22746
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22699
22747
|
extern const gea::CallableObject<double()> now;
|
|
22700
22748
|
#else
|
|
22701
|
-
inline
|
|
22749
|
+
inline constexpr gea::HostFunction<double(), &detail::now_invoke> now{};
|
|
22702
22750
|
#endif
|
|
22703
22751
|
|
|
22704
22752
|
} // namespace DateConstructor
|
|
@@ -22722,7 +22770,7 @@ inline std::string fromCharCode_invoke(void*, gea::Ref<gea::ArrayObject<double>>
|
|
|
22722
22770
|
#if defined(GEA_CPP_SHARED_RUNTIME_BUILTINS)
|
|
22723
22771
|
extern const gea::CallableObject<std::string(gea::Ref<gea::ArrayObject<double>>)> fromCharCode;
|
|
22724
22772
|
#else
|
|
22725
|
-
inline
|
|
22773
|
+
inline constexpr gea::HostFunction<std::string(gea::Ref<gea::ArrayObject<double>>), &detail::fromCharCode_invoke> fromCharCode{};
|
|
22726
22774
|
#endif
|
|
22727
22775
|
|
|
22728
22776
|
} // namespace StringConstructor
|
|
@@ -25126,9 +25174,10 @@ bool isDocumentLevelEvent(const Node& node, const std::string& name) {
|
|
|
25126
25174
|
* is gated on the node's live token instead -- a rebuilt subtree leaves an
|
|
25127
25175
|
* inert closure behind rather than a second generation of the handler.
|
|
25128
25176
|
*
|
|
25129
|
-
*
|
|
25177
|
+
* Bubbling events are delegated to the BODY and gated by `containsNode`; see
|
|
25130
25178
|
* the no-argument `addNodeListener` for why, and `recordNodeSubscription` for
|
|
25131
|
-
* how it is released with the node.
|
|
25179
|
+
* how it is released with the node. Scroll stays on its target because it does
|
|
25180
|
+
* not bubble.
|
|
25132
25181
|
*/
|
|
25133
25182
|
template <typename Node, typename Invoke>
|
|
25134
25183
|
void bindNodeListener(Node& node, const std::string& name, Invoke invoke) {
|
|
@@ -25155,6 +25204,10 @@ void bindNodeListener(Node& node, const std::string& name, Invoke invoke) {
|
|
|
25155
25204
|
});
|
|
25156
25205
|
return;
|
|
25157
25206
|
}
|
|
25207
|
+
if (name == "scroll") {
|
|
25208
|
+
target.addEventListener(name.c_str(), std::move(run));
|
|
25209
|
+
return;
|
|
25210
|
+
}
|
|
25158
25211
|
const auto listenerId = gea::embedded::ui::Document::instance().body().addEventListener(
|
|
25159
25212
|
name.c_str(), [target, run](gea::framework::events::PointerEvent& event) mutable {
|
|
25160
25213
|
if (!gea::embedded::ui::Tree::instance().containsNode(target.id(), event.targetId)) return;
|
|
@@ -27215,15 +27268,15 @@ inline std::size_t jsonEscapeScan(const char* data, std::size_t size, std::size_
|
|
|
27215
27268
|
}
|
|
27216
27269
|
|
|
27217
27270
|
/**
|
|
27218
|
-
* The READER's scan:
|
|
27271
|
+
* The READER's scan: the same three stops as the writer's.
|
|
27219
27272
|
*
|
|
27220
|
-
* A control character inside a quoted string is malformed JSON (RFC 8259 7
|
|
27221
|
-
*
|
|
27222
|
-
*
|
|
27223
|
-
*
|
|
27273
|
+
* A control character inside a quoted string is malformed JSON (RFC 8259 7,
|
|
27274
|
+
* ECMA-262 25.5.1's `JSONString` grammar), so it must end the run exactly as
|
|
27275
|
+
* a quote or an escape lead does -- the caller then throws on it. This reader
|
|
27276
|
+
* used to copy one through, which answered a document `JSON.parse` rejects.
|
|
27224
27277
|
*/
|
|
27225
27278
|
inline std::size_t jsonStringScan(const char* data, std::size_t size, std::size_t from) {
|
|
27226
|
-
return detail::jsonScan<
|
|
27279
|
+
return detail::jsonScan<true>(data, size, from);
|
|
27227
27280
|
}
|
|
27228
27281
|
|
|
27229
27282
|
/**
|
|
@@ -27234,30 +27287,24 @@ inline std::size_t jsonStringScan(const char* data, std::size_t size, std::size_
|
|
|
27234
27287
|
*
|
|
27235
27288
|
* v1 (`compiler/packages/geatsc/src/targets/cpp/runtime/json_reader.h`) is
|
|
27236
27289
|
* the prior art for a typed, non-boxing `JSON.parse(...) as T` decoder, and
|
|
27237
|
-
*
|
|
27238
|
-
* match `T` -- an extra key, a string where `T` declares a number
|
|
27239
|
-
*
|
|
27240
|
-
*
|
|
27241
|
-
*
|
|
27242
|
-
*
|
|
27243
|
-
*
|
|
27244
|
-
*
|
|
27245
|
-
*
|
|
27246
|
-
*
|
|
27247
|
-
*
|
|
27248
|
-
*
|
|
27249
|
-
*
|
|
27250
|
-
*
|
|
27251
|
-
*
|
|
27252
|
-
*
|
|
27253
|
-
*
|
|
27254
|
-
*
|
|
27255
|
-
* next key after a mismatched value; this stops the whole parse instead),
|
|
27256
|
-
* traded deliberately for a design whose termination is provable by
|
|
27257
|
-
* inspection without executing the compiled reader -- this port's harness is
|
|
27258
|
-
* restricted to `-fsyntax-only` and must not run generated binaries. Every
|
|
27259
|
-
* loop below only ever advances `pos_` or reads `truncated()` and returns;
|
|
27260
|
-
* `truncate()` snaps `pos_` to `text_.size()`, so nothing can spin.
|
|
27290
|
+
* one of its choices is kept: a well-formed document whose SHAPE does not
|
|
27291
|
+
* match `T` -- an extra key, a string where `T` declares a number -- is not an
|
|
27292
|
+
* error. The mismatched value is skipped (`skipValue`) and the field keeps its
|
|
27293
|
+
* default. That is this backend's own answer, because ECMA-262's `JSON.parse`
|
|
27294
|
+
* has no `T` to mismatch.
|
|
27295
|
+
*
|
|
27296
|
+
* Text that is not JSON at all is a different question, and ECMA-262 25.5.1
|
|
27297
|
+
* step 2 answers it: a catchable `SyntaxError`. Every grammar violation below
|
|
27298
|
+
* -- an unterminated container, a missing `:` or `,`, a bad literal, number,
|
|
27299
|
+
* escape or control character, trailing text after the root (`finish`) --
|
|
27300
|
+
* goes through `malformed`, which throws exactly that. The reader used to
|
|
27301
|
+
* stop silently at the first one instead and hand back whatever it had read
|
|
27302
|
+
* (`JSON.parse('')` was an empty record): a silently wrong answer, which is
|
|
27303
|
+
* worse than either throwing or refusing to compile.
|
|
27304
|
+
*
|
|
27305
|
+
* Termination: every loop below either advances `pos_` or throws, and the
|
|
27306
|
+
* buffer's NUL terminator opens no token, so the end of the text always ends
|
|
27307
|
+
* a scan.
|
|
27261
27308
|
*/
|
|
27262
27309
|
class Reader {
|
|
27263
27310
|
public:
|
|
@@ -27274,9 +27321,16 @@ class Reader {
|
|
|
27274
27321
|
*/
|
|
27275
27322
|
explicit Reader(const std::string& text) : text_(text), data_(text.data()), size_(text.size()), pos_(0) {}
|
|
27276
27323
|
|
|
27277
|
-
|
|
27324
|
+
/** ECMA-262 25.5.1 step 2: text that is not valid JSON throws a `SyntaxError`. The message follows V8's shape, position included. */
|
|
27325
|
+
[[noreturn]] void malformed(const char* what) const {
|
|
27326
|
+
gea::host::throwRuntimeError("SyntaxError", std::string(what) + " in JSON at position " + std::to_string(pos_));
|
|
27327
|
+
}
|
|
27278
27328
|
|
|
27279
|
-
|
|
27329
|
+
/** The text after the root value may only be whitespace (the grammar's whole `JSONText` is one value). */
|
|
27330
|
+
void finish() {
|
|
27331
|
+
skipWhitespace();
|
|
27332
|
+
if (pos_ < size_) malformed("Unexpected non-whitespace character after JSON");
|
|
27333
|
+
}
|
|
27280
27334
|
|
|
27281
27335
|
void skipWhitespace() {
|
|
27282
27336
|
// Every JSON whitespace byte is at or below 0x20, and every byte that can
|
|
@@ -27295,7 +27349,7 @@ class Reader {
|
|
|
27295
27349
|
}
|
|
27296
27350
|
}
|
|
27297
27351
|
|
|
27298
|
-
/** Skips leading whitespace and returns the byte at the cursor, or `'\0'` past the end of the text -- `'\0'`
|
|
27352
|
+
/** Skips leading whitespace and returns the byte at the cursor, or `'\0'` past the end of the text -- `'\0'` opens no JSON token, so every caller below reads it as "nothing usable is here" without a separate bound test. */
|
|
27299
27353
|
char peek() {
|
|
27300
27354
|
skipWhitespace();
|
|
27301
27355
|
// No bound test: `std::string::data()` is NUL-terminated, so the byte at
|
|
@@ -27353,17 +27407,11 @@ class Reader {
|
|
|
27353
27407
|
return true;
|
|
27354
27408
|
}
|
|
27355
27409
|
|
|
27356
|
-
/** Reads the next property key and consumes the following `:`, leaving the cursor at the value.
|
|
27410
|
+
/** Reads the next property key and consumes the following `:`, leaving the cursor at the value. Anything other than a quoted key and its colon is malformed; the `bool` is always `true` and kept so the generated key loop reads the same either way. */
|
|
27357
27411
|
bool nextKey(std::string& key) {
|
|
27358
|
-
if (peek() != '"')
|
|
27359
|
-
truncate();
|
|
27360
|
-
return false;
|
|
27361
|
-
}
|
|
27412
|
+
if (peek() != '"') malformed("Expected double-quoted property name");
|
|
27362
27413
|
readStringField(key);
|
|
27363
|
-
if (!consumeIf(':'))
|
|
27364
|
-
truncate();
|
|
27365
|
-
return false;
|
|
27366
|
-
}
|
|
27414
|
+
if (!consumeIf(':')) malformed("Expected ':' after property name");
|
|
27367
27415
|
return true;
|
|
27368
27416
|
}
|
|
27369
27417
|
|
|
@@ -27407,10 +27455,7 @@ class Reader {
|
|
|
27407
27455
|
* of the read -- `Reader` holds the text by reference already.
|
|
27408
27456
|
*/
|
|
27409
27457
|
bool nextKey(std::string_view& key, std::string& scratch) {
|
|
27410
|
-
if (peek() != '"')
|
|
27411
|
-
truncate();
|
|
27412
|
-
return false;
|
|
27413
|
-
}
|
|
27458
|
+
if (peek() != '"') malformed("Expected double-quoted property name");
|
|
27414
27459
|
const std::size_t opened = pos_ + 1;
|
|
27415
27460
|
const std::size_t stop = jsonStringScan(data_, size_, opened);
|
|
27416
27461
|
if (stop < size_ && data_[stop] == '"') {
|
|
@@ -27420,16 +27465,14 @@ class Reader {
|
|
|
27420
27465
|
readStringField(scratch);
|
|
27421
27466
|
key = scratch;
|
|
27422
27467
|
}
|
|
27423
|
-
if (!consumeIf(':'))
|
|
27424
|
-
truncate();
|
|
27425
|
-
return false;
|
|
27426
|
-
}
|
|
27468
|
+
if (!consumeIf(':')) malformed("Expected ':' after property name");
|
|
27427
27469
|
return true;
|
|
27428
27470
|
}
|
|
27429
27471
|
|
|
27430
27472
|
/**
|
|
27431
27473
|
* Consumes the separator after a field value: `,` (more keys follow) or
|
|
27432
|
-
* `}
|
|
27474
|
+
* `}` (the object ends). Anything else -- the end of the text included --
|
|
27475
|
+
* is an unterminated object.
|
|
27433
27476
|
*
|
|
27434
27477
|
* The byte is read ONCE. Spelled as `consumeIf(',')` then `consumeIf('}')` it
|
|
27435
27478
|
* was two `peek`s -- two whitespace skips and two bounds checks -- for the one
|
|
@@ -27442,11 +27485,12 @@ class Reader {
|
|
|
27442
27485
|
++pos_;
|
|
27443
27486
|
return true;
|
|
27444
27487
|
}
|
|
27445
|
-
if (c
|
|
27488
|
+
if (c != '}') malformed("Expected ',' or '}' after property value");
|
|
27489
|
+
++pos_;
|
|
27446
27490
|
return false;
|
|
27447
27491
|
}
|
|
27448
27492
|
|
|
27449
|
-
/** The same, for an ARRAY element: `,` (more follow) or `]
|
|
27493
|
+
/** The same, for an ARRAY element: `,` (more follow) or `]` (the array ends). */
|
|
27450
27494
|
bool advanceArray() {
|
|
27451
27495
|
skipWhitespace();
|
|
27452
27496
|
const char c = data_[pos_];
|
|
@@ -27454,7 +27498,8 @@ class Reader {
|
|
|
27454
27498
|
++pos_;
|
|
27455
27499
|
return true;
|
|
27456
27500
|
}
|
|
27457
|
-
if (c
|
|
27501
|
+
if (c != ']') malformed("Expected ',' or ']' after array element");
|
|
27502
|
+
++pos_;
|
|
27458
27503
|
return false;
|
|
27459
27504
|
}
|
|
27460
27505
|
|
|
@@ -27465,11 +27510,15 @@ class Reader {
|
|
|
27465
27510
|
skipValue();
|
|
27466
27511
|
return std::numeric_limits<double>::quiet_NaN();
|
|
27467
27512
|
}
|
|
27513
|
+
// `+` and `.` open no JSON number (RFC 8259 6), but they are admitted by
|
|
27514
|
+
// the test above so that the error names the number rather than calling
|
|
27515
|
+
// the byte a mismatched shape.
|
|
27516
|
+
if (c == '+' || c == '.') malformed("Unexpected token in JSON number");
|
|
27468
27517
|
const std::size_t start = pos_;
|
|
27469
27518
|
// `peek()` already read this byte and proved it opens a number, so the sign
|
|
27470
27519
|
// is decided from `c` rather than loaded and bounds-checked again.
|
|
27471
27520
|
const bool negative = c == '-';
|
|
27472
|
-
if (negative
|
|
27521
|
+
if (negative) ++pos_;
|
|
27473
27522
|
// The digits are accumulated during the SAME scan that finds the token's
|
|
27474
27523
|
// end, so a plain integer -- the overwhelmingly common JSON number -- is
|
|
27475
27524
|
// answered here and never reaches `std::from_chars`, which is a general
|
|
@@ -27491,30 +27540,26 @@ class Reader {
|
|
|
27491
27540
|
++pos_;
|
|
27492
27541
|
}
|
|
27493
27542
|
const std::size_t digits = pos_ - digitsAt;
|
|
27543
|
+
// The integer part is `0` or a digit run with no leading zero: `-`, `-.5`
|
|
27544
|
+
// and `01` are all malformed.
|
|
27545
|
+
if (digits == 0) malformed("No number after minus sign");
|
|
27546
|
+
if (digits > 1 && data_[digitsAt] == '0') malformed("Unexpected number");
|
|
27494
27547
|
const char next = data_[pos_];
|
|
27495
|
-
if (digits
|
|
27548
|
+
if (digits <= 19 && next != '.' && next != 'e' && next != 'E')
|
|
27496
27549
|
return negative ? -static_cast<double>(whole) : static_cast<double>(whole);
|
|
27497
|
-
|
|
27550
|
+
// A fraction and an exponent each need at least one digit of their own.
|
|
27551
|
+
if (data_[pos_] == '.') {
|
|
27498
27552
|
++pos_;
|
|
27499
|
-
|
|
27553
|
+
const std::size_t fraction = pos_;
|
|
27554
|
+
while (data_[pos_] >= '0' && data_[pos_] <= '9') ++pos_;
|
|
27555
|
+
if (pos_ == fraction) malformed("Unterminated fractional number");
|
|
27500
27556
|
}
|
|
27501
|
-
if (
|
|
27557
|
+
if (data_[pos_] == 'e' || data_[pos_] == 'E') {
|
|
27502
27558
|
++pos_;
|
|
27503
|
-
if (
|
|
27504
|
-
|
|
27505
|
-
|
|
27506
|
-
|
|
27507
|
-
// `-+.<digit>`, and the sign-check or the dot-check right below it
|
|
27508
|
-
// therefore always advances `pos_` by at least one byte. Kept as a
|
|
27509
|
-
// `assert`-free defensive floor rather than a recursive call back into
|
|
27510
|
-
// `skipValue()` -- a construct this method must never contain, since
|
|
27511
|
-
// `skipValue()`'s own number branch is what calls `readNumberField()` in
|
|
27512
|
-
// the first place, and a `skipValue()` <-> `readNumberField()` cycle
|
|
27513
|
-
// would defeat the single-direction progress argument every other loop
|
|
27514
|
-
// in this class relies on.
|
|
27515
|
-
if (pos_ == start) {
|
|
27516
|
-
truncate(); // defensive floor for the "unreachable" case above: never leave `pos_` unmoved
|
|
27517
|
-
return std::numeric_limits<double>::quiet_NaN();
|
|
27559
|
+
if (data_[pos_] == '+' || data_[pos_] == '-') ++pos_;
|
|
27560
|
+
const std::size_t exponent = pos_;
|
|
27561
|
+
while (data_[pos_] >= '0' && data_[pos_] <= '9') ++pos_;
|
|
27562
|
+
if (pos_ == exponent) malformed("Exponent part is missing a number");
|
|
27518
27563
|
}
|
|
27519
27564
|
// `std::from_chars` rather than `strtod` WHERE IT EXISTS: the same
|
|
27520
27565
|
// shortest-round-trip answer, decided by an integer algorithm instead of a
|
|
@@ -27525,13 +27570,10 @@ class Reader {
|
|
|
27525
27570
|
// integer fast path above, it is now the rare shape either way.
|
|
27526
27571
|
// `strtod` was 54ns of the 54ns `json_parse_number_array` spent per number.
|
|
27527
27572
|
//
|
|
27528
|
-
//
|
|
27529
|
-
//
|
|
27530
|
-
// token `strtod` would parse further than the scan did. The first is
|
|
27531
|
-
// stepped over; anything the parse does not consume WHOLE falls back, so
|
|
27532
|
-
// no input answers differently than it did.
|
|
27573
|
+
// The token is grammatical by now, so both parse it whole; `from_chars`
|
|
27574
|
+
// is still checked for that and falls back rather than trusted.
|
|
27533
27575
|
#if GEA_JSON_HAS_FROM_CHARS_DOUBLE
|
|
27534
|
-
const char* const first = data_ + start
|
|
27576
|
+
const char* const first = data_ + start;
|
|
27535
27577
|
const char* const last = data_ + pos_;
|
|
27536
27578
|
double parsed = 0;
|
|
27537
27579
|
const auto answer = std::from_chars(first, last, parsed);
|
|
@@ -27596,8 +27638,9 @@ class Reader {
|
|
|
27596
27638
|
}
|
|
27597
27639
|
|
|
27598
27640
|
/**
|
|
27599
|
-
* The rest of a string that turned out to carry an escape
|
|
27600
|
-
*
|
|
27641
|
+
* The rest of a string that turned out to carry an escape (or a control
|
|
27642
|
+
* character, or no closing quote), resumed with the cursor on the byte the
|
|
27643
|
+
* scan stopped at. Kept out of
|
|
27601
27644
|
* line: the `\uXXXX` decoder alone is bigger than everything above it, and a
|
|
27602
27645
|
* document that never uses one should not carry it through every call.
|
|
27603
27646
|
*/
|
|
@@ -27614,21 +27657,17 @@ class Reader {
|
|
|
27614
27657
|
// appends reallocates and copies O(log length) times. A JSON string
|
|
27615
27658
|
// containing no escape at all -- the overwhelmingly common shape -- now
|
|
27616
27659
|
// costs exactly one allocation and one `memcpy`. Correctness is unchanged
|
|
27617
|
-
// because the scan stops at
|
|
27618
|
-
//
|
|
27619
|
-
//
|
|
27620
|
-
|
|
27621
|
-
// rather than rejected.
|
|
27622
|
-
if (pos_ >= size_) {
|
|
27623
|
-
truncate();
|
|
27624
|
-
return;
|
|
27625
|
-
}
|
|
27660
|
+
// because the scan stops at every byte the loop below distinguishes: the
|
|
27661
|
+
// closing quote, the escape lead, and a control character the grammar
|
|
27662
|
+
// forbids (RFC 8259 7).
|
|
27663
|
+
if (pos_ >= size_) malformed("Unterminated string");
|
|
27626
27664
|
const char c = data_[pos_++];
|
|
27627
27665
|
if (c == '"') return;
|
|
27628
|
-
if (
|
|
27629
|
-
|
|
27630
|
-
|
|
27666
|
+
if (c != '\\') {
|
|
27667
|
+
--pos_;
|
|
27668
|
+
malformed("Bad control character in string literal");
|
|
27631
27669
|
}
|
|
27670
|
+
if (pos_ >= size_) malformed("Unterminated string");
|
|
27632
27671
|
const char escape = data_[pos_++];
|
|
27633
27672
|
switch (escape) {
|
|
27634
27673
|
case '"': out += '"'; break;
|
|
@@ -27640,10 +27679,7 @@ class Reader {
|
|
|
27640
27679
|
case 'r': out += '\r'; break;
|
|
27641
27680
|
case 't': out += '\t'; break;
|
|
27642
27681
|
case 'u': {
|
|
27643
|
-
if (pos_ + 4 > size_)
|
|
27644
|
-
truncate();
|
|
27645
|
-
return;
|
|
27646
|
-
}
|
|
27682
|
+
if (pos_ + 4 > size_) malformed("Bad Unicode escape");
|
|
27647
27683
|
unsigned code = 0;
|
|
27648
27684
|
bool validHex = true;
|
|
27649
27685
|
for (int digit = 0; digit < 4; ++digit) {
|
|
@@ -27654,10 +27690,7 @@ class Reader {
|
|
|
27654
27690
|
else if (h >= 'A' && h <= 'F') code |= static_cast<unsigned>(h - 'A' + 10);
|
|
27655
27691
|
else validHex = false;
|
|
27656
27692
|
}
|
|
27657
|
-
if (!validHex)
|
|
27658
|
-
truncate();
|
|
27659
|
-
return;
|
|
27660
|
-
}
|
|
27693
|
+
if (!validHex) malformed("Bad Unicode escape");
|
|
27661
27694
|
// UTF-8 encode the code point. A surrogate pair (an astral
|
|
27662
27695
|
// character split across two `\uXXXX` escapes) is not reassembled
|
|
27663
27696
|
// -- no corpus document this backend parses has one -- so each
|
|
@@ -27675,8 +27708,8 @@ class Reader {
|
|
|
27675
27708
|
break;
|
|
27676
27709
|
}
|
|
27677
27710
|
default:
|
|
27678
|
-
|
|
27679
|
-
|
|
27711
|
+
--pos_;
|
|
27712
|
+
malformed("Bad escaped character");
|
|
27680
27713
|
}
|
|
27681
27714
|
const std::size_t run = pos_;
|
|
27682
27715
|
pos_ = jsonStringScan(data_, size_, pos_);
|
|
@@ -27700,49 +27733,46 @@ class Reader {
|
|
|
27700
27733
|
++pos_;
|
|
27701
27734
|
for (;;) {
|
|
27702
27735
|
pos_ = jsonStringScan(data_, size_, pos_);
|
|
27703
|
-
if (pos_ >= size_)
|
|
27704
|
-
|
|
27705
|
-
|
|
27706
|
-
}
|
|
27707
|
-
if (data_[pos_] == '"') {
|
|
27736
|
+
if (pos_ >= size_) malformed("Unterminated string");
|
|
27737
|
+
const char c = data_[pos_];
|
|
27738
|
+
if (c == '"') {
|
|
27708
27739
|
++pos_;
|
|
27709
27740
|
return;
|
|
27710
27741
|
}
|
|
27711
|
-
|
|
27712
|
-
|
|
27713
|
-
|
|
27714
|
-
|
|
27742
|
+
if (c != '\\') malformed("Bad control character in string literal");
|
|
27743
|
+
// A skipped string is still part of the document, so its escapes are
|
|
27744
|
+
// held to the same grammar as a decoded one's.
|
|
27745
|
+
const char escape = data_[pos_ + 1];
|
|
27746
|
+
if (escape == 'u') {
|
|
27747
|
+
for (std::size_t digit = 2; digit < 6; ++digit) {
|
|
27748
|
+
const char h = pos_ + digit < size_ ? data_[pos_ + digit] : '\0';
|
|
27749
|
+
if (!((h >= '0' && h <= '9') || (h >= 'a' && h <= 'f') || (h >= 'A' && h <= 'F'))) malformed("Bad Unicode escape");
|
|
27750
|
+
}
|
|
27751
|
+
pos_ += 6;
|
|
27752
|
+
continue;
|
|
27715
27753
|
}
|
|
27754
|
+
if (escape != '"' && escape != '\\' && escape != '/' && escape != 'b' && escape != 'f' && escape != 'n' && escape != 'r' &&
|
|
27755
|
+
escape != 't')
|
|
27756
|
+
malformed("Bad escaped character");
|
|
27757
|
+
pos_ += 2;
|
|
27716
27758
|
}
|
|
27717
27759
|
}
|
|
27718
27760
|
|
|
27719
|
-
/** Skips one well-formed JSON value this program's declared shape does not name -- an object key nothing here reads, or the wrong-shaped value behind a field whose static type doesn't match what's actually in the document (ECMA-262's own `JSON.parse` skips nothing at all; a `T` narrower than the document, and refusing a mismatch rather than coercing it, are this backend's own choices -- see `emit-json.ts`'s top comment). Every branch either consumes at least one byte or
|
|
27761
|
+
/** Skips one well-formed JSON value this program's declared shape does not name -- an object key nothing here reads, or the wrong-shaped value behind a field whose static type doesn't match what's actually in the document (ECMA-262's own `JSON.parse` skips nothing at all; a `T` narrower than the document, and refusing a mismatch rather than coercing it, are this backend's own choices -- see `emit-json.ts`'s top comment). Text that is not a JSON value at all is malformed. Every branch either consumes at least one byte or throws, so this always terminates even on adversarial input. */
|
|
27720
27762
|
void skipValue() {
|
|
27721
27763
|
const char c = peek();
|
|
27722
|
-
if (c == '\0')
|
|
27723
|
-
truncate();
|
|
27724
|
-
return;
|
|
27725
|
-
}
|
|
27764
|
+
if (c == '\0') malformed("Unexpected end of JSON input");
|
|
27726
27765
|
if (c == '"') {
|
|
27727
27766
|
skipString();
|
|
27728
27767
|
} else if (c == '{') {
|
|
27729
27768
|
++pos_;
|
|
27730
27769
|
if (!consumeIf('}')) {
|
|
27731
27770
|
for (;;) {
|
|
27732
|
-
if (peek() != '"')
|
|
27733
|
-
truncate();
|
|
27734
|
-
break;
|
|
27735
|
-
}
|
|
27771
|
+
if (peek() != '"') malformed("Expected double-quoted property name");
|
|
27736
27772
|
skipString();
|
|
27737
|
-
if (!consumeIf(':'))
|
|
27738
|
-
truncate();
|
|
27739
|
-
break;
|
|
27740
|
-
}
|
|
27773
|
+
if (!consumeIf(':')) malformed("Expected ':' after property name");
|
|
27741
27774
|
skipValue();
|
|
27742
|
-
if (
|
|
27743
|
-
if (consumeIf(',')) continue;
|
|
27744
|
-
consumeIf('}');
|
|
27745
|
-
break;
|
|
27775
|
+
if (!advance()) break;
|
|
27746
27776
|
}
|
|
27747
27777
|
}
|
|
27748
27778
|
} else if (c == '[') {
|
|
@@ -27750,29 +27780,22 @@ class Reader {
|
|
|
27750
27780
|
if (!consumeIf(']')) {
|
|
27751
27781
|
for (;;) {
|
|
27752
27782
|
skipValue();
|
|
27753
|
-
if (
|
|
27754
|
-
if (consumeIf(',')) continue;
|
|
27755
|
-
consumeIf(']');
|
|
27756
|
-
break;
|
|
27783
|
+
if (!advanceArray()) break;
|
|
27757
27784
|
}
|
|
27758
27785
|
}
|
|
27759
27786
|
} else if (c == 't') {
|
|
27760
|
-
if (!consumeLiteral("true", 4))
|
|
27787
|
+
if (!consumeLiteral("true", 4)) malformed("Unexpected token");
|
|
27761
27788
|
} else if (c == 'f') {
|
|
27762
|
-
if (!consumeLiteral("false", 5))
|
|
27789
|
+
if (!consumeLiteral("false", 5)) malformed("Unexpected token");
|
|
27763
27790
|
} else if (c == 'n') {
|
|
27764
|
-
if (!consumeLiteral("null", 4))
|
|
27791
|
+
if (!consumeLiteral("null", 4)) malformed("Unexpected token");
|
|
27765
27792
|
} else if (c == '-' || c == '+' || c == '.' || (c >= '0' && c <= '9')) {
|
|
27766
|
-
|
|
27793
|
+
// Never a mismatch here: `readNumberField` either consumes a whole
|
|
27794
|
+
// grammatical number or throws, so it cannot hand the same byte back.
|
|
27767
27795
|
readNumberField();
|
|
27768
|
-
if (pos_ == start) truncate(); // readNumberField saw digits at peek() but somehow consumed none: give up cleanly rather than loop
|
|
27769
27796
|
} else {
|
|
27770
|
-
// A byte that opens no JSON value at all
|
|
27771
|
-
|
|
27772
|
-
// on the same byte -- is what keeps every caller above provably
|
|
27773
|
-
// terminating.
|
|
27774
|
-
++pos_;
|
|
27775
|
-
truncate();
|
|
27797
|
+
// A byte that opens no JSON value at all.
|
|
27798
|
+
malformed("Unexpected token");
|
|
27776
27799
|
}
|
|
27777
27800
|
}
|
|
27778
27801
|
|
|
@@ -27781,15 +27804,15 @@ class Reader {
|
|
|
27781
27804
|
const char c = peek();
|
|
27782
27805
|
if (c == '"') return gea::Value::box(gea::Value::Tag::String, readStringField());
|
|
27783
27806
|
if (c == 't') {
|
|
27784
|
-
if (!consumeLiteral("true", 4))
|
|
27807
|
+
if (!consumeLiteral("true", 4)) malformed("Unexpected token");
|
|
27785
27808
|
return gea::Value::box(gea::Value::Tag::Boolean, true);
|
|
27786
27809
|
}
|
|
27787
27810
|
if (c == 'f') {
|
|
27788
|
-
if (!consumeLiteral("false", 5))
|
|
27811
|
+
if (!consumeLiteral("false", 5)) malformed("Unexpected token");
|
|
27789
27812
|
return gea::Value::box(gea::Value::Tag::Boolean, false);
|
|
27790
27813
|
}
|
|
27791
27814
|
if (c == 'n') {
|
|
27792
|
-
if (!consumeLiteral("null", 4))
|
|
27815
|
+
if (!consumeLiteral("null", 4)) malformed("Unexpected token");
|
|
27793
27816
|
return gea::Value::box(gea::Value::Tag::Null, static_cast<std::nullptr_t>(nullptr));
|
|
27794
27817
|
}
|
|
27795
27818
|
if (c == '[') {
|
|
@@ -27798,7 +27821,7 @@ class Reader {
|
|
|
27798
27821
|
if (!consumeIf(']')) {
|
|
27799
27822
|
for (;;) {
|
|
27800
27823
|
array->push(readDynamicValue());
|
|
27801
|
-
if (
|
|
27824
|
+
if (!advanceArray()) break;
|
|
27802
27825
|
}
|
|
27803
27826
|
}
|
|
27804
27827
|
return gea::Value::box(gea::Value::Tag::Object, array);
|
|
@@ -27815,9 +27838,9 @@ class Reader {
|
|
|
27815
27838
|
if (!consumeIf('}')) {
|
|
27816
27839
|
std::string key;
|
|
27817
27840
|
for (;;) {
|
|
27818
|
-
|
|
27841
|
+
nextKey(key);
|
|
27819
27842
|
(*object)[key] = readDynamicValue();
|
|
27820
|
-
if (
|
|
27843
|
+
if (!advance()) break;
|
|
27821
27844
|
}
|
|
27822
27845
|
}
|
|
27823
27846
|
return gea::Value::box(gea::Value::Tag::Object, object);
|
|
@@ -27825,8 +27848,9 @@ class Reader {
|
|
|
27825
27848
|
if (c == '-' || c == '+' || c == '.' || (c >= '0' && c <= '9')) {
|
|
27826
27849
|
return gea::Value::box(gea::Value::Tag::Number, readNumberField());
|
|
27827
27850
|
}
|
|
27828
|
-
|
|
27829
|
-
|
|
27851
|
+
// Every token that opens a JSON value was answered above, so this is the
|
|
27852
|
+
// end of the text or a byte no value starts with.
|
|
27853
|
+
malformed(c == '\0' ? "Unexpected end of JSON input" : "Unexpected token");
|
|
27830
27854
|
}
|
|
27831
27855
|
|
|
27832
27856
|
/** The cursor, for a caller measuring what one value cost to read. See `elementCapacityEstimate`. */
|
|
@@ -28351,7 +28375,6 @@ inline void gea_json_read(gea::json::Reader& reader, gea::Ref<gea::ArrayObject<E
|
|
|
28351
28375
|
out->cells.emplace_back();
|
|
28352
28376
|
gea_json_read(reader, out->cells.back().value);
|
|
28353
28377
|
}
|
|
28354
|
-
if (reader.truncated()) return;
|
|
28355
28378
|
++seen;
|
|
28356
28379
|
if (!sized) {
|
|
28357
28380
|
const std::size_t hint = gea::json::elementCapacityEstimate(seen, reader.position() - opened, reader.remaining());
|