Skip to content

Commit

Permalink
0.2 release
Browse files Browse the repository at this point in the history
- New binding system for exposing Objective-C methods to JavaScript
- Hide `constructor` when enumerating attributing of a JavaScript object
- Fix incorrect value of `node.onframeupdate` when it's not set
  • Loading branch information
openaphid committed May 15, 2012
1 parent e0a6660 commit b29a1ef
Show file tree
Hide file tree
Showing 76 changed files with 1,319 additions and 150 deletions.
92 changes: 92 additions & 0 deletions OpenAphid/AJDynamicBinding.cpp
@@ -0,0 +1,92 @@
/*
Copyright 2012 Aphid Mobile
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/


#include <config.h>

#include "AJDynamicBinding.h"

#include <runtime/AJFunction.h>
#include <runtime/NativeFunctionWrapper.h>
#include <runtime/PrototypeFunction.h>
#include <runtime/Lookup.h>

#include "AJOABinding.h"
#include "OAUtil.h"

namespace Aphid {
using namespace AJ;

#include "AJDynamicBinding_table.in.h"

///-------------------------------------------------------------------------------------------------------------------
AJDynamicBinding::AJDynamicBinding(NonNullPassRefPtr<Structure> structure, AJOAGlobalObject* globalObject, PassRefPtr<DynamicBinding> impl)
: Base(structure, globalObject)
, m_impl(impl)
{
AJ_LEAK_DETECT_INC("AJDynamicBinding");
ExecState * exec = globalObject->globalExec();

Vector<UString> names;
m_impl->listFunctionNames(names);

for (int i = 0; i < names.size(); i++) {
const UString& name = names.at(i);
putDirectFunction(exec, new (exec) NativeFunctionWrapper(exec, globalObject->prototypeFunctionStructure(), 0, Identifier(exec, name), ajDynamicBindingFunction));
}
ASSERT(!exec->hadException());
}

AJDynamicBinding::~AJDynamicBinding()
{
//oa_debug("AJDynamicBinding destructed");
m_impl->clearWrapper(this);
AJ_LEAK_DETECT_DEC("AJDynamicBinding");
}
///-------------------------------------------------------------------------------------------------------------------
DynamicBinding* toDynamicBinding(AJValue value)
{
return value.inherits(&AJDynamicBinding::s_info) ? ajoa_cast<AJDynamicBinding*>(asObject(value))->impl() : 0;
}

AJValue toAJ(ExecState* exec, AJOAGlobalObject* globalObject, DynamicBinding* impl)
{
if (!impl)
return jsNull();

AJObject* wrapper = impl->wrapper();
if (wrapper)
return wrapper;
ASSERT(!impl->isInheritanceWrapper());
return createAJOAWrapper<AJDynamicBinding>(exec, globalObject, impl);
}

///-------------------------------------------------------------------------------------------------------------------
AJ::AJValue JSC_HOST_CALL ajDynamicBindingFunction(AJ::ExecState* exec, AJ::AJObject* functionObject, AJ::AJValue thisValue, const AJ::ArgList& args)
{
CHECK_INHERITS(exec, thisValue, AJDynamicBinding);

AJDynamicBinding* thisObject = ajoa_cast<AJDynamicBinding*>(asObject(thisValue));

if (functionObject->inherits(&InternalFunction::info)) {
InternalFunction* function = asInternalFunction(functionObject);
const UString& name = function->name(exec);
return thisObject->impl()->invokeFunction(exec, thisObject->globalObject(), name, args);
}
return jsUndefined();
}

}
13 changes: 13 additions & 0 deletions OpenAphid/AJNamespaceAphid.cpp
Expand Up @@ -31,6 +31,7 @@ limitations under the License.
#include "AJNamespaceG2D.h"
#include "AJNamespaceiOS.h"
#include "AJNamespaceJS.h"
#include "AJNamespaceExt.h"
//end

#include "OAGlobalObject.h"
Expand Down Expand Up @@ -99,4 +100,16 @@ namespace Aphid {
return toAJ(exec, jsNamespaceAphid->globalObject(), jsNamespaceAphid->globalObject()->impl()->namespaceiOS());
}

AJ::AJValue ajNamespaceAphidExt(AJ::ExecState* exec, AJ::AJValue thisValue, const AJ::Identifier&)
{
AJNamespaceAphid* jsNamespaceAphid = ajoa_cast<AJNamespaceAphid*>(asObject(thisValue));
return toAJ(exec, jsNamespaceAphid->globalObject(), jsNamespaceAphid->globalObject()->impl()->namespaceExt());
}

AJ::AJValue ajNamespaceAphidExtios(AJ::ExecState* exec, AJ::AJValue thisValue, const AJ::Identifier&)
{
AJNamespaceAphid* jsNamespaceAphid = ajoa_cast<AJNamespaceAphid*>(asObject(thisValue));
return toAJ(exec, jsNamespaceAphid->globalObject(), jsNamespaceAphid->globalObject()->impl()->namespaceExtIOS());
}

}
69 changes: 69 additions & 0 deletions OpenAphid/AJNamespaceExt.cpp
@@ -0,0 +1,69 @@
/*
Copyright 2012 Aphid Mobile
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/


#include <config.h>

#include "AJNamespaceExt.h"

#include <runtime/AJFunction.h>
#include <runtime/NativeFunctionWrapper.h>
#include <runtime/PrototypeFunction.h>
#include <runtime/Lookup.h>

#include "AJOABinding.h"
#include "OAUtil.h"

namespace Aphid {
using namespace AJ;

#include "AJNamespaceExt_table.in.h"

///-------------------------------------------------------------------------------------------------------------------
AJNamespaceExt::AJNamespaceExt(NonNullPassRefPtr<Structure> structure, AJOAGlobalObject* globalObject, PassRefPtr<NamespaceExt> impl)
: Base(structure, globalObject)
, m_impl(impl)
{
AJ_LEAK_DETECT_INC("AJNamespaceExt");
}

AJNamespaceExt::~AJNamespaceExt()
{
//oa_debug("AJNamespaceExt destructed");
m_impl->clearWrapper(this);
AJ_LEAK_DETECT_DEC("AJNamespaceExt");
}

///-------------------------------------------------------------------------------------------------------------------
NamespaceExt* toNamespaceExt(AJValue value)
{
return value.inherits(&AJNamespaceExt::s_info) ? ajoa_cast<AJNamespaceExt*>(asObject(value))->impl() : 0;
}

//TODO: set inline?
AJValue toAJ(ExecState* exec, AJOAGlobalObject* globalObject, NamespaceExt* impl)
{
if (!impl)
return jsNull();

AJObject* wrapper = impl->wrapper();
if (wrapper)
return wrapper;
ASSERT(!impl->isInheritanceWrapper());
return createAJOAWrapper<AJNamespaceExt>(exec, globalObject, impl);
}

}
5 changes: 4 additions & 1 deletion OpenAphid/AJNode.cpp
Expand Up @@ -324,7 +324,10 @@ namespace Aphid {
AJ::AJValue ajNodeOnframeupdate(AJ::ExecState*, AJ::AJValue thisValue, const AJ::Identifier&)
{
AJNode* ajNode = ajoa_cast<AJNode*>(asObject(thisValue));
return ajNode->impl()->jsUpdateCallback();
if (AJObject* callback = ajNode->impl()->jsUpdateCallback())
return callback;
else
return jsNull();
}

void setAJNodeOnframeupdate(AJ::ExecState* exec, AJ::AJObject* thisObject, AJ::AJValue value)
Expand Down
3 changes: 0 additions & 3 deletions OpenAphid/AJOABinding.cpp
Expand Up @@ -48,9 +48,6 @@ namespace Aphid {
UString exceptionURL = exceptionObj->get(exec, Identifier(exec, "sourceURL")).toString(exec);
UString errorMessage = exception.toString(exec);
exec->clearException();
/*if (ExceptionBase* exceptionBase = toExceptionBase(exception))
errorMessage = toUString(exceptionBase->message() + ": " + exceptionBase->description());
*/

Diagnostic::error(formatUString("[%s:%d] JS Exception: %s", exceptionURL.UTF8String().data(), lineNO, errorMessage.UTF8String().data()));
} else
Expand Down
2 changes: 0 additions & 2 deletions OpenAphid/Derived/AJAction_table.in.h
Expand Up @@ -28,13 +28,11 @@ ASSERT_CLASS_FITS_IN_CELL(AJActionPrototype);

bool AJAction::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
//TODO: a rough guess during code generation
return getStaticPropertySlot<AJAction, Base>(exec, &AJActionTable, this, propertyName, slot);
}

bool AJAction::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& slot)
{
//TODO: a rough guess during code generation
return getStaticPropertyDescriptor<AJAction, Base>(exec, &AJActionTable, this, propertyName, slot);
}

Expand Down
4 changes: 1 addition & 3 deletions OpenAphid/Derived/AJAffineTransformation_table.in.h
Expand Up @@ -20,7 +20,7 @@ ASSERT_CLASS_FITS_IN_CELL(AJAffineTransformationConstructor);
{"ty", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(ajAffineTransformationTy), (intptr_t)setAJAffineTransformationTy THUNK_GENERATOR(0)},
{"setAll", Function|DontDelete, (intptr_t)static_cast<NativeFunction>(ajAffineTransformationFunctionSetAll), (intptr_t)6 THUNK_GENERATOR(0)},
{"clone", Function|DontDelete, (intptr_t)static_cast<NativeFunction>(ajAffineTransformationFunctionClone), (intptr_t)0 THUNK_GENERATOR(0)},
{"constructor", ReadOnly|DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(ajAffineTransformationConstructor), (intptr_t)0 THUNK_GENERATOR(0)},
{"constructor", ReadOnly|DontEnum|DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(ajAffineTransformationConstructor), (intptr_t)0 THUNK_GENERATOR(0)},
{0, 0, 0, 0 THUNK_GENERATOR(0)}
};

Expand All @@ -33,13 +33,11 @@ ASSERT_CLASS_FITS_IN_CELL(AJAffineTransformationConstructor);

bool AJAffineTransformation::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
//TODO: a rough guess during code generation
return getStaticPropertySlot<AJAffineTransformation, Base>(exec, &AJAffineTransformationTable, this, propertyName, slot);
}

bool AJAffineTransformation::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& slot)
{
//TODO: a rough guess during code generation
return getStaticPropertyDescriptor<AJAffineTransformation, Base>(exec, &AJAffineTransformationTable, this, propertyName, slot);
}

Expand Down
4 changes: 1 addition & 3 deletions OpenAphid/Derived/AJAnimation_table.in.h
Expand Up @@ -13,7 +13,7 @@ ASSERT_CLASS_FITS_IN_CELL(AJAnimationConstructor);
static const HashTableValue AJAnimationTableValues[3] =
{
{"delay", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(ajAnimationDelay), (intptr_t)setAJAnimationDelay THUNK_GENERATOR(0)},
{"constructor", ReadOnly|DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(ajAnimationConstructor), (intptr_t)0 THUNK_GENERATOR(0)},
{"constructor", ReadOnly|DontEnum|DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(ajAnimationConstructor), (intptr_t)0 THUNK_GENERATOR(0)},
{0, 0, 0, 0 THUNK_GENERATOR(0)}
};

Expand All @@ -34,13 +34,11 @@ ASSERT_CLASS_FITS_IN_CELL(AJAnimationConstructor);

bool AJAnimation::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
//TODO: a rough guess during code generation
return getStaticValueSlot<AJAnimation, Base>(exec, &AJAnimationTable, this, propertyName, slot);
}

bool AJAnimation::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& slot)
{
//TODO: a rough guess during code generation
return getStaticValueDescriptor<AJAnimation, Base>(exec, &AJAnimationTable, this, propertyName, slot);
}

Expand Down
4 changes: 1 addition & 3 deletions OpenAphid/Derived/AJCamera_table.in.h
Expand Up @@ -15,7 +15,7 @@ ASSERT_CLASS_FITS_IN_CELL(AJCameraConstructor);
{"eye", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(ajCameraEye), (intptr_t)setAJCameraEye THUNK_GENERATOR(0)},
{"center", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(ajCameraCenter), (intptr_t)setAJCameraCenter THUNK_GENERATOR(0)},
{"up", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(ajCameraUp), (intptr_t)setAJCameraUp THUNK_GENERATOR(0)},
{"constructor", ReadOnly|DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(ajCameraConstructor), (intptr_t)0 THUNK_GENERATOR(0)},
{"constructor", ReadOnly|DontEnum|DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(ajCameraConstructor), (intptr_t)0 THUNK_GENERATOR(0)},
{0, 0, 0, 0 THUNK_GENERATOR(0)}
};

Expand All @@ -28,13 +28,11 @@ ASSERT_CLASS_FITS_IN_CELL(AJCameraConstructor);

bool AJCamera::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
//TODO: a rough guess during code generation
return getStaticValueSlot<AJCamera, Base>(exec, &AJCameraTable, this, propertyName, slot);
}

bool AJCamera::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& slot)
{
//TODO: a rough guess during code generation
return getStaticValueDescriptor<AJCamera, Base>(exec, &AJCameraTable, this, propertyName, slot);
}

Expand Down
4 changes: 1 addition & 3 deletions OpenAphid/Derived/AJColorNode_table.in.h
Expand Up @@ -14,7 +14,7 @@ ASSERT_CLASS_FITS_IN_CELL(AJColorNodeConstructor);
{
{"color", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(ajColorNodeColor), (intptr_t)setAJColorNodeColor THUNK_GENERATOR(0)},
{"opacity", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(ajColorNodeOpacity), (intptr_t)setAJColorNodeOpacity THUNK_GENERATOR(0)},
{"constructor", ReadOnly|DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(ajColorNodeConstructor), (intptr_t)0 THUNK_GENERATOR(0)},
{"constructor", ReadOnly|DontEnum|DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(ajColorNodeConstructor), (intptr_t)0 THUNK_GENERATOR(0)},
{0, 0, 0, 0 THUNK_GENERATOR(0)}
};

Expand All @@ -27,13 +27,11 @@ ASSERT_CLASS_FITS_IN_CELL(AJColorNodeConstructor);

bool AJColorNode::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
//TODO: a rough guess during code generation
return getStaticValueSlot<AJColorNode, Base>(exec, &AJColorNodeTable, this, propertyName, slot);
}

bool AJColorNode::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& slot)
{
//TODO: a rough guess during code generation
return getStaticValueDescriptor<AJColorNode, Base>(exec, &AJColorNodeTable, this, propertyName, slot);
}

Expand Down
4 changes: 1 addition & 3 deletions OpenAphid/Derived/AJColor_table.in.h
Expand Up @@ -16,7 +16,7 @@ ASSERT_CLASS_FITS_IN_CELL(AJColorConstructor);
{"g", ReadOnly|DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(ajColorG), (intptr_t)0 THUNK_GENERATOR(0)},
{"b", ReadOnly|DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(ajColorB), (intptr_t)0 THUNK_GENERATOR(0)},
{"a", ReadOnly|DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(ajColorA), (intptr_t)0 THUNK_GENERATOR(0)},
{"constructor", ReadOnly|DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(ajColorConstructor), (intptr_t)0 THUNK_GENERATOR(0)},
{"constructor", ReadOnly|DontEnum|DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(ajColorConstructor), (intptr_t)0 THUNK_GENERATOR(0)},
{0, 0, 0, 0 THUNK_GENERATOR(0)}
};

Expand All @@ -37,13 +37,11 @@ ASSERT_CLASS_FITS_IN_CELL(AJColorConstructor);

bool AJColor::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
//TODO: a rough guess during code generation
return getStaticValueSlot<AJColor, Base>(exec, &AJColorTable, this, propertyName, slot);
}

bool AJColor::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& slot)
{
//TODO: a rough guess during code generation
return getStaticValueDescriptor<AJColor, Base>(exec, &AJColorTable, this, propertyName, slot);
}

Expand Down
2 changes: 0 additions & 2 deletions OpenAphid/Derived/AJDirector_table.in.h
Expand Up @@ -39,13 +39,11 @@ ASSERT_CLASS_FITS_IN_CELL(AJDirectorPrototype);

bool AJDirector::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
//TODO: a rough guess during code generation
return getStaticValueSlot<AJDirector, Base>(exec, &AJDirectorTable, this, propertyName, slot);
}

bool AJDirector::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& slot)
{
//TODO: a rough guess during code generation
return getStaticValueDescriptor<AJDirector, Base>(exec, &AJDirectorTable, this, propertyName, slot);
}

Expand Down

0 comments on commit b29a1ef

Please sign in to comment.