File tree Expand file tree Collapse file tree 3 files changed +25
-3
lines changed Expand file tree Collapse file tree 3 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,20 @@ namespace V8GLUtils {
32
32
delete[] tmp_js_path;
33
33
}
34
34
35
+ char *pushRootPath (char *new_path) {
36
+ char *old_path = root_path;
37
+ char *pch = strrchr (new_path, V8GLUtils::separator);
38
+ int last_index = pch ? (pch - new_path + 1 ) : 2 ;
39
+ root_path = new char [last_index + 1 ];
40
+ strncpy (root_path, pch ? new_path : " ./" , last_index);
41
+ root_path[last_index] = ' \0 ' ;
42
+ return old_path;
43
+ }
44
+ void popRootPath (char *old_path) {
45
+ delete[] root_path;
46
+ root_path = old_path;
47
+ }
48
+
35
49
char * getRootPath (void ) {
36
50
return V8GLUtils::root_path;
37
51
}
Original file line number Diff line number Diff line change @@ -6,6 +6,9 @@ namespace V8GLUtils {
6
6
7
7
char * getRootPath (void );
8
8
char * getRealPath (char * file_path);
9
+
10
+ char *pushRootPath (char *new_path);
11
+ void popRootPath (char *old_path);
9
12
};
10
13
11
14
#endif
Original file line number Diff line number Diff line change @@ -146,10 +146,15 @@ Handle<Value> load(const Arguments& args) {
146
146
// get argument
147
147
String::Utf8Value value0 (args[i]);
148
148
char * arg0 = *value0;
149
- string str (V8GLUtils::getRealPath (arg0));
150
- if (!exec (str)) {
149
+ char * filepath = V8GLUtils::getRealPath (arg0);
150
+
151
+ char *old_path = V8GLUtils::pushRootPath (filepath);
152
+ bool success = exec (string (filepath));
153
+ V8GLUtils::popRootPath (old_path);
154
+
155
+ if (!success) {
151
156
fprintf (stderr, " Error reading '%s'.\n " , arg0);
152
- return v8::Undefined ( );
157
+ return ThrowException ( String::New ( " Failed to load script " ) );
153
158
}
154
159
}
155
160
You can’t perform that action at this time.
0 commit comments