Project

General

Profile

Bug #164

Updated by Igor Pashev over 10 years ago

http://cgit.osdyson.org/pkg-webkit/webkit.git/ 

 With JIT enabled I can't use JS functions: 
 <pre> 
 pashev@bok:~/js$ ./js 'var f = function(x) {return x}; f(0)' 
 TypeError: function is not a function (evaluating 'f(0)') 

 pashev@bok:~/js$ ./js 'Math.sin(9)' 
 0.4121184852417566 
 </pre> 

 <pre> 
 g++ -O0 -g js.cpp -o js -I /usr/include/webkitgtk-1.0/JavaScriptCore/ -I /usr/include/webkitgtk-1.0/ -ljavascriptcoregtk-1.0 
 </pre> 

 *js.cpp:* 
 <pre> 
 #include "JSBase.h" 
 #include "JSObjectRef.h" 
 #include "JSStringRef.h" 
 #include "JSContextRef.h" 
 #include <stdio.h> 
 #include <stdlib.h> 

 static const char *progname; 
 static char buf[1024]; 

 void usage(FILE *out) 
 { 
   fprintf(out, "Usage: %s <js-script>\n", progname); 
 } 

 void usageError() 
 { 
   usage(stderr); 
   exit(1); 
 } 

 static void evaluate(const char *text) 
 { 
   JSGlobalContextRef context = JSGlobalContextCreateInGroup(NULL, NULL); 
   JSValueRef exception; 
   JSStringRef script = JSStringCreateWithUTF8CString(text); 
   JSValueRef result = JSEvaluateScript(context, script, NULL, NULL, 1, &exception); 
   if (result) 
     { 
       JSStringRef str = JSValueToStringCopy(context, result, NULL); 
       (void) JSStringGetUTF8CString(str, buf, sizeof(buf)); 
       printf("%s\n", buf); 
     } 
   else 
     { 
       JSStringRef exceptionIString = JSValueToStringCopy(context, exception, NULL); 
       size_t exceptionUTF8Size = JSStringGetMaximumUTF8CStringSize(exceptionIString); 
       char* exceptionUTF8 = (char*)malloc(exceptionUTF8Size); 
       JSStringGetUTF8CString(exceptionIString, exceptionUTF8, exceptionUTF8Size); 
       printf("%s\n", exceptionUTF8); 
       free(exceptionUTF8); 
       JSStringRelease(exceptionIString); 
     } 
 } 


 int main(int argc, char* argv[]) 
 { 
   progname = argv[0]; 
   if (argc != 2) 
     usageError(); 
   evaluate(argv[1]); 
   return 0; 
 } 
 </pre> 

Back