-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathPWScript.m
More file actions
68 lines (57 loc) · 1.48 KB
/
Copy pathPWScript.m
File metadata and controls
68 lines (57 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// ProWidgets
//
// 1.0.0
//
// Created by Alan Yip on 18 Jan 2014
// Copyright 2014 Alan Yip. All rights reserved.
//
#import "PWScript.h"
#import "JSBridge/PWJSBridge.h"
@implementation PWScript
+ (instancetype)scriptWithName:(NSString *)name inBundle:(NSBundle *)bundle {
PWScript *script = [self new];
script.isJS = NO;
script.name = name;
script.bundle = bundle;
return [script autorelease];
}
+ (instancetype)scriptWithJSFile:(NSString *)filename withName:(NSString *)name inBundle:(NSBundle *)bundle {
PWScript *script = [self new];
script.isJS = YES;
script.name = name;
script.bundle = bundle;
script.filename = filename;
script.path = [NSString stringWithFormat:@"%@/%@", [bundle bundlePath], filename];
script.bridge = [[[PWJSBridge alloc] initWithScript:script] autorelease];
return [script autorelease];
}
- (void)execute {
if (_isJS && _path != nil) {
LOG(@"PWScript: execute JavaScript file at '%@'", _path);
// read JS file
[_bridge readJSFile:_path];
// tell bridge to clear JSContext
//[_bridge scriptExecuted];
}
}
- (void)_execute {
if (_executed) return;
LOG(@"PWScript: execute script");
[self retain]; // retain myself while executing the script in background
[self execute];
_executed = YES;
//[self release]; // release myself after executing the script
}
- (void)dealloc {
DEALLOCLOG;
// release JSBridge
if (_bridge != nil) {
[_bridge scriptExecuted];
RELEASE(_bridge)
}
RELEASE(_filename)
RELEASE(_path)
[super dealloc];
}
@end