【发布时间】:2022-12-27 19:39:49
【问题描述】:
So I have this simple Javascript code where I am comparing database-stored cart items with client-sent new cart items. But I am getting this new error which I have never seen before:
#
# Fatal error in , line 0
# Fatal JavaScript invalid size error 178414678
#
#
#
#FailureMessage Object: 000000DCF17BE620
1: 00007FF7F50A401F v8::internal::CodeObjectRegistry::~CodeObjectRegistry+112511
2: 00007FF7F4FC116F v8::CFunctionInfo::HasOptions+7055
3: 00007FF7F5C97302 V8_Fatal+162
4: 00007FF7F5820C65 v8::internal::FactoryBase<v8::internal::Factory>::NewFixedArray+101
5: 00007FF7F56CA463 v8::internal::FeedbackNexus::ic_state+62771
6: 00007FF7F56E0FC0 v8::Message::GetIsolate+15840
7: 00007FF7F5555681 v8::internal::CompilationCache::IsEnabledScriptAndEval+26849
8: 00007FF7F59F34B1 v8::internal::SetupIsolateDelegate::SetupHeap+494417
9: 000001F9C44485C2
What the code does is, it checks if the product id is same or not in both the arrays. If it is then it will just replace the database cart item unit with client-sent cart item unit. If it is not, then it will just push the client-sent cart item to database-stored cart items array. That's all it does.
The code:
const dbCartItems = [
{ productID: '1233433', unit: 1 },
{ productID: 'asfa34wr', unit: 2 }
];
const clientCartItems = [
{ productID: 'dfhgdf46t3', unit: 4 },
{ productID: 'hgfh566', unit: 1 },
{ productID: '32523', unit: 1 }
];
for ( let i = 0; i < dbCartItems.length; i++ ) {
for ( let j = 0; j < clientCartItems.length; j++ ) {
if ( dbCartItems[ i ].productID === clientCartItems[ j ].productID ) {
dbCartItems[ i ].unit = clientCartItems[ j ].unit;
} else {
dbCartItems.push( clientCartItems[ j ] );
}
}
}
console.log( dbCartItems );
Can someone please explain what is wrong with the code that it throws this kind of error which I have never seen before?
【问题讨论】:
-
dbCartItems.push( clientCartItems[ j ] );You keep increasing the length of the array inside the loop?
标签: javascript