/* }}} */
static JSGlobalContextRef Context_;
-static JSObjectRef System_;
static JSClassRef Functor_;
static JSClassRef Global_;
static JSClassRef Runtime_;
static JSClassRef Struct_;
-JSObjectRef Array_;
-JSObjectRef Error_;
-JSObjectRef Function_;
-JSObjectRef String_;
-
-JSObjectRef Array_prototype_;
-JSObjectRef Function_prototype_;
-JSObjectRef Object_prototype_;
-
+JSStringRef Array_s;
+JSStringRef cy_s;
JSStringRef length_s;
JSStringRef message_s;
JSStringRef name_s;
return JSObjectMake(context, Functor_, internal);
}
+JSObjectRef CYGetCachedObject(JSContextRef context, JSStringRef name) {
+ return CYCastJSObject(context, CYGetProperty(context, CYCastJSObject(context, CYGetProperty(context, CYGetGlobalObject(context), cy_s)), name));
+}
+
static JSObjectRef CYMakeFunctor(JSContextRef context, JSValueRef value, const char *type) {
+ JSObjectRef Function(CYGetCachedObject(context, CYJSString("Function")));
+
JSValueRef exception(NULL);
- bool function(JSValueIsInstanceOfConstructor(context, value, Function_, &exception));
+ bool function(JSValueIsInstanceOfConstructor(context, value, Function, &exception));
CYThrow(context, exception);
if (function) {
array = (*JSObjectMakeArray$)(context, argc, args, &exception);
CYThrow(context, exception);
} else {
- JSValueRef value(CYCallAsFunction(context, Array_, NULL, argc, args));
+ JSObjectRef Array(CYGetCachedObject(context, CYJSString("Array")));
+ JSValueRef value(CYCallAsFunction(context, Array, NULL, argc, args));
array = CYCastJSObject(context, value);
}
- CYSetProperty(context, System_, CYJSString("args"), array);
+ JSObjectRef System(CYGetCachedObject(context, CYJSString("System")));
+ CYSetProperty(context, System, CYJSString("args"), array);
}
JSObjectRef CYGetGlobalObject(JSContextRef context) {
//definition.getProperty = &Global_getProperty;
Global_ = JSClassCreate(&definition);
+ Array_s = JSStringCreateWithUTF8CString("Array");
+ cy_s = JSStringCreateWithUTF8CString("$cy");
length_s = JSStringCreateWithUTF8CString("length");
message_s = JSStringCreateWithUTF8CString("message");
name_s = JSStringCreateWithUTF8CString("name");
}
const char *CYJSError::PoolCString(apr_pool_t *pool) const {
- return CYPoolCString(pool, context_, value_);
+ // XXX: this used to be CYPoolCString
+ return CYPoolCCYON(pool, context_, value_);
}
JSValueRef CYJSError::CastJSValue(JSContextRef context) const {
}
JSValueRef CYCastJSError(JSContextRef context, const char *message) {
+ JSObjectRef Error(CYGetCachedObject(context, CYJSString("Error")));
+
JSValueRef arguments[1] = {CYCastJSValue(context, message)};
JSValueRef exception(NULL);
- JSValueRef value(JSObjectCallAsConstructor(context, Error_, 1, arguments, &exception));
+ JSValueRef value(JSObjectCallAsConstructor(context, Error, 1, arguments, &exception));
CYThrow(context, exception);
return value;
void CYSetupContext(JSGlobalContextRef context) {
JSObjectRef global(CYGetGlobalObject(context));
- Array_ = CYCastJSObject(context, CYGetProperty(context, global, CYJSString("Array")));
- JSValueProtect(context, Array_);
- Array_prototype_ = CYCastJSObject(context, CYGetProperty(context, Array_, prototype_s));
- JSValueProtect(context, Array_prototype_);
+ JSObjectRef cy(JSObjectMake(context, NULL, NULL));
+ CYSetProperty(context, global, cy_s, cy);
+
+ JSObjectRef Array(CYCastJSObject(context, CYGetProperty(context, global, CYJSString("Array"))));
+ CYSetProperty(context, cy, CYJSString("Array"), Array);
- Error_ = CYCastJSObject(context, CYGetProperty(context, global, CYJSString("Error")));
- JSValueProtect(context, Error_);
+ JSObjectRef Array_prototype(CYCastJSObject(context, CYGetProperty(context, Array, prototype_s)));
+ CYSetProperty(context, cy, CYJSString("Array_prototype"), Array_prototype);
- Function_ = CYCastJSObject(context, CYGetProperty(context, global, CYJSString("Function")));
- JSValueProtect(context, Function_);
- Function_prototype_ = (JSObjectRef) CYGetProperty(context, Function_, prototype_s);
- JSValueProtect(context, Function_prototype_);
+ JSObjectRef Error(CYCastJSObject(context, CYGetProperty(context, global, CYJSString("Error"))));
+ CYSetProperty(context, cy, CYJSString("Error"), Error);
+
+ JSObjectRef Function(CYCastJSObject(context, CYGetProperty(context, global, CYJSString("Function"))));
+ CYSetProperty(context, cy, CYJSString("Function"), Function);
+
+ JSObjectRef Function_prototype(CYCastJSObject(context, CYGetProperty(context, Function, prototype_s)));
+ CYSetProperty(context, cy, CYJSString("Function_prototype"), Function_prototype);
JSObjectRef Object(CYCastJSObject(context, CYGetProperty(context, global, CYJSString("Object"))));
- Object_prototype_ = CYCastJSObject(context, CYGetProperty(context, Object, prototype_s));
- JSValueProtect(context, Object_prototype_);
+ CYSetProperty(context, cy, CYJSString("Object"), Object);
+
+ JSObjectRef Object_prototype(CYCastJSObject(context, CYGetProperty(context, Object, prototype_s)));
+ CYSetProperty(context, cy, CYJSString("Object_prototype"), Object_prototype);
- String_ = CYCastJSObject(context, CYGetProperty(context, global, CYJSString("String")));
- JSValueProtect(context, String_);
+ JSObjectRef String(CYCastJSObject(context, CYGetProperty(context, global, CYJSString("String"))));
+ CYSetProperty(context, cy, CYJSString("String"), String);
JSObjectSetPrototype(context, global, JSObjectMake(context, Runtime_, NULL));
- CYSetProperty(context, Array_prototype_, toCYON_s, &Array_callAsFunction_toCYON, kJSPropertyAttributeDontEnum);
+ CYSetProperty(context, Array_prototype, toCYON_s, &Array_callAsFunction_toCYON, kJSPropertyAttributeDontEnum);
JSObjectRef Functor(JSObjectMakeConstructor(context, Functor_, &Functor_new));
-
- JSObjectSetPrototype(context, (JSObjectRef) CYGetProperty(context, Functor, prototype_s), Function_prototype_);
-
+ JSObjectSetPrototype(context, CYCastJSObject(context, CYGetProperty(context, Functor, prototype_s)), Function_prototype);
CYSetProperty(context, global, CYJSString("Functor"), Functor);
+
CYSetProperty(context, global, CYJSString("Pointer"), JSObjectMakeConstructor(context, Pointer_, &Pointer_new));
CYSetProperty(context, global, CYJSString("Type"), JSObjectMakeConstructor(context, Type_privateData::Class_, &Type_new));
CYSetProperty(context, global, CYJSString("$cyq"), &$cyq);
- System_ = JSObjectMake(context, NULL, NULL);
- JSValueProtect(context, System_);
+ JSObjectRef System(JSObjectMake(context, NULL, NULL));
+ CYSetProperty(context, cy, CYJSString("System"), Function);
- CYSetProperty(context, global, CYJSString("system"), System_);
- CYSetProperty(context, System_, CYJSString("args"), CYJSNull(context));
- //CYSetProperty(context, System_, CYJSString("global"), global);
- CYSetProperty(context, System_, CYJSString("print"), &System_print);
+ CYSetProperty(context, global, CYJSString("system"), System);
+ CYSetProperty(context, System, CYJSString("args"), CYJSNull(context));
+ //CYSetProperty(context, System, CYJSString("global"), global);
+ CYSetProperty(context, System, CYJSString("print"), &System_print);
if (hooks_ != NULL && hooks_->SetupContext != NULL)
(*hooks_->SetupContext)(context);
static JSClassRef ObjectiveC_Images_;
#endif
-static JSObjectRef Instance_prototype_;
-
#ifdef __APPLE__
static Class NSCFBoolean_;
static Class NSCFType_;
// XXX: trick this out with associated objects!
JSValueRef CYGetClassPrototype(JSContextRef context, id self) {
if (self == nil)
- return Instance_prototype_;
+ return CYGetCachedObject(context, CYJSString("Instance_prototype"));
// XXX: I need to think through multi-context
typedef std::map<id, JSValueRef> CacheMap;
JSValueRef prototype;
if (self == NSArray_)
- prototype = Array_prototype_;
+ prototype = CYGetCachedObject(context, CYJSString("Array_prototype"));
else if (self == NSDictionary_)
- prototype = Object_prototype_;
+ prototype = CYGetCachedObject(context, CYJSString("Object_prototype"));
else
prototype = CYGetClassPrototype(context, class_getSuperclass(self));
/* }}} */
NSObject *CYCastNSObject_(apr_pool_t *pool, JSContextRef context, JSObjectRef object) {
+ JSObjectRef Array(CYGetCachedObject(context, Array_s));
JSValueRef exception(NULL);
- bool array(JSValueIsInstanceOfConstructor(context, object, Array_, &exception));
+ bool array(JSValueIsInstanceOfConstructor(context, object, Array, &exception));
CYThrow(context, exception);
id value(array ? [CYJSArray alloc] : [CYJSObject alloc]);
return CYPoolRelease(pool, [value initWithJSObject:object inContext:context]);
JSValueRef exception(NULL);
JSValueRef arguments[1];
arguments[0] = CYCastJSValue(context_, (NSObject *) object);
- JSObjectCallAsFunction(context_, CYCastJSObject(context_, CYGetProperty(context_, Array_, push_s)), object_, 1, arguments, &exception);
+ JSObjectRef Array(CYGetCachedObject(context_, Array_s));
+ JSObjectCallAsFunction(context_, CYCastJSObject(context_, CYGetProperty(context_, Array, push_s)), object_, 1, arguments, &exception);
CYThrow(context_, exception);
} CYObjectiveCatch }
arguments[0] = CYCastJSValue(context_, index);
arguments[1] = CYCastJSValue(context_, 0);
arguments[2] = CYCastJSValue(context_, (NSObject *) object);
- JSObjectCallAsFunction(context_, CYCastJSObject(context_, CYGetProperty(context_, Array_, splice_s)), object_, 3, arguments, &exception);
+ JSObjectRef Array(CYGetCachedObject(context_, Array_s));
+ JSObjectCallAsFunction(context_, CYCastJSObject(context_, CYGetProperty(context_, Array, splice_s)), object_, 3, arguments, &exception);
CYThrow(context_, exception);
} CYObjectiveCatch }
- (void) removeLastObject { CYObjectiveTry {
JSValueRef exception(NULL);
- JSObjectCallAsFunction(context_, CYCastJSObject(context_, CYGetProperty(context_, Array_, pop_s)), object_, 0, NULL, &exception);
+ JSObjectRef Array(CYGetCachedObject(context_, Array_s));
+ JSObjectCallAsFunction(context_, CYCastJSObject(context_, CYGetProperty(context_, Array, pop_s)), object_, 0, NULL, &exception);
CYThrow(context_, exception);
} CYObjectiveCatch }
JSValueRef arguments[2];
arguments[0] = CYCastJSValue(context_, index);
arguments[1] = CYCastJSValue(context_, 1);
- JSObjectCallAsFunction(context_, CYCastJSObject(context_, CYGetProperty(context_, Array_, splice_s)), object_, 2, arguments, &exception);
+ JSObjectRef Array(CYGetCachedObject(context_, Array_s));
+ JSObjectCallAsFunction(context_, CYCastJSObject(context_, CYGetProperty(context_, Array, splice_s)), object_, 2, arguments, &exception);
CYThrow(context_, exception);
} CYObjectiveCatch }
void CYObjectiveC_SetupContext(JSContextRef context) { CYPoolTry {
JSObjectRef global(CYGetGlobalObject(context));
+ JSObjectRef cy(CYCastJSObject(context, CYGetProperty(context, global, cy_s)));
JSObjectRef ObjectiveC(JSObjectMake(context, NULL, NULL));
CYSetProperty(context, global, CYJSString("ObjectiveC"), ObjectiveC);
JSObjectRef Selector(JSObjectMakeConstructor(context, Selector_, &Selector_new));
JSObjectRef Super(JSObjectMakeConstructor(context, Super_, &Super_new));
- Instance_prototype_ = (JSObjectRef) CYGetProperty(context, Instance, prototype_s);
- JSValueProtect(context, Instance_prototype_);
+ JSObjectRef Instance_prototype(CYCastJSObject(context, CYGetProperty(context, Instance, prototype_s)));
+ CYSetProperty(context, cy, CYJSString("Instance_prototype"), Instance_prototype);
CYSetProperty(context, global, CYJSString("Instance"), Instance);
CYSetProperty(context, global, CYJSString("Selector"), Selector);
CYSetProperty(context, global, CYJSString("objc_msgSend"), JSObjectMakeFunctionWithCallback(context, CYJSString("objc_msgSend"), &$objc_msgSend));
- JSObjectSetPrototype(context, (JSObjectRef) CYGetProperty(context, Message, prototype_s), Function_prototype_);
- JSObjectSetPrototype(context, (JSObjectRef) CYGetProperty(context, Selector, prototype_s), Function_prototype_);
+ JSObjectRef Function_prototype(CYGetCachedObject(context, CYJSString("Function_prototype")));
+ JSObjectSetPrototype(context, CYCastJSObject(context, CYGetProperty(context, Message, prototype_s)), Function_prototype);
+ JSObjectSetPrototype(context, CYCastJSObject(context, CYGetProperty(context, Selector, prototype_s)), Function_prototype);
} CYPoolCatch() }
static CYHooks CYObjectiveCHooks = {