// init the interpreter
  KJScript* kjs_create(KHTMLPart *khtmlpart)
  {
    KJScript *script = new KJScript();
#ifndef NDEBUG
    script->enableDebug();
#endif
    KJS::Global global(Global::current());

    KJSO window(newWindow(khtmlpart));
    global.put("window", window);
    // make "window" prefix implicit for shortcuts like alert()
    global.setFilter(window);
    global.setPrototype(window);

    return script;
  }
Example #2
0
int main(int, char **)
{
  KJScript kjs;
  kjs.enableDebug();
  DOM::Document doc;

  DOMDocument *dd = new DOMDocument(&doc);
  Global::current().put("document", KJSO(dd));

  printf("Entering interactive mode.\n"
	 "You may access the DOM via the 'document' property.\n"
	 "Use debug() to print to the console. Press C-d or C-c to exit.\n\n");

  char buffer[1000];
  FILE *in = fdopen(0, "r");

  while (1) {
    printf("KJS> ");
    if (!fgets(buffer, 999, in))
      break;
    kjs.evaluate(buffer);
  }
  printf("\n");
}