nodenetcdf 4.9.31 → 4.9.32
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.
- package/package.json +1 -1
- package/src/Attribute.cpp +15 -0
- package/src/Group.cpp +52 -10
- package/src/Variable.cpp +14 -4
- package/test/json.js +34 -0
package/package.json
CHANGED
package/src/Attribute.cpp
CHANGED
|
@@ -365,6 +365,21 @@ void Attribute::ToJSON(const v8::FunctionCallbackInfo<v8::Value> &args)
|
|
|
365
365
|
}
|
|
366
366
|
value = v8::Null(isolate);
|
|
367
367
|
}
|
|
368
|
+
else if (value->IsTypedArray())
|
|
369
|
+
{
|
|
370
|
+
// Convert TypedArray to regular array for JSON serialization
|
|
371
|
+
v8::Local<v8::TypedArray> typedArray = v8::Local<v8::TypedArray>::Cast(value);
|
|
372
|
+
uint32_t length = typedArray->Length();
|
|
373
|
+
v8::Local<v8::Array> array = v8::Array::New(isolate, length);
|
|
374
|
+
|
|
375
|
+
for (uint32_t i = 0; i < length; i++)
|
|
376
|
+
{
|
|
377
|
+
v8::Local<v8::Value> element = typedArray->Get(context, i).ToLocalChecked();
|
|
378
|
+
(void)array->Set(context, i, element);
|
|
379
|
+
}
|
|
380
|
+
value = array;
|
|
381
|
+
}
|
|
382
|
+
// Don't wrap primitives - only convert TypedArrays to arrays
|
|
368
383
|
|
|
369
384
|
(void)json->CreateDataProperty(context, value_str, value);
|
|
370
385
|
|
package/src/Group.cpp
CHANGED
|
@@ -525,30 +525,72 @@ void Group::ToJSON(const v8::FunctionCallbackInfo<v8::Value> &args)
|
|
|
525
525
|
}
|
|
526
526
|
}
|
|
527
527
|
|
|
528
|
-
//
|
|
529
|
-
// These will be accessed through property getters which trigger the respective Get* methods
|
|
528
|
+
// Convert dimensions object to array
|
|
530
529
|
v8::Local<v8::Value> dimensions = args.Holder()->Get(context, dimensions_str).ToLocalChecked();
|
|
531
|
-
if (dimensions->IsObject())
|
|
530
|
+
if (dimensions->IsObject() && !dimensions->IsNull())
|
|
532
531
|
{
|
|
533
|
-
|
|
532
|
+
v8::Local<v8::Object> dimsObj = dimensions->ToObject(context).ToLocalChecked();
|
|
533
|
+
v8::Local<v8::Array> propNames = dimsObj->GetOwnPropertyNames(context).ToLocalChecked();
|
|
534
|
+
v8::Local<v8::Array> dimsArray = v8::Array::New(isolate, propNames->Length());
|
|
535
|
+
|
|
536
|
+
for (uint32_t i = 0; i < propNames->Length(); i++)
|
|
537
|
+
{
|
|
538
|
+
v8::Local<v8::Value> key = propNames->Get(context, i).ToLocalChecked();
|
|
539
|
+
v8::Local<v8::Value> value = dimsObj->Get(context, key).ToLocalChecked();
|
|
540
|
+
(void)dimsArray->Set(context, i, value);
|
|
541
|
+
}
|
|
542
|
+
(void)json->CreateDataProperty(context, dimensions_str, dimsArray);
|
|
534
543
|
}
|
|
535
544
|
|
|
545
|
+
// Convert variables object to array
|
|
536
546
|
v8::Local<v8::Value> variables = args.Holder()->Get(context, variables_str).ToLocalChecked();
|
|
537
|
-
if (variables->IsObject())
|
|
547
|
+
if (variables->IsObject() && !variables->IsNull())
|
|
538
548
|
{
|
|
539
|
-
|
|
549
|
+
v8::Local<v8::Object> varsObj = variables->ToObject(context).ToLocalChecked();
|
|
550
|
+
v8::Local<v8::Array> propNames = varsObj->GetOwnPropertyNames(context).ToLocalChecked();
|
|
551
|
+
v8::Local<v8::Array> varsArray = v8::Array::New(isolate, propNames->Length());
|
|
552
|
+
|
|
553
|
+
for (uint32_t i = 0; i < propNames->Length(); i++)
|
|
554
|
+
{
|
|
555
|
+
v8::Local<v8::Value> key = propNames->Get(context, i).ToLocalChecked();
|
|
556
|
+
v8::Local<v8::Value> value = varsObj->Get(context, key).ToLocalChecked();
|
|
557
|
+
(void)varsArray->Set(context, i, value);
|
|
558
|
+
}
|
|
559
|
+
(void)json->CreateDataProperty(context, variables_str, varsArray);
|
|
540
560
|
}
|
|
541
561
|
|
|
562
|
+
// Convert attributes object to array
|
|
542
563
|
v8::Local<v8::Value> attributes = args.Holder()->Get(context, attributes_str).ToLocalChecked();
|
|
543
|
-
if (attributes->IsObject())
|
|
564
|
+
if (attributes->IsObject() && !attributes->IsNull())
|
|
544
565
|
{
|
|
545
|
-
|
|
566
|
+
v8::Local<v8::Object> attrsObj = attributes->ToObject(context).ToLocalChecked();
|
|
567
|
+
v8::Local<v8::Array> propNames = attrsObj->GetOwnPropertyNames(context).ToLocalChecked();
|
|
568
|
+
v8::Local<v8::Array> attrsArray = v8::Array::New(isolate, propNames->Length());
|
|
569
|
+
|
|
570
|
+
for (uint32_t i = 0; i < propNames->Length(); i++)
|
|
571
|
+
{
|
|
572
|
+
v8::Local<v8::Value> key = propNames->Get(context, i).ToLocalChecked();
|
|
573
|
+
v8::Local<v8::Value> value = attrsObj->Get(context, key).ToLocalChecked();
|
|
574
|
+
(void)attrsArray->Set(context, i, value);
|
|
575
|
+
}
|
|
576
|
+
(void)json->CreateDataProperty(context, attributes_str, attrsArray);
|
|
546
577
|
}
|
|
547
578
|
|
|
579
|
+
// Convert subgroups object to array
|
|
548
580
|
v8::Local<v8::Value> subgroups = args.Holder()->Get(context, subgroups_str).ToLocalChecked();
|
|
549
|
-
if (subgroups->IsObject())
|
|
581
|
+
if (subgroups->IsObject() && !subgroups->IsNull())
|
|
550
582
|
{
|
|
551
|
-
|
|
583
|
+
v8::Local<v8::Object> subgrpsObj = subgroups->ToObject(context).ToLocalChecked();
|
|
584
|
+
v8::Local<v8::Array> propNames = subgrpsObj->GetOwnPropertyNames(context).ToLocalChecked();
|
|
585
|
+
v8::Local<v8::Array> subgrpsArray = v8::Array::New(isolate, propNames->Length());
|
|
586
|
+
|
|
587
|
+
for (uint32_t i = 0; i < propNames->Length(); i++)
|
|
588
|
+
{
|
|
589
|
+
v8::Local<v8::Value> key = propNames->Get(context, i).ToLocalChecked();
|
|
590
|
+
v8::Local<v8::Value> value = subgrpsObj->Get(context, key).ToLocalChecked();
|
|
591
|
+
(void)subgrpsArray->Set(context, i, value);
|
|
592
|
+
}
|
|
593
|
+
(void)json->CreateDataProperty(context, subgroups_str, subgrpsArray);
|
|
552
594
|
}
|
|
553
595
|
|
|
554
596
|
args.GetReturnValue().Set(json);
|
package/src/Variable.cpp
CHANGED
|
@@ -1383,18 +1383,28 @@ void Variable::ToJSON(const v8::FunctionCallbackInfo<v8::Value> &args)
|
|
|
1383
1383
|
(void)json->CreateDataProperty(context, type_str,
|
|
1384
1384
|
v8::String::NewFromUtf8(isolate, type_name, v8::NewStringType::kInternalized).ToLocalChecked());
|
|
1385
1385
|
|
|
1386
|
-
//
|
|
1386
|
+
// Dimensions are already an array, just add them
|
|
1387
1387
|
v8::Local<v8::Value> dimensions = args.Holder()->Get(context, dimensions_str).ToLocalChecked();
|
|
1388
1388
|
if (dimensions->IsArray())
|
|
1389
1389
|
{
|
|
1390
1390
|
(void)json->CreateDataProperty(context, dimensions_str, dimensions);
|
|
1391
1391
|
}
|
|
1392
1392
|
|
|
1393
|
-
//
|
|
1393
|
+
// Convert attributes object to array
|
|
1394
1394
|
v8::Local<v8::Value> attributes = args.Holder()->Get(context, attributes_str).ToLocalChecked();
|
|
1395
|
-
if (attributes->IsObject())
|
|
1395
|
+
if (attributes->IsObject() && !attributes->IsNull())
|
|
1396
1396
|
{
|
|
1397
|
-
|
|
1397
|
+
v8::Local<v8::Object> attrsObj = attributes->ToObject(context).ToLocalChecked();
|
|
1398
|
+
v8::Local<v8::Array> propNames = attrsObj->GetOwnPropertyNames(context).ToLocalChecked();
|
|
1399
|
+
v8::Local<v8::Array> attrsArray = v8::Array::New(isolate, propNames->Length());
|
|
1400
|
+
|
|
1401
|
+
for (uint32_t i = 0; i < propNames->Length(); i++)
|
|
1402
|
+
{
|
|
1403
|
+
v8::Local<v8::Value> key = propNames->Get(context, i).ToLocalChecked();
|
|
1404
|
+
v8::Local<v8::Value> value = attrsObj->Get(context, key).ToLocalChecked();
|
|
1405
|
+
(void)attrsArray->Set(context, i, value);
|
|
1406
|
+
}
|
|
1407
|
+
(void)json->CreateDataProperty(context, attributes_str, attrsArray);
|
|
1398
1408
|
}
|
|
1399
1409
|
|
|
1400
1410
|
args.GetReturnValue().Set(json);
|
package/test/json.js
CHANGED
|
@@ -63,6 +63,40 @@ describe('JSON Serialization', function() {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
});
|
|
66
|
+
|
|
67
|
+
it('should not serialize attribute values as null', function() {
|
|
68
|
+
// Check all attributes in file don't have null values when serialized
|
|
69
|
+
var jsonStr = JSON.stringify(file);
|
|
70
|
+
var nullMatches = jsonStr.match(/"value":\s*null/g);
|
|
71
|
+
var nullCount = nullMatches ? nullMatches.length : 0;
|
|
72
|
+
|
|
73
|
+
expect(nullCount).to.equal(0, 'Found ' + nullCount + ' null attribute values in JSON');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('should convert TypedArray values to regular arrays in JSON', function() {
|
|
77
|
+
// Find an attribute with a TypedArray value
|
|
78
|
+
var variables = file.root.variables;
|
|
79
|
+
for (var varName in variables) {
|
|
80
|
+
var variable = variables[varName];
|
|
81
|
+
var varAttrs = variable.attributes;
|
|
82
|
+
for (var attrName in varAttrs) {
|
|
83
|
+
var attr = varAttrs[attrName];
|
|
84
|
+
|
|
85
|
+
// Check if value is a TypedArray
|
|
86
|
+
if (attr.value && typeof attr.value === 'object' &&
|
|
87
|
+
attr.value.constructor && attr.value.constructor.name.includes('Array') &&
|
|
88
|
+
!Array.isArray(attr.value)) {
|
|
89
|
+
|
|
90
|
+
// It's a TypedArray, test it converts to regular array
|
|
91
|
+
var json = JSON.parse(JSON.stringify(attr));
|
|
92
|
+
|
|
93
|
+
// In JSON, it should be a regular array
|
|
94
|
+
expect(Array.isArray(json.value)).to.be.true;
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
});
|
|
66
100
|
});
|
|
67
101
|
|
|
68
102
|
describe('Variable', function() {
|