-
Notifications
You must be signed in to change notification settings - Fork 103
/
javascript_array.cpp
95 lines (80 loc) · 3.05 KB
/
javascript_array.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <stdio.h>
#include "baselib_string.h"
#include "javascript_array.h"
base_array::base_array() {
this->array_length=1;
this->array_type_=BASE_ARRAY_CLASS;
this->array_index=alloc_memory(4);
*(unsigned long*)this->array_index=0;
}
base_array::base_array(unsigned long init_length) {
this->array_length=init_length;
this->array_type_=BASE_ARRAY_CLASS;
this->array_index=alloc_memory(4*init_length);
memset(this->array_index,0,4*init_length);
}
base_array::~base_array() {
free_memory(this->array_index);
}
void* base_array::get_index(unsigned long index) {
unsigned long* read_address=((unsigned long*)this->array_index+index);
return (void*)*read_address;
}
void base_array::set_index(unsigned long index,void* index_data) {
unsigned long* write_address=((unsigned long*)this->array_index+index);
*write_address=(unsigned long)index_data;
}
unsigned long base_array::length(void) {
return this->array_length;
}
array_type base_array::type(void) {
return this->array_type_;
}
int_array::int_array() {
this->array_length=1;
this->array_type_=INT_ARRAY_CLASS;
this->array_index=alloc_memory(4);
*(unsigned long*)this->array_index=0;
}
int_array::int_array(unsigned long init_length) {
this->array_length=init_length;
this->array_type_=INT_ARRAY_CLASS;
this->array_index=alloc_memory(4*init_length);
memset(this->array_index,0,4*init_length);
}
object_array::object_array() {
this->array_length=1;
this->array_type_=OBJECT_ARRAY_CLASS;
this->array_index=alloc_memory(sizeof(object_index));
memset(this->array_index,0,sizeof(object_index));
}
object_array::object_array(unsigned long init_length) {
this->array_length=1;
this->array_type_=OBJECT_ARRAY_CLASS;
this->array_index=alloc_memory(sizeof(object_index)*init_length);
memset(this->array_index,0,sizeof(object_index)*init_length);
}
void* object_array::get_index(unsigned long index) {
for (object_index* object_index_point=(object_index*)this->array_index;
object_index_point!=NULL;
object_index_point=object_index_point->next_object_index)
if (object_index_point->object_index_number==index)
return &object_index_point->object_data;
return NULL;
}
void object_array::set_index(unsigned long index,void* index_data) {
object_index* last_object_index_point=NULL;
for (object_index* object_index_point=(object_index*)this->array_index;
object_index_point!=NULL;
object_index_point=object_index_point->next_object_index) {
last_object_index_point=object_index_point;
if (object_index_point->object_index_number==index) {
memcpy(&object_index_point->object_data,index_data,sizeof(javascript_variant_struct));
return;
}
}
if (NULL!=last_object_index_point) {
last_object_index_point->next_object_index=(object_index*)alloc_memory(sizeof(object_index));
memset(last_object_index_point->next_object_index,0,sizeof(object_index));
}
}