--- /dev/null
+// -*- mode: c++; c-basic-offset: 4 -*-
+/*
+ * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "JSBase.h"
+
+#include "APICast.h"
+
+#include <kjs/ExecState.h>
+#include <kjs/Interpreter.h>
+#include <kjs/JSLock.h>
+#include <kjs/object.h>
+
+using namespace KJS;
+
+JSValueRef JSEvaluateScript(JSContextRef context, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
+{
+ JSLock lock;
+ ExecState* exec = toJS(context);
+ JSObject* jsThisObject = toJS(thisObject);
+ UString::Rep* scriptRep = toJS(script);
+ UString::Rep* sourceURLRep = toJS(sourceURL);
+ // Interpreter::evaluate sets "this" to the global object if it is NULL
+ Completion completion = exec->dynamicInterpreter()->evaluate(UString(sourceURLRep), startingLineNumber, UString(scriptRep), jsThisObject);
+
+ if (completion.complType() == Throw) {
+ if (exception)
+ *exception = toRef(completion.value());
+ return 0;
+ }
+
+ if (completion.value())
+ return toRef(completion.value());
+
+ // happens, for example, when the only statement is an empty (';') statement
+ return toRef(jsUndefined());
+}
+
+bool JSCheckScriptSyntax(JSContextRef context, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
+{
+ JSLock lock;
+
+ ExecState* exec = toJS(context);
+ UString::Rep* scriptRep = toJS(script);
+ UString::Rep* sourceURLRep = toJS(sourceURL);
+ Completion completion = exec->dynamicInterpreter()->checkSyntax(UString(sourceURLRep), startingLineNumber, UString(scriptRep));
+ if (completion.complType() == Throw) {
+ if (exception)
+ *exception = toRef(completion.value());
+ return false;
+ }
+
+ return true;
+}
+
+void JSGarbageCollect()
+{
+ JSLock lock;
+ Collector::collect();
+}
#ifndef JSBase_h
#define JSBase_h
+#include <stdbool.h>
+
/* JavaScript engine interface */
/*! @typedef JSContextRef A JavaScript execution context. Holds the global object and other execution state. */
/*! @typedef JSObjectRef A JavaScript object. A JSObject is a JSValue. */
typedef struct __JSValue* JSObjectRef;
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Script Evaluation */
+
+/*!
+@function
+@abstract Evaluates a string of JavaScript.
+@param context The execution context to use.
+@param script A JSString containing the script to evaluate.
+@param thisObject The object to use as "this," or NULL to use the global object as "this."
+@param sourceURL A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions.
+@param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions.
+@param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
+@result The JSValue that results from evaluating script, or NULL if an exception is thrown.
+*/
+JSValueRef JSEvaluateScript(JSContextRef context, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
+
+/*!
+@function JSCheckScriptSyntax
+@abstract Checks for syntax errors in a string of JavaScript.
+@param context The execution context to use.
+@param script A JSString containing the script to check for syntax errors.
+@param sourceURL A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions.
+@param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions.
+@param exception A pointer to a JSValueRef in which to store a syntax error exception, if any. Pass NULL if you do not care to store a syntax error exception.
+@result true if the script is syntactically correct, otherwise false.
+*/
+bool JSCheckScriptSyntax(JSContextRef context, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
+
+/*!
+@function
+@abstract Performs a JavaScript garbage collection.
+@discussion JavaScript values that are on the machine stack, in a register,
+ protected by JSValueProtect, set as the global object of an execution context,
+ or reachable from any such value will not be collected.
+
+ You are not required to call this function; the JavaScript engine will garbage
+ collect as needed.
+*/
+void JSGarbageCollect(void);
+
+#ifdef __cplusplus
+}
+#endif
+
#endif // JSBase_h
ExecState* exec = toJS(context);
return toRef(exec->dynamicInterpreter()->globalObject());
}
-
-JSValueRef JSEvaluateScript(JSContextRef context, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
-{
- JSLock lock;
- ExecState* exec = toJS(context);
- JSObject* jsThisObject = toJS(thisObject);
- UString::Rep* scriptRep = toJS(script);
- UString::Rep* sourceURLRep = toJS(sourceURL);
- // Interpreter::evaluate sets "this" to the global object if it is NULL
- Completion completion = exec->dynamicInterpreter()->evaluate(UString(sourceURLRep), startingLineNumber, UString(scriptRep), jsThisObject);
-
- if (completion.complType() == Throw) {
- if (exception)
- *exception = toRef(completion.value());
- return 0;
- }
-
- if (completion.value())
- return toRef(completion.value());
-
- // happens, for example, when the only statement is an empty (';') statement
- return toRef(jsUndefined());
-}
-
-bool JSCheckScriptSyntax(JSContextRef context, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
-{
- JSLock lock;
-
- ExecState* exec = toJS(context);
- UString::Rep* scriptRep = toJS(script);
- UString::Rep* sourceURLRep = toJS(sourceURL);
- Completion completion = exec->dynamicInterpreter()->checkSyntax(UString(sourceURLRep), startingLineNumber, UString(scriptRep));
- if (completion.complType() == Throw) {
- if (exception)
- *exception = toRef(completion.value());
- return false;
- }
-
- return true;
-}
*/
JSObjectRef JSContextGetGlobalObject(JSContextRef context);
-// Evaluation
-/*!
-@function
-@abstract Evaluates a string of JavaScript.
-@param context The execution context to use.
-@param script A JSString containing the script to evaluate.
-@param thisObject The object to use as "this," or NULL to use the global object as "this."
-@param sourceURL A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions.
-@param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions.
-@param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
-@result The JSValue that results from evaluating script, or NULL if an exception is thrown.
-*/
-JSValueRef JSEvaluateScript(JSContextRef context, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
-
-/*!
-@function JSCheckScriptSyntax
-@abstract Checks for syntax errors in a string of JavaScript.
-@param context The execution context to use.
-@param script A JSString containing the script to check for syntax errors.
-@param sourceURL A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions.
-@param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions.
-@param exception A pointer to a JSValueRef in which to store a syntax error exception, if any. Pass NULL if you do not care to store a syntax error exception.
-@result true if the script is syntactically correct, otherwise false.
-*/
-bool JSCheckScriptSyntax(JSContextRef context, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
-
#ifdef __cplusplus
}
#endif
JSValue* jsValue = toJS(value);
gcUnprotect(jsValue);
}
-
-void JSGarbageCollect()
-{
- JSLock lock;
- Collector::collect();
-}
*/
void JSValueUnprotect(JSValueRef value);
-/*!
-@function
-@abstract Performs a JavaScript garbage collection.
-@discussion JavaScript values that are on the machine stack, in a register,
- protected by JSValueProtect, set as the global object of an execution context,
- or reachable from any such value will not be collected.
-
- You are not required to call this function; the JavaScript engine will garbage
- collect as needed.
-*/
-void JSGarbageCollect(void);
-
#ifdef __cplusplus
}
#endif
+2006-07-14 Geoffrey Garen <ggaren@apple.com>
+
+ Reviewed by Beth.
+
+ Moved JSCheckScriptSyntax, JSEvaluateScript, and JSGarbageCollect into
+ JSBase.h/.cpp. They don't belong in the value-specific or context-specific
+ files because they're not part of the value or context implementations.
+
+ * API/JSBase.h:
+ * API/JSContextRef.cpp:
+ (JSContextGetGlobalObject):
+ * API/JSContextRef.h:
+ * API/JSValueRef.cpp:
+ (JSValueUnprotect):
+ * API/JSValueRef.h:
+ * JavaScriptCore.xcodeproj/project.pbxproj:
+
2006-07-13 Timothy Hatcher <timothy@apple.com>
Reviewed by Maciej.
/* Begin PBXBuildFile section */
141211310A48794D00480255 /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 932F5BD90822A1C700736975 /* JavaScriptCore.framework */; };
141211340A48795800480255 /* minidom.c in Sources */ = {isa = PBXBuildFile; fileRef = 141211020A48780900480255 /* minidom.c */; };
+ 1421359B0A677F4F00A8195E /* JSBase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1421359A0A677F4F00A8195E /* JSBase.cpp */; };
142711390A460BBB0080EEEA /* JSBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 142711380A460BBB0080EEEA /* JSBase.h */; settings = {ATTRIBUTES = (Private, ); }; };
143A97E60A4A06E200456B66 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6560A4CF04B3B3E7008AE952 /* CoreFoundation.framework */; };
1440057F0A5335640005F061 /* JSNode.c in Sources */ = {isa = PBXBuildFile; fileRef = 1440F6420A4F8B6A0005F061 /* JSNode.c */; };
141211020A48780900480255 /* minidom.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = minidom.c; sourceTree = "<group>"; };
1412110D0A48788700480255 /* minidom.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = minidom.js; sourceTree = "<group>"; };
141211200A48793C00480255 /* minidom */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = minidom; sourceTree = BUILT_PRODUCTS_DIR; };
+ 1421359A0A677F4F00A8195E /* JSBase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSBase.cpp; sourceTree = "<group>"; };
142711380A460BBB0080EEEA /* JSBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSBase.h; sourceTree = "<group>"; };
1440051F0A531D3B0005F061 /* Node.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Node.h; sourceTree = "<group>"; };
144005200A531D3B0005F061 /* Node.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Node.c; sourceTree = "<group>"; };
children = (
1482B78A0A4305AB00517CFC /* APICast.h */,
14BD5A2F0A3E91F600BAF59C /* JavaScriptCore.h */,
+ 1421359A0A677F4F00A8195E /* JSBase.cpp */,
142711380A460BBB0080EEEA /* JSBase.h */,
1440F8AD0A508D200005F061 /* JSCallbackConstructor.cpp */,
1440F8AC0A508D200005F061 /* JSCallbackConstructor.h */,
1440F8920A508B100005F061 /* JSCallbackFunction.cpp in Sources */,
1440F8AF0A508D200005F061 /* JSCallbackConstructor.cpp in Sources */,
1440FCE40A51E46B0005F061 /* JSClassRef.cpp in Sources */,
+ 1421359B0A677F4F00A8195E /* JSBase.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};