Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
halo
hardware_ril
Commits
16c00522
Commit
16c00522
authored
15 years ago
by
Wink Saville
Browse files
Options
Download
Email Patches
Plain Diff
Add testV8.
Change-Id: I26ec3bc964c523fe6f855e8fe3d436064acfb27a
parent
2db099fd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
1 deletion
+88
-1
mock-ril/Android.mk
mock-ril/Android.mk
+2
-1
mock-ril/mock-ril.cpp
mock-ril/mock-ril.cpp
+86
-0
No files found.
mock-ril/Android.mk
View file @
16c00522
...
...
@@ -11,13 +11,14 @@ LOCAL_SHARED_LIBRARIES := \
libcutils libutils libril
LOCAL_STATIC_LIBRARIES
:=
\
libprotobuf-cpp-2.3.0-lite
libprotobuf-cpp-2.3.0-lite
libv8
# for asprinf
LOCAL_CFLAGS
:=
-D_GNU_SOURCE
-UNDEBUG
-DGOOGLE_PROTOBUF_NO_RTTI
LOCAL_C_INCLUDES
:=
\
external/protobuf/src
\
external/v8/include
\
bionic
\
$(KERNEL_HEADERS)
...
...
This diff is collapsed.
Click to expand it.
mock-ril/mock-ril.cpp
View file @
16c00522
...
...
@@ -38,6 +38,7 @@
#include <utils/Log.h>
#include "t.pb.h"
#include <v8.h>
#define MOCK_RIL_VER_STRING "Android Mock-ril 0.1"
...
...
@@ -158,6 +159,89 @@ static void * mainLoop(void *param)
return
NULL
;
}
// Extracts a C string from a V8 Utf8Value.
const
char
*
ToCString
(
const
v8
::
String
::
Utf8Value
&
value
)
{
return
*
value
?
*
value
:
"<string conversion failed>"
;
}
// Report an exception
void
LogErrorMessage
(
v8
::
Handle
<
v8
::
Message
>
message
,
const
char
*
alternate_message
)
{
v8
::
HandleScope
handle_scope
;
if
(
message
.
IsEmpty
())
{
// V8 didn't provide any extra information about this error; just
// print the exception.
LOGD
(
"%s"
,
alternate_message
);
}
else
{
v8
::
String
::
Utf8Value
filename
(
message
->
GetScriptResourceName
());
const
char
*
filename_string
=
ToCString
(
filename
);
int
linenum
=
message
->
GetLineNumber
();
LOGD
(
"file:%s line:%i"
,
filename_string
,
linenum
);
// Print line of source code.
v8
::
String
::
Utf8Value
sourceline
(
message
->
GetSourceLine
());
const
char
*
sourceline_string
=
ToCString
(
sourceline
);
LOGD
(
"%s"
,
sourceline_string
);
// Print location information under source line
int
start
=
message
->
GetStartColumn
();
int
end
=
message
->
GetEndColumn
();
char
*
error_string
=
new
char
[
end
];
memset
(
error_string
,
' '
,
start
);
memset
(
&
error_string
[
start
],
'^'
,
end
-
start
);
error_string
[
end
]
=
0
;
LOGD
(
"%s"
,
error_string
);
delete
[]
error_string
;
}
}
void
ErrorCallback
(
v8
::
Handle
<
v8
::
Message
>
message
,
v8
::
Handle
<
v8
::
Value
>
data
)
{
LogErrorMessage
(
message
,
""
);
}
// Report an exception
void
ReportException
(
v8
::
TryCatch
*
try_catch
)
{
v8
::
HandleScope
handle_scope
;
v8
::
String
::
Utf8Value
exception
(
try_catch
->
Exception
());
v8
::
Handle
<
v8
::
Message
>
msg
=
try_catch
->
Message
();
if
(
msg
.
IsEmpty
())
{
// Why is try_catch->Message empty?
// is always empty on compile errors
}
LogErrorMessage
(
msg
,
ToCString
(
exception
));
}
void
testV8
()
{
LOGD
(
"testV8 E:"
);
v8
::
HandleScope
handle_scope
;
v8
::
TryCatch
try_catch
;
// Catch errors as they occur as using ReportException doesn't work??
v8
::
Handle
<
v8
::
Value
>
mydata
(
v8
::
String
::
New
(
"hello"
));
v8
::
V8
::
AddMessageListener
(
ErrorCallback
,
mydata
);
// Create context and make it the current scope
v8
::
Handle
<
v8
::
Context
>
context
=
v8
::
Context
::
New
();
v8
::
Context
::
Scope
context_scope
(
context
);
// Compile the source
v8
::
Handle
<
v8
::
String
>
source
=
v8
::
String
::
New
(
"
\n\n
'Hi
\n\n
"
);
v8
::
Handle
<
v8
::
Script
>
script
=
v8
::
Script
::
Compile
(
source
);
if
(
script
.
IsEmpty
())
{
ReportException
(
&
try_catch
);
}
else
{
// Run the resulting script
v8
::
Handle
<
v8
::
Value
>
result
=
script
->
Run
();
if
(
result
.
IsEmpty
())
{
ReportException
(
&
try_catch
);
}
else
{
v8
::
String
::
Utf8Value
result_string
(
result
);
LOGD
(
"testV8 result=%s"
,
ToCString
(
result_string
));
}
}
LOGD
(
"testV8 X:"
);
}
pthread_t
s_tid_mainloop
;
const
RIL_RadioFunctions
*
RIL_Init
(
const
struct
RIL_Env
*
env
,
int
argc
,
char
**
argv
)
...
...
@@ -167,6 +251,8 @@ const RIL_RadioFunctions *RIL_Init(const struct RIL_Env *env, int argc, char **a
LOGD
(
"RIL_Init E"
);
testV8
();
s_rilenv
=
env
;
ret
=
pthread_attr_init
(
&
attr
);
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment