Skip to content
This repository has been archived by the owner on Jan 13, 2021. It is now read-only.

Commit

Permalink
Various bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
logancollins committed Aug 8, 2012
1 parent e8e770f commit e04ddcb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 38 deletions.
42 changes: 12 additions & 30 deletions Mocha/MochaRuntime.m
Expand Up @@ -1028,50 +1028,32 @@ JSValueRef Mocha_getProperty(JSContextRef ctx, JSObjectRef object, JSStringRef p


// Enums // Enums
else if ([symbol isKindOfClass:[MOBridgeSupportEnum class]]) { else if ([symbol isKindOfClass:[MOBridgeSupportEnum class]]) {
NSNumber *value = [(MOBridgeSupportEnum *)symbol value];

double doubleValue = 0; double doubleValue = 0;

NSNumber *value = [(MOBridgeSupportEnum *)symbol value];
#if __LP64__ #if __LP64__
NSNumber *value64 = [(MOBridgeSupportEnum *)symbol value64]; NSNumber *value64 = [(MOBridgeSupportEnum *)symbol value64];
if (value != nil) { if (value64 != nil) {
doubleValue = [value doubleValue];
}
else if (value64 != nil) {
doubleValue = [value doubleValue]; doubleValue = [value doubleValue];
} }
else { else {
NSException *e = [NSException exceptionWithName:MORuntimeException reason:[NSString stringWithFormat:@"No value for enum: %@", symbol] userInfo:nil]; #endif
if (exception != NULL) { if (value != nil) {
*exception = [runtime JSValueForObject:e]; doubleValue = [value doubleValue];
} }
return NULL; else {
} NSException *e = [NSException exceptionWithName:MORuntimeException reason:[NSString stringWithFormat:@"No value for enum: %@", symbol] userInfo:nil];
#else if (exception != NULL) {
if (value != nil) { *exception = [runtime JSValueForObject:e];
doubleValue = [value doubleValue]; }
} return NULL;
else {
NSException *e = [NSException exceptionWithName:MORuntimeException reason:[NSString stringWithFormat:@"No value for enum: %@", symbol] userInfo:nil];
if (exception != NULL) {
*exception = [runtime JSValueForObject:e];
} }
return NULL; #if __LP64__
} }
#endif #endif

return JSValueMakeNumber(ctx, doubleValue); return JSValueMakeNumber(ctx, doubleValue);
} }
} }


// Describe ourselves
if ([propertyName isEqualToString:@"toString"] || [propertyName isEqualToString:@"valueOf"]) {
JSStringRef scriptJS = JSStringCreateWithUTF8CString("return '(Mocha global object)'");
JSObjectRef fn = JSObjectMakeFunction(ctx, NULL, 0, NULL, scriptJS, NULL, 1, NULL);
JSStringRelease(scriptJS);
return fn;
}

return NULL; return NULL;
} }


Expand Down
2 changes: 1 addition & 1 deletion Mocha/Objects/MOJavaScriptObject.m
Expand Up @@ -35,7 +35,7 @@ - (void)setJSObject:(JSObjectRef)JSObject JSContext:(JSContextRef)JSContext {
JSValueUnprotect(_JSContext, _JSObject); JSValueUnprotect(_JSContext, _JSObject);
} }
_JSObject = JSObject; _JSObject = JSObject;
_JSContext = _JSContext; _JSContext = JSContext;
if (_JSObject != NULL) { if (_JSObject != NULL) {
JSValueProtect(_JSContext, _JSObject); JSValueProtect(_JSContext, _JSObject);
} }
Expand Down
3 changes: 0 additions & 3 deletions Mocha/Utilities/MOFunctionArgument.h
Expand Up @@ -41,11 +41,8 @@
// Storage // Storage
@property (readonly) ffi_type *ffiType; @property (readonly) ffi_type *ffiType;
@property (readonly) void** storage; @property (readonly) void** storage;
@property (readonly) void** rawStoragePointer;
@property (copy, readonly) NSString *typeDescription; @property (copy, readonly) NSString *typeDescription;


- (void *)allocateStorage;

// Values // Values
- (JSValueRef)getValueAsJSValueInContext:(JSContextRef)ctx; - (JSValueRef)getValueAsJSValueInContext:(JSContextRef)ctx;
- (void)setValueAsJSValue:(JSValueRef)value context:(JSContextRef)ctx; - (void)setValueAsJSValue:(JSValueRef)value context:(JSContextRef)ctx;
Expand Down
11 changes: 7 additions & 4 deletions Mocha/Utilities/MOFunctionArgument.m
Expand Up @@ -23,6 +23,13 @@
#import <objc/runtime.h> #import <objc/runtime.h>




@interface MOFunctionArgument ()

- (void *)allocateStorage;

@end


@implementation MOFunctionArgument { @implementation MOFunctionArgument {
char _typeEncoding; char _typeEncoding;
void* _storage; void* _storage;
Expand Down Expand Up @@ -180,10 +187,6 @@ - (void**)storage {
return _storage; return _storage;
} }


- (void**)rawStoragePointer {
return _storage;
}

- (void *)allocateStorage { - (void *)allocateStorage {
if (!_typeEncoding) { if (!_typeEncoding) {
@throw [NSException exceptionWithName:MORuntimeException reason:[NSString stringWithFormat:@"No type encoding set in %@", self] userInfo:nil]; @throw [NSException exceptionWithName:MORuntimeException reason:[NSString stringWithFormat:@"No type encoding set in %@", self] userInfo:nil];
Expand Down

0 comments on commit e04ddcb

Please sign in to comment.