已合并
bind-this-method #1122
bind-this-method #1122
已合并
raifmirzaerten创建于 2025年9月29日
raifmirzaerten
raifmirzaerten
2025年9月29日

一、内容说明(相关的Issue)

二、建议测试周期和提测地址

建议测试完成时间:xxxx.xx.xx
投产上线时间:xxxx.xx.xx
提测地址:CI环境/压测环境
测试账号:

三、变更内容

  • 3.1 关联PR列表

  • 3.2 数据库和部署说明

    1. 常规更新
    2. 重启unicorn
    3. 重启sidekiq
    4. 迁移任务:是否有迁移任务,没有写 "无"
    5. rake脚本:bundle exec xxx RAILS_ENV = production;没有写 "无"
  • 3.4 其他技术优化内容(做了什么,变更了什么)

    • 重构了 xxxx 代码
    • xxxx 算法优化
  • 3.5 废弃通知(什么字段、方法弃用?)

  • 3.6 后向不兼容变更(是否有无法向后兼容的变更?)

四、研发自测点(自测哪些?冒烟用例全部自测?)

自测测试结论:

五、测试关注点(需要提醒QA重点关注的、可能会忽略的地方)

检查点:

需求名称 是否影响xx公共模块 是否需要xx功能 需求升级是否依赖其他子产品
xxx 需要 不需要

接口测试:

性能测试:

并发测试:

其他:

likedislike
Pull Request已成功合入, 合并人@openharmony_ci
(感谢 raifmirzaerten 的贡献)
openharmony_ci
openharmony_ci成员
2025年9月29日 评论:

感谢提交 Pull Requests!
Thanks for submitting a pull request.

likedislike
openharmony_ciopenharmony_ci成员
2025年9月29日 添加了label:dco检查成功
xudan16
xudan16成员2025年9月30日进行代码检视2
test/unittest/sample/ThisBindCheck/ets/LocalAndClassSimilar.ts
已过期
@@ -0,0 +24,4 @@
24+ private someProp: A = new A();
25+ 
26+ public someMethod(someProp: A) {
27+ console.log(`Some important message with prop -> ${this.someProp.getSomething}` +
xudan16
xudan162025年9月30日评论:

what will happed if someProp is defined in this someMethod rather than from param?

likedislike
System
系统消息系统
2025年10月10日 评论:
likedislike
raifmirzaertenraifmirzaerten
2025年10月10日 推送  1 个提交:fc33e413-numeric rule field check
raifmirzaertenraifmirzaerten
2025年10月10日 强制推送  1 个提交:2d612f89-numeric rule field check
raifmirzaertenraifmirzaerten
2025年10月10日 修改标题为 “[WIP]bind-this-method”,原标题为“[WIP]numeric rule field check”
xudan16
xudan16成员2025年10月10日进行代码检视2
src/checker/migration/ThisBindCheck.ts
已过期
@@ -147,2 +151,3 @@
147151 }
148- } else {
152+ } else if (user instanceof ArkAssignStmt) {
153+ if(user.getRightOp() instanceof ArkPtrInvokeExpr) {
xudan16
xudan162025年10月10日评论:

not quite understand about this check. why it's unsafe if the rightOp is ArkPtrInvokeExpr?

likedislike
System
系统消息系统
2025年10月10日 评论:
likedislike
raifmirzaertenraifmirzaerten
2025年10月10日 强制推送  1 个提交:b9248158-bind this rule impl
xudan16
xudan16成员2025年10月10日进行代码检视1
test/unittest/code/ThisBindCheck.test.ts
已过期
@@ -95,12 +95,10 @@ describe('ThisBindTest', () => {
9595 
9696 test('ThisBindTest_008', () => {
9797 const detectFile: string = path.join(realPath, 'ets', 'GlobalThis.ets');
98- const expectReportList = ['25%16%'];
xudan16
xudan162025年10月10日评论:

why there is no issue here?

likedislike
xudan16
xudan16成员2025年10月10日进行代码检视1
src/checker/migration/ThisBindCheck.ts
@@ -39,30 +40,30 @@
40+import {ArkPtrInvokeExpr} from "arkanalyzer/lib";
3941 
4042const logger = Logger.getLogger(LOG_MODULE_TYPE.HOMECHECK, 'ThisBindCheck');
4143 
@@ -106,6 +108,7 @@ export class ThisBindCheck implements BaseChecker {
106108 const isBuilder = method.hasBuilderDecorator();
107109 const isLocalBuilder = method.hasDecorator('LocalBuilder');
108110 const leftOp = stmt.getLeftOp();
111+ 
109112 if (i + 1 >= stmts.length || !this.hasBindThis(leftOp, stmts[i + 1])) {
110113 if (!this.isSafeUse(leftOp)) {
111114 this.addIssueReport(stmt, isBuilder, isLocalBuilder, base, scene);
@@ -132,12 +135,13 @@ export class ThisBindCheck implements BaseChecker {
132135 
133136 private isSafeUse(v: Value): boolean {
134137 if (!(v instanceof Local)) {
138+ 
135139 return false;
136140 }
137141 
138142 const users = v.getUsedStmts();
139143 if (users.length === 0) {
140- return false;
144+ return true;
141145 }
142146 for (const user of users) {
143147 if (user instanceof ArkIfStmt) {
@@ -145,7 +149,9 @@ export class ThisBindCheck implements BaseChecker {
145149 if (v !== cond.getOp1() && v !== cond.getOp2()) {
146150 return false;
147151 }
xudan16
xudan162025年10月10日评论:

How can we distinguish the cases for:

  1. function pointer with called.
  2. function pointer without called.
likedislike
xudan16
xudan16成员2025年10月10日进行代码检视1
test/unittest/sample/ThisBindCheck/ets/LocalAndClassSimilar.ts
@@ -0,0 +25,4 @@
25+function someMethod(getSomething : () => string): void {
26+ getSomething();
27+}
28+someMethod(getSomething);
xudan16
xudan162025年10月10日评论:

Add a case for let res = foo(getSomething)

likedislike
raifmirzaertenraifmirzaerten
2025年10月10日 强制推送  1 个提交:1e566073-bind this rule impl
raifmirzaertenraifmirzaerten
2025年10月10日 强制推送  1 个提交:dba6c880-bind this rule impl
raifmirzaertenraifmirzaerten
2025年10月10日 强制推送  1 个提交:6196525d-bind this rule impl
xudan16
xudan16成员2025年10月11日进行代码检视1
test/unittest/code/ThisBindCheck.test.ts
@@ -135,3 +127,3 @@
135127 const detectFileReport = checkEntry.fileChecks.find((fileCheck) => fileCheck.arkFile.getFilePath() === detectFile);
136128 assert.isDefined(detectFileReport, 'The file path is error.');
137- assert.equal(detectFileReport?.issues.length, expectReportList.length, 'The number of reported line is different from the expected number of line.');
129+ assert.equal(detectFileReport?.issues.length, 0,'The number of reported line should be 0.');
xudan16
xudan162025年10月11日评论:

It should still report issue in all these files which are used to report. Avoid to remove the issue.

If necessary, you need to update the corresponding sample code to ensure the issue report as before.

likedislike
xudan16
xudan16成员2025年10月11日进行代码检视1
src/checker/migration/ThisBindCheck.ts
@@ -76,3 +78,3 @@
7678 public check = (targetMtd: ArkMethod): void => {
7779 const file = targetMtd.getDeclaringArkFile();
78- if (file.getName().includes('.test.ets')) {
80+ if (file.getName().includes('.test.ets') || file.getName().includes('.ts') || file.getName().includes('.js')) {
xudan16
xudan162025年10月11日评论:

please using targetMtd.getLanguage() !== Language.ARKTS1_2 to do the check.

the file could also be with .ets but not marked as arkts1.2 which no need to check as well as C++ files.

likedislike
raifmirzaertenraifmirzaerten
2025年10月13日 强制推送  1 个提交:0b9347d6-bind this rule impl
raifmirzaertenraifmirzaerten
2025年10月17日 取消了草稿状态
yifei-xueyifei-xue成员
2025年10月20日 通过审查
xudan16
xudan16成员
2025年10月20日 评论:

FORCE_VERIFY

likedislike
openharmony_ciopenharmony_ci成员
2025年10月20日 通过测试
openharmony_ci
openharmony_ci成员
2025年10月20日 评论:

添加 测试通过 成功!

likedislike
openharmony_ciopenharmony_ci成员
2025年10月20日 合入了pull request,合并节点 SHA:bc5527693d8646cf3134c668596a13a2d0bb9740