2 #include "PlatformException.h"
7 JSArrayBase::JSArrayBase( JSContextRef context, JSObjectRef array ):mContext(context), mArray(array){
8 if(!JSIsArrayValue(context, array)){
9 throw TypeMismatchException("The type is not array");
11 JSValueProtect(context, array);
14 JSArrayBase::JSArrayBase( JSContextRef context):mContext(context){
15 JSValueRef exception = NULL;
16 mArray = JSObjectMakeArray( context, 0, NULL, &exception);
17 if(exception != NULL){
18 throw UnknownException(context, exception);
22 JSArrayBase::~JSArrayBase(){
23 JSValueUnprotect(mContext, mArray);
26 size_t JSArrayBase::size() const {
27 return JSGetArrayLength(mContext, mArray);
30 void JSArrayBase::resize(size_t size){
31 JSUtil::setProperty(mContext, mArray, "length", JSUtil::toJSValueRef(mContext, static_cast<double>(size)), kJSPropertyAttributeNone, NULL);
34 JSValueRef JSArrayBase::get(int index) const{
35 return JSGetArrayElement(mContext, mArray, index);
38 bool JSArrayBase::set( int index, JSValueRef value){
39 bool t = JSSetArrayElement(mContext, mArray, index, value);
43 bool JSArrayBase::append( JSValueRef value ){
44 return set( size(), value);