Skip to content

Commit

Permalink
BUGFIX: block 中未对 NSNumberNode 的子节点进行变量捕获,导致变量查找失败的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverFruity committed Mar 27, 2023
1 parent 1a731d6 commit fce3cf7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion OCRunner.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "OCRunner"
s.version = "1.2.10"
s.version = "1.2.11"
s.summary = "OCRunner"
s.description = <<-DESC
Execute Objective-C code Dynamically. iOS hotfix SDK.
Expand Down
4 changes: 4 additions & 0 deletions OCRunner/RunnerClasses+Execute.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ void copy_undef_var(id exprOrStatement, MFVarDeclareChain *chain, MFScopeChain *
if (exprOrStatementClass == [ORValueExpression class]) {
ORValueExpression *expr = (ORValueExpression *)exprOrStatement;
switch (expr.value_type) {
case OCValueNSNumber:{
copy_undef_var(expr.value, chain, fromScope, destScope);
break;
}
case OCValueDictionary:{
for (NSArray *kv in expr.value) {
ORNode *keyExp = kv.firstObject;
Expand Down
16 changes: 16 additions & 0 deletions OCRunnerTests/OCRunnerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1128,4 +1128,20 @@ class CRunnerTests: XCTestCase {
let result = scope.getValueWithIdentifier("result")?.intValue
XCTAssert(result == 3);
}
func testBlockCaptureNSNumberSubNodes() {
let source =
"""
int x = 1, y = 2, z= 3;
id (^block)(void) = ^id{
return @(x * y * z + 1);
};
id result = block();
"""
let ast = ocparser.parseSource(source)
for classValue in ast.nodes {
(classValue as! OCExecute).execute(scope);
}
let result = scope.getValueWithIdentifier("result")?.objectValue
XCTAssert(result as? NSNumber == NSNumber(value: 7), "\(result)");
}
}

0 comments on commit fce3cf7

Please sign in to comment.