1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | #include "PDFArrayDriver.h"
|
21 | #include "RefCountPtr.h"
|
22 | #include "ConstructorsHolder.h"
|
23 |
|
24 | using namespace v8;
|
25 |
|
26 |
|
27 |
|
28 | DEF_SUBORDINATE_INIT(PDFArrayDriver::Init)
|
29 | {
|
30 | CREATE_ISOLATE_CONTEXT;
|
31 |
|
32 | Local<FunctionTemplate> t = NEW_FUNCTION_TEMPLATE_EXTERNAL(New);
|
33 |
|
34 | t->SetClassName(NEW_STRING("PDFArray"));
|
35 | t->InstanceTemplate()->SetInternalFieldCount(1);
|
36 |
|
37 | SET_PROTOTYPE_METHOD(t, "toJSArray", ToJSArray);
|
38 | SET_PROTOTYPE_METHOD(t, "queryObject", QueryObject);
|
39 | SET_PROTOTYPE_METHOD(t, "getLength", GetLength);
|
40 | PDFObjectDriver::Init(t);
|
41 |
|
42 |
|
43 | EXPOSE_EXTERNAL_FOR_INIT(ConstructorsHolder, holder)
|
44 | SET_CONSTRUCTOR(holder->PDFArray_constructor, t);
|
45 | SET_CONSTRUCTOR_TEMPLATE(holder->PDFArray_constructor_template, t);
|
46 | }
|
47 |
|
48 | METHOD_RETURN_TYPE PDFArrayDriver::New(const ARGS_TYPE& args)
|
49 | {
|
50 | CREATE_ISOLATE_CONTEXT;
|
51 | CREATE_ESCAPABLE_SCOPE;
|
52 | EXPOSE_EXTERNAL_ARGS(ConstructorsHolder, externalHolder)
|
53 |
|
54 | PDFArrayDriver* array = new PDFArrayDriver();
|
55 | array->holder = externalHolder;
|
56 | array->Wrap(args.This());
|
57 | SET_FUNCTION_RETURN_VALUE(args.This())
|
58 | }
|
59 |
|
60 | PDFObject* PDFArrayDriver::GetObject()
|
61 | {
|
62 | return TheObject.GetPtr();
|
63 | }
|
64 |
|
65 | METHOD_RETURN_TYPE PDFArrayDriver::ToJSArray(const ARGS_TYPE& args)
|
66 | {
|
67 | CREATE_ISOLATE_CONTEXT;
|
68 | CREATE_ESCAPABLE_SCOPE;
|
69 |
|
70 | PDFArrayDriver* arrayDriver = ObjectWrap::Unwrap<PDFArrayDriver>(args.This());
|
71 |
|
72 | Local<Array> result = NEW_ARRAY((int)arrayDriver->TheObject->GetLength());
|
73 |
|
74 | for(unsigned long i=0; i < arrayDriver->TheObject->GetLength();++i)
|
75 | {
|
76 | RefCountPtr<PDFObject> anObject(arrayDriver->TheObject->QueryObject(i));
|
77 | result->Set(GET_CURRENT_CONTEXT, NEW_NUMBER(i),arrayDriver->holder->GetInstanceFor(anObject.GetPtr()));
|
78 | }
|
79 |
|
80 | SET_FUNCTION_RETURN_VALUE(result)
|
81 | }
|
82 |
|
83 | METHOD_RETURN_TYPE PDFArrayDriver::GetLength(const ARGS_TYPE& args)
|
84 | {
|
85 | CREATE_ISOLATE_CONTEXT;
|
86 | CREATE_ESCAPABLE_SCOPE;
|
87 |
|
88 | PDFArrayDriver* arrayDriver = ObjectWrap::Unwrap<PDFArrayDriver>(args.This());
|
89 |
|
90 | Local<Number> result = NEW_NUMBER(arrayDriver->TheObject->GetLength());
|
91 |
|
92 | SET_FUNCTION_RETURN_VALUE(result)
|
93 | }
|
94 |
|
95 | METHOD_RETURN_TYPE PDFArrayDriver::QueryObject(const ARGS_TYPE& args)
|
96 | {
|
97 | CREATE_ISOLATE_CONTEXT;
|
98 | CREATE_ESCAPABLE_SCOPE;
|
99 |
|
100 | if(args.Length() != 1 || !args[0]->IsNumber())
|
101 | {
|
102 | THROW_EXCEPTION("wrong arguments, pass 1 argument which is an index in the array");
|
103 | SET_FUNCTION_RETURN_VALUE(UNDEFINED)
|
104 |
|
105 | }
|
106 |
|
107 | PDFArrayDriver* arrayDriver = ObjectWrap::Unwrap<PDFArrayDriver>(args.This());
|
108 | if(TO_UINT32(args[0])->Value() >= arrayDriver->TheObject->GetLength())
|
109 | {
|
110 | THROW_EXCEPTION("wrong arguments, pass 1 argument which is a valid index in the array");
|
111 | SET_FUNCTION_RETURN_VALUE(UNDEFINED)
|
112 | }
|
113 |
|
114 | RefCountPtr<PDFObject> anObject = arrayDriver->TheObject->QueryObject(TO_UINT32(args[0])->Value());
|
115 | Local<Value> result = arrayDriver->holder->GetInstanceFor(anObject.GetPtr());
|
116 |
|
117 | SET_FUNCTION_RETURN_VALUE(result)
|
118 | } |
\ | No newline at end of file |