@@ -245,6 +245,7 @@ bool MetadataNode::IsMarkedAsSuper(const Handle<Object>& obj)
245
245
Handle <Object> MetadataNode::CreateClassProxy (Isolate *isolate)
246
246
{
247
247
auto existingClassProxy = GetExistingClassProxy (m_name);
248
+
248
249
if (!existingClassProxy.IsEmpty ())
249
250
{
250
251
return existingClassProxy;
@@ -601,6 +602,7 @@ Handle<Object> MetadataNode::GetImplementationObject(const Handle<Object>& objec
601
602
void MetadataNode::GetterCallback (Local<String> property, const PropertyCallbackInfo<Value>& info)
602
603
{
603
604
string propName = ConvertToString (property);
605
+
604
606
if (propName.empty ())
605
607
return ;
606
608
@@ -1168,6 +1170,7 @@ vector<MetadataEntry> MetadataNode::GetMetadataCandidatesForTypeWithoutCustomMet
1168
1170
curPtr += sizeof (uint8_t ) + sizeof (uint32_t );
1169
1171
}
1170
1172
1173
+ // get candidates from instance methods metadata
1171
1174
uint16_t instanceMethodCout = *reinterpret_cast <uint16_t *>(curPtr);
1172
1175
curPtr += sizeof (uint16_t );
1173
1176
for (int i = 0 ; i < instanceMethodCout; i++)
@@ -1181,6 +1184,7 @@ vector<MetadataEntry> MetadataNode::GetMetadataCandidatesForTypeWithoutCustomMet
1181
1184
}
1182
1185
}
1183
1186
1187
+ // get candidates from static methods metadata
1184
1188
uint16_t staticMethodCout = *reinterpret_cast <uint16_t *>(curPtr);
1185
1189
curPtr += sizeof (uint16_t );
1186
1190
for (int i = 0 ; i < staticMethodCout; i++)
@@ -1211,6 +1215,7 @@ vector<MetadataEntry> MetadataNode::GetMetadataCandidatesForTypeWithoutCustomMet
1211
1215
candidates.push_back (extendsEntry);
1212
1216
}
1213
1217
1218
+ // get candidates from instance fields metadata
1214
1219
uint16_t instanceFieldCout = *reinterpret_cast <uint16_t *>(curPtr);
1215
1220
curPtr += sizeof (uint16_t );
1216
1221
for (int i = 0 ; i < instanceFieldCout; i++)
@@ -1224,6 +1229,7 @@ vector<MetadataEntry> MetadataNode::GetMetadataCandidatesForTypeWithoutCustomMet
1224
1229
}
1225
1230
}
1226
1231
1232
+ // get candidates from static fields metadata
1227
1233
uint16_t staticFieldCout = *reinterpret_cast <uint16_t *>(curPtr);
1228
1234
curPtr += sizeof (uint16_t );
1229
1235
for (int i = 0 ; i < staticFieldCout; i++)
@@ -1327,20 +1333,21 @@ Handle<Function> MetadataNode::CreateFunction(const Handle<Object>& thiz, const
1327
1333
void MetadataNode::SetterCallback (Local<String> property, Local<Value> value, const PropertyCallbackInfo<Value>& info)
1328
1334
{
1329
1335
string propName = ConvertToString (property);
1336
+
1330
1337
if (propName.empty ())
1331
1338
return ;
1332
1339
1333
1340
auto thiz = info.This ();
1334
1341
MetadataNode *node = GetNodeFromHandle (thiz);
1335
1342
1336
- //
1337
1343
auto & cache = node->m_childCache ;
1338
1344
auto itStart = cache.begin ();
1339
1345
auto itEnd = cache.end ();
1340
1346
auto itFound = find_if (itStart, itEnd, [&propName] (const MetadataCacheItem& item) { return item.name == propName; } );
1341
1347
if (itFound != itEnd)
1342
1348
{
1343
1349
const auto & cacheItem = *itFound;
1350
+
1344
1351
if (cacheItem.type == MetadataCacheItemType::Field)
1345
1352
{
1346
1353
bool isStatic = cacheItem.entry .type == NodeType::StaticField;
@@ -1351,9 +1358,11 @@ void MetadataNode::SetterCallback(Local<String> property, Local<Value> value, co
1351
1358
{
1352
1359
assert (false );
1353
1360
}
1354
- return ;
1361
+ if (!cacheItem.entry .isFinal )
1362
+ {
1363
+ return ;
1364
+ }
1355
1365
}
1356
- //
1357
1366
1358
1367
DEBUG_WRITE (" MetadataNode::SetterCallback propName='%s', node='%s', hash=%d" , propName.c_str (), node->m_name .c_str (), thiz->GetIdentityHash ());
1359
1368
@@ -1373,12 +1382,19 @@ void MetadataNode::SetterCallback(Local<String> property, Local<Value> value, co
1373
1382
1374
1383
if ((first.type == NodeType::Field) || (first.type == NodeType::StaticField))
1375
1384
{
1385
+ if (first.isFinal )
1386
+ {
1387
+ Isolate *isolate (Isolate::GetCurrent ());
1388
+ Handle <String> exceptionMessage = ConvertToV8String (" You are trying to SET a final field! Final fields can only be read." );
1389
+ Local<Value> IllegalAccessException (exceptionMessage);
1390
+
1391
+ isolate->ThrowException (IllegalAccessException);
1392
+ }
1376
1393
s_setJavaField (thiz, value, node->m_name , first.name , first.sig , first.declaringType , first.isStatic );
1377
- //
1394
+
1378
1395
MetadataCacheItem cacheItem (propName, nullptr , MetadataCacheItemType::Field);
1379
1396
cacheItem.entry = first;
1380
1397
cache.push_back (cacheItem);
1381
- //
1382
1398
}
1383
1399
else
1384
1400
{
0 commit comments