Skip to content

Commit 04a345f

Browse files
committed
Working backup
1 parent 2158080 commit 04a345f

File tree

5 files changed

+145
-29
lines changed

5 files changed

+145
-29
lines changed

JawaScriptExecutive-iOS/JawaFunc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
{
1616

1717
}
18+
@property int switchId;
1819
@end
1920

2021

JawaScriptExecutive-iOS/JawaObject.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,24 @@
99
#ifndef JawaObject_h
1010
#define JawaObject_h
1111

12+
#import "JawaObjectRef.h"
13+
14+
extern NSMutableDictionary* objectPrototype;
15+
1216
@interface JawaObject : NSObject
1317
{
14-
18+
1519
}
16-
-(NSString*)toString;
20+
@property (strong) NSMutableDictionary* properties;
21+
@property (strong) NSMutableDictionary* prototype;
22+
23+
-(id) init;
24+
-(void) setProp:(NSString*)key with:(JawaObjectRef*)value;
25+
-(JawaObjectRef*) getProp:(NSString*)key;
26+
-(int)getBuiltinID:(NSString*)funcName;
27+
-(JawaObjectRef*)invokeBuiltin:(NSString*)funcName;
28+
-(NSString*)description;
29+
-(NSString*) toJSON:(NSMutableString*)ret;
1730
@end
1831

1932
#endif /* JawaObject_h */

JawaScriptExecutive-iOS/JawaObject.m

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,57 @@
88

99
#import <Foundation/Foundation.h>
1010
#import "JawaObject.h"
11+
#import "JawaFunc.h"
12+
13+
NSMutableDictionary* objectPrototype;
1114

1215
@implementation JawaObject
1316

17+
-(id) init {
18+
self = [super init];
19+
_properties = [[NSMutableDictionary alloc] init];
20+
_prototype = objectPrototype;
21+
return self;
22+
}
23+
24+
-(void) setProp:(NSString*)key with:(JawaObjectRef*)value {
25+
[self.properties setObject:value forKey:key];
26+
}
27+
28+
-(JawaObjectRef*) getProp:(NSString*)key {
29+
NSObject* v = [self.properties objectForKey:key];
30+
if (v != nil) return (JawaObjectRef*)v;
31+
v = [self.prototype objectForKey:key];
32+
if (v != nil)
33+
return [JawaObjectRef
34+
RefWithJawaFunc:(JawaFunc*)v
35+
on:[JawaObjectRef RefWithJawaObject:self]];
36+
return nil;
37+
}
38+
39+
-(int)getBuiltinID:(NSString*)funcName {
40+
NSObject* v = [self.prototype objectForKey:funcName];
41+
if (v != nil) return ((JawaFunc*)v).switchId;
42+
return -1;
43+
}
44+
45+
-(JawaObjectRef*)invokeBuiltin:(NSString*)funcName {
46+
int ID = [self getBuiltinID:funcName];
47+
switch(ID) {
48+
// toJSON()
49+
case 0: {
50+
return [JawaObjectRef RefWithString:[self toJSON:nil]];
51+
}
52+
}
53+
return nil;
54+
}
55+
56+
-(NSString*) description {
57+
return [NSString stringWithFormat:@""];
58+
}
59+
60+
-(NSString*) toJSON:(NSMutableString*)ret {
61+
return [NSString stringWithFormat:@""];
62+
}
1463

1564
@end

JawaScriptExecutive-iOS/JawaObjectRef.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717

1818
@interface JawaObjectRef : NSObject
1919
{
20-
NSObject* object;
21-
__weak JawaObjectRef* appliedOn;
20+
2221
}
22+
23+
@property (strong) NSObject* object;
24+
@property (weak) JawaObjectRef* appliedOn;
25+
2326
-(id)init;
2427
-(id)initWithNumber:(double)number;
2528
-(id)initWithString:(NSString*)string;
@@ -28,8 +31,18 @@
2831
-(id)initWithJawaFunc:(JawaFunc*)func;
2932
-(id)initWithJawaFunc:(JawaFunc*)func on:(JawaObjectRef*)obj;
3033
-(id)initWithJawaObject:(JawaObject*)obj;
31-
-(NSString*)toString;
34+
-(NSString*)description;
3235
-(id)transfer;
36+
37+
+(id)Ref;
38+
+(id)RefWithNumber:(double)number;
39+
+(id)RefWithString:(NSString*)string;
40+
+(id)RefWithBoolean:(bool)tf;
41+
+(id)RefWithJawaArray:(JawaArray*)array;
42+
+(id)RefWithJawaFunc:(JawaFunc*)func;
43+
+(id)RefWithJawaFunc:(JawaFunc*)func on:(JawaObjectRef*)obj;
44+
+(id)RefWithJawaObject:(JawaObject*)obj;
45+
3346
@end
3447

3548
#endif /* JawaObjectRef_h */

JawaScriptExecutive-iOS/JawaObjectRef.m

Lines changed: 64 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,68 +13,108 @@
1313

1414
@implementation JawaObjectRef
1515

16-
-(id)init { self = [super init]; object = NULL; return self; }
16+
-(id)init { self = [super init]; _object = NULL; return self; }
1717
-(id)initWithNumber:(double)number {
1818
self = [super init];
19-
object = [NSDecimalNumber numberWithDouble:number];
19+
if (self) {
20+
_object = [NSDecimalNumber numberWithDouble:number];
21+
}
2022
return self;
2123
}
2224
-(id)initWithString:(NSString*)string {
2325
self = [super init];
24-
object = [NSMutableString stringWithString:string];
26+
if (self) {
27+
_object = [NSMutableString stringWithString:string];
28+
}
2529
return self;
2630
}
2731
-(id)initWithBoolean:(bool)tf {
2832
self = [super init];
29-
object = [NSNumber numberWithBool:tf];
33+
if (self) {
34+
_object = [NSNumber numberWithBool:tf];
35+
}
3036
return self;
3137
}
3238
-(id)initWithJawaArray:(JawaArray*)array {
3339
self = [super init];
34-
object = array;
40+
if (self) {
41+
_object = array;
42+
}
3543
return self;
3644
}
3745
-(id)initWithJawaFunc:(JawaFunc*)func {
3846
self = [super init];
39-
object = func;
40-
appliedOn = nil;
47+
if (self) {
48+
_object = func;
49+
_appliedOn = nil;
50+
}
4151
return self;
4252
}
4353
-(id)initWithJawaFunc:(JawaFunc*)func on:(JawaObjectRef*)obj {
4454
self = [super init];
45-
object = func;
46-
appliedOn = obj;
55+
if (self) {
56+
_object = func;
57+
_appliedOn = obj;
58+
}
4759
return self;
4860
}
4961
-(id)initWithJawaObject:(JawaObject*)obj {
5062
self = [super init];
51-
object = obj;
63+
if (self) {
64+
_object = obj;
65+
}
5266
return self;
5367
}
54-
-(NSString*)toString {
55-
if ([object class] == [NSDecimalNumber class]) {
56-
double n = ((NSDecimalNumber*)object).doubleValue;
68+
-(NSString*)description {
69+
if ([self.object isMemberOfClass: [NSDecimalNumber class]]) {
70+
double n = ((NSDecimalNumber*)self.object).doubleValue;
5771
if (fabs(n-round(n)) < QUANTUM) {
5872
return [NSString stringWithFormat:@"%ld", (long)n];
5973
}
6074
return [NSString stringWithFormat:@"%f", n];
61-
} else if ([object class] == [NSNumber class]) {
62-
bool b = ((NSNumber*)object).boolValue;
75+
} else if ([self.object isMemberOfClass: [NSNumber class]]) {
76+
bool b = ((NSNumber*)self.object).boolValue;
6377
return b ? @"true" : @"false";
64-
} else if ([object class] == [NSMutableString class]) {
65-
return [NSString stringWithString:((NSMutableString*)object)];
66-
} else if ([object isKindOfClass:[JawaObject class]]) {
67-
return [((JawaObject*)object) toString];
78+
} else if ([self.object isMemberOfClass: [NSMutableString class]]) {
79+
return [NSString stringWithString:((NSMutableString*)self.object)];
80+
} else if ([self.object isKindOfClass:[JawaObject class]]) {
81+
return [((JawaObject*)self.object) description];
6882
}
6983
return nil;
7084
}
7185
-(id)transfer {
72-
if ([object isKindOfClass:[NSNumber class]]) {
73-
return [((NSNumber*)object) copy];
74-
} else if ([object class] == [NSMutableString class]) {
75-
return [((NSMutableString*)object) mutableCopy];
86+
if ([self.object isKindOfClass:[NSNumber class]]) {
87+
return [((NSNumber*)self.object) copy];
88+
} else if ([self.object isMemberOfClass: [NSMutableString class]]) {
89+
return [((NSMutableString*)self.object) mutableCopy];
7690
} else
77-
return object;
91+
return self.object;
92+
}
93+
94+
+(id)Ref {
95+
return [[self alloc] init];
7896
}
97+
+(id)RefWithNumber:(double)number {
98+
return [[self alloc] initWithNumber:number];
99+
}
100+
+(id)RefWithString:(NSString*)string {
101+
return [[self alloc] initWithString:string];
102+
}
103+
+(id)RefWithBoolean:(bool)tf {
104+
return [[self alloc] initWithBoolean:tf];
105+
}
106+
+(id)RefWithJawaArray:(JawaArray*)array {
107+
return [[self alloc] initWithJawaArray:array];
108+
}
109+
+(id)RefWithJawaFunc:(JawaFunc*)func {
110+
return [[self alloc] initWithJawaFunc:func];
111+
}
112+
+(id)RefWithJawaFunc:(JawaFunc*)func on:(JawaObjectRef*)obj {
113+
return [[self alloc] initWithJawaFunc:func on:obj];
114+
}
115+
+(id)RefWithJawaObject:(JawaObject*)obj {
116+
return [[self alloc] initWithJawaObject:obj];
117+
}
118+
79119

80120
@end

0 commit comments

Comments
 (0)