#include "JavaScript.hpp"
#include "String.hpp"
-std::vector<CYHook *> hooks_;
+static std::vector<CYHook *> &GetHooks() {
+ static std::vector<CYHook *> hooks;
+ return hooks;
+}
CYRegisterHook::CYRegisterHook(CYHook *hook) {
- hooks_.push_back(hook);
+ GetHooks().push_back(hook);
}
/* JavaScript Properties {{{ */
void CYSetPrototype(JSContextRef context, JSObjectRef object, JSValueRef value) {
JSObjectSetPrototype(context, object, value);
- _assert(JSObjectGetPrototype(context, object) == value);
+ _assert(CYIsStrictEqual(context, JSObjectGetPrototype(context, object), value));
}
/* }}} */
/* JavaScript Strings {{{ */
}
};
-typedef std::map<const char *, Type_privateData *, CYCStringLess> TypeMap;
-static TypeMap Types_;
-
JSObjectRef CYMakeStruct(JSContextRef context, void *data, sig::Type *type, ffi_type *ffi, JSObjectRef owner) {
Struct_privateData *internal(new Struct_privateData(context, owner));
CYPool &pool(*internal->pool_);
return value != NULL && JSValueIsObject(context, value) && JSObjectIsFunction(context, (JSObjectRef) value);
}
+bool CYIsEqual(JSContextRef context, JSValueRef lhs, JSValueRef rhs) {
+ return _jsccall(JSValueIsEqual, context, lhs, rhs);
+}
+
+bool CYIsStrictEqual(JSContextRef context, JSValueRef lhs, JSValueRef rhs) {
+ return JSValueIsStrictEqual(context, lhs, rhs);
+}
+
size_t CYArrayLength(JSContextRef context, JSObjectRef array) {
return CYCastDouble(context, CYGetProperty(context, array, length_s));
}
break;
default:
- for (CYHook *hook : hooks_)
+ for (CYHook *hook : GetHooks())
if (hook->PoolFFI != NULL)
if ((*hook->PoolFFI)(pool, context, type, ffi, data, value))
return;
null:
return CYJSNull(context);
default:
- for (CYHook *hook : hooks_)
+ for (CYHook *hook : GetHooks())
if (hook->FromFFI != NULL)
if (JSValueRef value = (*hook->FromFFI)(context, type, ffi, data, initialize, owner))
return value;
uint8_t value[cif->rtype->size];
- for (CYHook *hook : hooks_)
+ for (CYHook *hook : GetHooks())
if (hook->CallFunction != NULL) {
// XXX: this only supports one hook, but it is a bad idea anyway
(*hook->CallFunction)(context, cif, function, value, values);
ExecutionHandle(JSContextRef context) :
context_(context)
{
- handles_.resize(hooks_.size());
- for (size_t i(0); i != hooks_.size(); ++i) {
- CYHook *hook(hooks_[i]);
+ handles_.resize(GetHooks().size());
+ for (size_t i(0); i != GetHooks().size(); ++i) {
+ CYHook *hook(GetHooks()[i]);
if (hook->ExecuteStart != NULL)
handles_[i] = (*hook->ExecuteStart)(context_);
else
}
~ExecutionHandle() {
- for (size_t i(hooks_.size()); i != 0; --i) {
- CYHook *hook(hooks_[i-1]);
+ for (size_t i(GetHooks().size()); i != 0; --i) {
+ CYHook *hook(GetHooks()[i-1]);
if (hook->ExecuteEnd != NULL)
(*hook->ExecuteEnd)(context_, handles_[i-1]);
}
Result_ = JSStringCreateWithUTF8CString("_");
- for (CYHook *hook : hooks_)
+ for (CYHook *hook : GetHooks())
if (hook->Initialize != NULL)
(*hook->Initialize)();
}
if (CYBridgeEntry *entry = CYBridgeHash("1dlerror", 8))
entry->cache_ = new cy::Functor(entry->value_, reinterpret_cast<void (*)()>(&dlerror));
- for (CYHook *hook : hooks_)
+ for (CYHook *hook : GetHooks())
if (hook->SetupContext != NULL)
(*hook->SetupContext)(context);