KHtml

testecma.cpp
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (C) 2000 Harri Porten ([email protected])
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 /**
21  * An interactive interpreter to test the ECMA Script language bindings
22  * for the DOM of KHTML.
23  * The 'document' property is preset to an instance of Document and serves
24  * as an entrypoint.
25  *
26  * Example session:
27  *
28  * KJS> text = document.createTextNode('foo');
29  * KJS> document.appendChild(text);
30  * KJS> debug(document.firstChild.nodeValue);
31  * ---> foo
32  */
33 
34 #include <stdio.h>
35 #include <kjs/object.h>
36 #include <kjs/interpreter.h>
37 #include "dom/dom_doc.h"
38 #include "dom/dom_string.h"
39 #include "ecma/kjs_dom.h"
40 
41 using namespace KJS;
42 
43 int main(int, char **)
44 {
45  KJScript kjs;
46  kjs.enableDebug();
47  DOM::Document doc;
48 
49  DOMDocument *dd = new DOMDocument(&doc);
50  Global::current().put("document", KJSO(dd));
51 
52  printf("Entering interactive mode.\n"
53  "You may access the DOM via the 'document' property.\n"
54  "Use debug() to print to the console. Press C-d or C-c to exit.\n\n");
55 
56  char buffer[1000];
57  FILE *in = fdopen(0, "r");
58 
59  while (1) {
60  printf("KJS> ");
61  if (!fgets(buffer, 999, in)) {
62  break;
63  }
64  kjs.evaluate(buffer);
65  }
66  printf("\n");
67 }
The Document interface represents the entire HTML or XML document.
Definition: dom_doc.h:246
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Oct 25 2021 22:48:23 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.