Completion.cpp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
  3. * Copyright (C) 2001 Peter Kelly (pmk@post.com)
  4. * Copyright (C) 2003, 2007 Apple Inc.
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Library General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Library General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Library General Public License
  17. * along with this library; see the file COPYING.LIB. If not, write to
  18. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19. * Boston, MA 02110-1301, USA.
  20. *
  21. */
  22. #include "config.h"
  23. #include "Completion.h"
  24. #include "CallFrame.h"
  25. #include "CodeProfiling.h"
  26. #include "Debugger.h"
  27. #include "Interpreter.h"
  28. #include "JSGlobalObject.h"
  29. #include "JSLock.h"
  30. #include "Operations.h"
  31. #include "Parser.h"
  32. #include <wtf/WTFThreadData.h>
  33. #include <stdio.h>
  34. namespace JSC {
  35. bool checkSyntax(ExecState* exec, const SourceCode& source, JSValue* returnedException)
  36. {
  37. JSLockHolder lock(exec);
  38. RELEASE_ASSERT(exec->vm().identifierTable == wtfThreadData().currentIdentifierTable());
  39. ProgramExecutable* program = ProgramExecutable::create(exec, source);
  40. JSObject* error = program->checkSyntax(exec);
  41. if (error) {
  42. if (returnedException)
  43. *returnedException = error;
  44. return false;
  45. }
  46. return true;
  47. }
  48. bool checkSyntax(VM& vm, const SourceCode& source, ParserError& error)
  49. {
  50. JSLockHolder lock(vm);
  51. RELEASE_ASSERT(vm.identifierTable == wtfThreadData().currentIdentifierTable());
  52. RefPtr<ProgramNode> programNode = parse<ProgramNode>(&vm, source, 0, Identifier(), JSParseNormal, JSParseProgramCode, error);
  53. return programNode;
  54. }
  55. JSValue evaluate(ExecState* exec, const SourceCode& source, JSValue thisValue, JSValue* returnedException)
  56. {
  57. JSLockHolder lock(exec);
  58. RELEASE_ASSERT(exec->vm().identifierTable == wtfThreadData().currentIdentifierTable());
  59. RELEASE_ASSERT(!exec->vm().isCollectorBusy());
  60. CodeProfiling profile(source);
  61. ProgramExecutable* program = ProgramExecutable::create(exec, source);
  62. if (!program) {
  63. if (returnedException)
  64. *returnedException = exec->vm().exception;
  65. exec->vm().exception = JSValue();
  66. return jsUndefined();
  67. }
  68. if (!thisValue || thisValue.isUndefinedOrNull())
  69. thisValue = exec->dynamicGlobalObject();
  70. JSObject* thisObj = thisValue.toThisObject(exec);
  71. JSValue result = exec->interpreter()->execute(program, exec, thisObj);
  72. if (exec->hadException()) {
  73. if (returnedException)
  74. *returnedException = exec->exception();
  75. exec->clearException();
  76. return jsUndefined();
  77. }
  78. RELEASE_ASSERT(result);
  79. return result;
  80. }
  81. } // namespace JSC