Add missing call target check for Set and Map

Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IANXIB

Signed-off-by: daizihan <daizihan@huawei.com>
Change-Id: Ib9e0bda1a11579d7422bbb760cc26ac4dae38bbb
This commit is contained in:
daizihan 2024-09-01 18:53:59 +08:00
parent 8faea49627
commit 856872a884
5 changed files with 69 additions and 0 deletions

View File

@ -253,9 +253,13 @@ GateRef BuiltinLowering::LowerCallTargetCheck(Environment *env, GateRef gate)
return LowerCallTargetCheckWithDetector(gate, id);
}
case BuiltinsStubCSigns::ID::DateGetTime:
case BuiltinsStubCSigns::ID::MapClear:
case BuiltinsStubCSigns::ID::MapDelete:
case BuiltinsStubCSigns::ID::MapGet:
case BuiltinsStubCSigns::ID::MapHas:
case BuiltinsStubCSigns::ID::SetAdd:
case BuiltinsStubCSigns::ID::SetClear:
case BuiltinsStubCSigns::ID::SetDelete:
case BuiltinsStubCSigns::ID::SetHas: {
return LowerCallTargetCheckWithObjectType(gate, id);
}
@ -333,12 +337,16 @@ GateRef BuiltinLowering::LowerCallTargetCheckWithObjectType(GateRef gate, Builti
{
JSType expectType = JSType::INVALID;
switch (id) {
case BuiltinsStubCSigns::ID::MapClear:
case BuiltinsStubCSigns::ID::MapDelete:
case BuiltinsStubCSigns::ID::MapGet:
case BuiltinsStubCSigns::ID::MapHas: {
expectType = JSType::JS_MAP;
break;
}
case BuiltinsStubCSigns::ID::SetAdd:
case BuiltinsStubCSigns::ID::SetClear:
case BuiltinsStubCSigns::ID::SetDelete:
case BuiltinsStubCSigns::ID::SetHas: {
expectType = JSType::JS_SET;
break;

View File

@ -270,6 +270,22 @@ printClear1(mm) //aot: [trace] Check Type: BuiltinInstanceHClassMismatch
//: undefined
print("case 3") //: case 3
function checkObjWithMapProto() {
let o = {};
Object.setPrototypeOf(o, Map.prototype);
try {
print((o as Map<number, number>).clear(1));
} catch(e) {
print(e);
}
}
//aot: [trace] Check Type: NotCallTarget1
//: TypeError: obj is not JSMap
checkObjWithMapProto();
if (ArkTools.isAOTCompiled(printClear1)) {
Map.prototype.clear = function() {
return "prototype";

View File

@ -257,6 +257,21 @@ printDelete2(mm, 1); //aot: [trace] Check Type: BuiltinInstanceHClassMismatch
//: false
print("case 3") //: case 3
function checkObjWithMapProto() {
let o = {};
Object.setPrototypeOf(o, Map.prototype);
try {
print((o as Map<number, number>).delete(1));
} catch(e) {
print(e);
}
}
//aot: [trace] Check Type: NotCallTarget1
//: TypeError: obj is not JSMap
checkObjWithMapProto();
if (ArkTools.isAOTCompiled(printDelete2)) {
Map.prototype.delete = function(x: any) {
return -x * 10;

View File

@ -286,6 +286,20 @@ print(mm.size); //: 1
printClear2(mm) //: undefined
print(m.size); //: 0
function checkObjWithSetProto() {
let o = {};
Object.setPrototypeOf(o, Set.prototype);
try {
o.clear(1);
} catch(e) {
print(e);
}
}
//aot: [trace] Check Type: NotCallTarget1
//: TypeError: obj is not JSSet
checkObjWithSetProto();
if (ArkTools.isAOTCompiled(printClear2)) {
Object.setPrototypeOf(mm, mimicSet)
}

View File

@ -272,6 +272,22 @@ printDelete2(mm, 1); //aot: [trace] Check Type: BuiltinInstanceHClassMismatch
//: false
print("case 3"); //: case 3
function checkObjWithSetProto() {
let o = {};
Object.setPrototypeOf(o, Set.prototype);
try {
o.delete(1);
} catch(e) {
print(e);
}
}
//aot: [trace] Check Type: NotCallTarget1
//: TypeError: obj is not JSSet
checkObjWithSetProto();
if (ArkTools.isAOTCompiled(printDelete2)) {
Set.prototype.delete = function(x: any) {
return -x * 10;