2012-02-02 21:57:20 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2012-02-02 21:57:20 +00:00
|
|
|
|
2012-11-30 17:49:20 +00:00
|
|
|
#ifndef JSOBJECTBUILDER_H
|
|
|
|
#define JSOBJECTBUILDER_H
|
|
|
|
|
2013-08-28 02:59:14 +00:00
|
|
|
#include "js/TypeDecls.h"
|
2013-09-05 23:10:37 +00:00
|
|
|
#include "js/RootingAPI.h"
|
2012-11-30 17:49:20 +00:00
|
|
|
|
2013-09-05 23:10:37 +00:00
|
|
|
class JSCustomArray;
|
2012-11-30 17:49:20 +00:00
|
|
|
class JSCustomObject;
|
|
|
|
class JSCustomObjectBuilder;
|
2012-11-30 17:46:59 +00:00
|
|
|
class nsAString;
|
2012-02-02 21:57:20 +00:00
|
|
|
|
|
|
|
/* this is handy wrapper around JSAPI to make it more pleasant to use.
|
|
|
|
* We collect the JSAPI errors and so that callers don't need to */
|
2013-09-05 23:10:37 +00:00
|
|
|
class JSObjectBuilder
|
2012-02-02 21:57:20 +00:00
|
|
|
{
|
2012-11-30 17:46:59 +00:00
|
|
|
public:
|
2013-09-05 23:10:37 +00:00
|
|
|
typedef JS::Handle<JSObject*> ObjectHandle;
|
|
|
|
typedef JS::Handle<JSObject*> ArrayHandle;
|
|
|
|
typedef JS::Rooted<JSObject*> RootedObject;
|
|
|
|
typedef JS::Rooted<JSObject*> RootedArray;
|
|
|
|
typedef JSObject* Object;
|
|
|
|
typedef JSObject* Array;
|
|
|
|
|
2012-02-02 21:57:20 +00:00
|
|
|
// We need to ensure that this object lives on the stack so that GC sees it properly
|
2012-11-30 17:49:20 +00:00
|
|
|
explicit JSObjectBuilder(JSContext *aCx);
|
|
|
|
~JSObjectBuilder() {}
|
|
|
|
|
2013-09-05 23:10:37 +00:00
|
|
|
void DefineProperty(JS::HandleObject aObject, const char *name, JS::HandleObject aValue);
|
|
|
|
void DefineProperty(JS::HandleObject aObject, const char *name, int value);
|
|
|
|
void DefineProperty(JS::HandleObject aObject, const char *name, double value);
|
|
|
|
void DefineProperty(JS::HandleObject aObject, const char *name, nsAString &value);
|
|
|
|
void DefineProperty(JS::HandleObject aObject, const char *name, const char *value, size_t valueLength);
|
|
|
|
void DefineProperty(JS::HandleObject aObject, const char *name, const char *value);
|
|
|
|
void ArrayPush(JS::HandleObject aArray, int value);
|
|
|
|
void ArrayPush(JS::HandleObject aArray, const char *value);
|
|
|
|
void ArrayPush(JS::HandleObject aArray, JS::HandleObject aObject);
|
|
|
|
JSObject *CreateArray();
|
|
|
|
JSObject *CreateObject();
|
|
|
|
|
|
|
|
JSContext *context() const { return mCx; }
|
2012-11-30 17:46:59 +00:00
|
|
|
|
|
|
|
private:
|
2012-11-30 17:49:20 +00:00
|
|
|
JSObjectBuilder(const JSObjectBuilder&);
|
|
|
|
JSObjectBuilder& operator=(const JSObjectBuilder&);
|
|
|
|
|
|
|
|
void* operator new(size_t);
|
|
|
|
void* operator new[](size_t);
|
|
|
|
void operator delete(void*) {
|
|
|
|
// Since JSObjectBuilder has a virtual destructor the compiler
|
|
|
|
// has to provide a destructor in the object file that will call
|
|
|
|
// operate delete in case there is a derived class since its
|
|
|
|
// destructor wont know how to free this instance.
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
void operator delete[](void*);
|
2012-02-02 21:57:20 +00:00
|
|
|
|
|
|
|
JSContext *mCx;
|
2012-11-30 17:46:59 +00:00
|
|
|
int mOk;
|
2012-02-02 21:57:20 +00:00
|
|
|
};
|
|
|
|
|
2012-11-30 17:49:20 +00:00
|
|
|
#endif
|
2012-02-02 21:57:20 +00:00
|
|
|
|