/src/3rdparty/webkit/Source/WebCore/bridge/c/c_runtime.cpp

https://bitbucket.org/ultra_iter/qt-vtl · C++ · 85 lines · 49 code · 12 blank · 24 comment · 3 complexity · 10b4de880a3294c700811b3b72edc2f0 MD5 · raw file

  1. /*
  2. * Copyright (C) 2004 Apple Computer, Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
  17. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  21. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "config.h"
  26. #if ENABLE(NETSCAPE_PLUGIN_API)
  27. #include "c_runtime.h"
  28. #include "c_instance.h"
  29. #include "c_utility.h"
  30. #include "npruntime_impl.h"
  31. #include <runtime/ScopeChain.h>
  32. #include <runtime/JSLock.h>
  33. #include <runtime/JSObject.h>
  34. namespace JSC {
  35. namespace Bindings {
  36. JSValue CField::valueFromInstance(ExecState* exec, const Instance* inst) const
  37. {
  38. const CInstance* instance = static_cast<const CInstance*>(inst);
  39. NPObject* obj = instance->getObject();
  40. if (obj->_class->getProperty) {
  41. NPVariant property;
  42. VOID_TO_NPVARIANT(property);
  43. bool result;
  44. {
  45. JSLock::DropAllLocks dropAllLocks(SilenceAssertionsOnly);
  46. result = obj->_class->getProperty(obj, _fieldIdentifier, &property);
  47. CInstance::moveGlobalExceptionToExecState(exec);
  48. }
  49. if (result) {
  50. JSValue result = convertNPVariantToValue(exec, &property, instance->rootObject());
  51. _NPN_ReleaseVariantValue(&property);
  52. return result;
  53. }
  54. }
  55. return jsUndefined();
  56. }
  57. void CField::setValueToInstance(ExecState *exec, const Instance *inst, JSValue aValue) const
  58. {
  59. const CInstance* instance = static_cast<const CInstance*>(inst);
  60. NPObject* obj = instance->getObject();
  61. if (obj->_class->setProperty) {
  62. NPVariant variant;
  63. convertValueToNPVariant(exec, aValue, &variant);
  64. {
  65. JSLock::DropAllLocks dropAllLocks(SilenceAssertionsOnly);
  66. obj->_class->setProperty(obj, _fieldIdentifier, &variant);
  67. CInstance::moveGlobalExceptionToExecState(exec);
  68. }
  69. _NPN_ReleaseVariantValue(&variant);
  70. }
  71. }
  72. } }
  73. #endif // ENABLE(NETSCAPE_PLUGIN_API)