diff --git a/ecmascript/ic/ic_runtime.cpp b/ecmascript/ic/ic_runtime.cpp index 55227c0d20e6003e8b9afd562b2236b06ca472e7..e5b0b4c705fa9b0ac836fe3e84ccbbdf33ff4325 100644 --- a/ecmascript/ic/ic_runtime.cpp +++ b/ecmascript/ic/ic_runtime.cpp @@ -136,15 +136,20 @@ JSTaggedValue LoadICRuntime::LoadMiss(JSHandle receiver, JSHandle if (receiver->IsTypedArray() || !receiver->IsJSObject()) { return JSTaggedValue::GetProperty(thread_, receiver, key).GetValue().GetTaggedValue(); } - ObjectOperator op(GetThread(), receiver, key); - auto result = JSHandle(thread_, JSObject::GetProperty(GetThread(), &op)); - if (!op.IsFound() && GetICKind() == ICKind::NamedGlobalLoadIC) { + // 1. find from global record + if (GetICKind() == ICKind::NamedGlobalLoadIC) { bool found = false; JSTaggedValue res = SlowRuntimeStub::LdGlobalRecord(thread_, key.GetTaggedValue(), &found); - if (!found) { - return SlowRuntimeStub::ThrowReferenceError(GetThread(), key.GetTaggedValue(), " is not definded"); + if (found) { + icAccessor_.SetAsMega(); + return res; } - return res; + } + // 2. find from global object + ObjectOperator op(GetThread(), receiver, key); + auto result = JSHandle(thread_, JSObject::GetProperty(GetThread(), &op)); + if (!op.IsFound() && GetICKind() == ICKind::NamedGlobalLoadIC) { + return SlowRuntimeStub::ThrowReferenceError(GetThread(), key.GetTaggedValue(), " is not definded"); } RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(GetThread()); // ic-switch @@ -172,7 +177,19 @@ JSTaggedValue StoreICRuntime::StoreMiss(JSHandle receiver, JSHand bool success = JSTaggedValue::SetProperty(GetThread(), receiver, key, value, true); return success ? JSTaggedValue::Undefined() : JSTaggedValue::Exception(); } + // 1. find from global record + if (GetICKind() == ICKind::NamedGlobalStoreIC) { + bool found = false; + SlowRuntimeStub::LdGlobalRecord(thread_, key.GetTaggedValue(), &found); + if (found) { + SlowRuntimeStub::TryUpdateGlobalRecord(thread_, key.GetTaggedValue(), value.GetTaggedValue()); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_); + icAccessor_.SetAsMega(); + return JSTaggedValue::Undefined(); + } + } UpdateReceiverHClass(JSHandle(GetThread(), JSHandle::Cast(receiver)->GetClass())); + // 2. find from global object ObjectOperator op(GetThread(), receiver, key); bool success = JSObject::SetProperty(&op, value, true); if (!success && GetICKind() == ICKind::NamedGlobalStoreIC) { diff --git a/test/moduletest/globalrecord/expect_out.txt b/test/moduletest/globalrecord/expect_output.txt similarity index 100% rename from test/moduletest/globalrecord/expect_out.txt rename to test/moduletest/globalrecord/expect_output.txt