internal.h
来自「konqueror3 embedded版本, KDE环境下的当家浏览器的嵌入式版」· C头文件 代码 · 共 509 行 · 第 1/2 页
H
509 行
// -*- c-basic-offset: 2 -*-/* * This file is part of the KDE libraries * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) * Copyright (C) 2001 Peter Kelly (pmk@post.com) * Copyright (C) 2003 Apple Computer, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */#ifndef _INTERNAL_H_#define _INTERNAL_H_#include "ustring.h"#include "value.h"#include "object.h"#include "function.h"#include "types.h"#include "interpreter.h"#include "scope_chain.h"#include "array_instance.h"#ifndef I18N_NOOP#define I18N_NOOP(s) s#endifnamespace KJS { static const double D16 = 65536.0; static const double D32 = 4294967296.0; class FunctionBodyNode; class FunctionBodyNode; class FunctionPrototypeImp; class FunctionImp; class Parameter; class Debugger; // --------------------------------------------------------------------------- // Primitive impls // --------------------------------------------------------------------------- class UndefinedImp : public ValueImp { public: Type type() const { return UndefinedType; } Value toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const; bool toBoolean(ExecState *exec) const; double toNumber(ExecState *exec) const; UString toString(ExecState *exec) const; Object toObject(ExecState *exec) const; static UndefinedImp *staticUndefined; }; inline Undefined::Undefined(UndefinedImp *imp) : Value(imp) { } class NullImp : public ValueImp { public: Type type() const { return NullType; } Value toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const; bool toBoolean(ExecState *exec) const; double toNumber(ExecState *exec) const; UString toString(ExecState *exec) const; Object toObject(ExecState *exec) const; static NullImp *staticNull; }; inline Null::Null(NullImp *imp) : Value(imp) { } class BooleanImp : public ValueImp { public: BooleanImp(bool v = false) : val(v) { } bool value() const { return val; } Type type() const { return BooleanType; } Value toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const; bool toBoolean(ExecState *exec) const; double toNumber(ExecState *exec) const; UString toString(ExecState *exec) const; Object toObject(ExecState *exec) const; static BooleanImp *staticTrue; static BooleanImp *staticFalse; private: bool val; }; inline Boolean::Boolean(BooleanImp *imp) : Value(imp) { } class StringImp : public ValueImp { public: StringImp(const UString& v) : val(v) { } UString value() const { return val; } Type type() const { return StringType; } Value toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const; bool toBoolean(ExecState *exec) const; double toNumber(ExecState *exec) const; UString toString(ExecState *exec) const; Object toObject(ExecState *exec) const; private: UString val; }; inline String::String(StringImp *imp) : Value(imp) { } class NumberImp : public ValueImp { friend class Number; friend class InterpreterImp; public: static ValueImp *create(int); static ValueImp *create(double); static ValueImp *zero() { return SimpleNumber::make(0); } static ValueImp *one() { return SimpleNumber::make(1); } static ValueImp *two() { return SimpleNumber::make(2); } double value() const { return val; } Type type() const { return NumberType; } Value toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const; bool toBoolean(ExecState *exec) const; double toNumber(ExecState *exec) const; UString toString(ExecState *exec) const; Object toObject(ExecState *exec) const; static NumberImp *staticNaN; private: NumberImp(double v) : val(v) { } virtual bool toUInt32(unsigned&) const; double val; }; inline Number::Number(NumberImp *imp) : Value(imp) { } /** * @short The "label set" in Ecma-262 spec */ class LabelStack { public: LabelStack(): tos(0L), iterationDepth(0), switchDepth(0) {} ~LabelStack(); LabelStack(const LabelStack &other); LabelStack &operator=(const LabelStack &other); /** * If id is not empty and is not in the stack already, puts it on top of * the stack and returns true, otherwise returns false */ bool push(const Identifier &id); /** * Is the id in the stack? */ bool contains(const Identifier &id) const; /** * Removes from the stack the last pushed id (what else?) */ void pop(); void pushIteration() { iterationDepth++; } void popIteration() { iterationDepth--; } bool inIteration() const { return (iterationDepth > 0); } void pushSwitch() { switchDepth++; } void popSwitch() { switchDepth--; } bool inSwitch() const { return (switchDepth > 0); } private: struct StackElem { Identifier id; StackElem *prev; }; StackElem *tos; void clear(); int iterationDepth; int switchDepth; }; // --------------------------------------------------------------------------- // Parsing & evaluateion // --------------------------------------------------------------------------- class SourceCode { public: SourceCode(int _sid) : sid(_sid), interpreter(0), refcount(0), next(0) {} void ref() { refcount++; } void deref() { if (!--refcount) cleanup(); } void cleanup(); int sid; InterpreterImp *interpreter; int refcount; SourceCode *next; }; /** * @internal * * Parses ECMAScript source code and converts into FunctionBodyNode objects, which * represent the root of a parse tree. This class provides a conveniant workaround * for the problem of the bison parser working in a static context. */ class Parser { public: static FunctionBodyNode *parse(const UChar *code, unsigned int length, SourceCode **src, int *errLine = 0, UString *errMsg = 0); static FunctionBodyNode *progNode; static SourceCode *source; static int sid; private: }; class InterpreterImp { friend class Collector; public: static void globalInit(); static void globalClear(); InterpreterImp(Interpreter *interp, const Object &glob); ~InterpreterImp(); Object &globalObject() const { return const_cast<Object &>(global); } Interpreter* interpreter() const { return m_interpreter; } void initGlobalObject(); static void lock();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?