jat@google.com | 64a55cb | 2009-10-16 14:16:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2007 Google Inc. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | * use this file except in compliance with the License. You may obtain a copy of |
| 6 | * the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | * License for the specific language governing permissions and limitations under |
| 14 | * the License. |
| 15 | */ |
| 16 | |
| 17 | #include "JsRootedValue.h" |
| 18 | |
| 19 | // Initialize static value used to hold the JavaScript String class. |
| 20 | JSClass* JsRootedValue::stringClass = 0; |
| 21 | |
| 22 | // Initialize static reference to the sole JSRuntime value in Gecko. |
| 23 | JSRuntime* JsRootedValue::runtime = 0; |
| 24 | |
| 25 | // Static stack of JavaScript execution contexts. |
| 26 | std::stack<JSContext*> JsRootedValue::contextStack; |
| 27 | |
| 28 | /* |
| 29 | * Actually get the stringClass pointer from JavaScript. |
| 30 | */ |
| 31 | void JsRootedValue::fetchStringClass() const { |
| 32 | Tracer tracer("JsRootedValue::fetchStringClass"); |
| 33 | JSContext* cx = currentContext(); |
| 34 | jsval val = JS_GetEmptyStringValue(cx); |
| 35 | JSObject* obj; |
| 36 | // on error, leave stringClass null |
| 37 | if (!JS_ValueToObject(cx, val, &obj)) return; |
| 38 | if (!obj) { |
| 39 | tracer.log("ensureStringClass: null object"); |
| 40 | return; |
| 41 | } |
| 42 | stringClass = JS_GET_CLASS(cx, obj); |
| 43 | tracer.log("stringClass=%08x", unsigned(stringClass)); |
| 44 | } |