From 1209b88e96f253cdc19aa4c95e011c84597844f0 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 25 May 2011 10:36:13 +1000 Subject: [PATCH 06/15] Allow access to the calling script data --- include/v8.h | 1 + src/api.cc | 12 ++++++++++++ 2 files changed, 13 insertions(+), 0 deletions(-) diff --git a/include/v8.h b/include/v8.h index d78ab1f..2bc0ed1 100644 --- a/include/v8.h +++ b/include/v8.h @@ -3337,6 +3337,7 @@ class V8EXPORT Context { */ static Local GetCalling(); static Local GetCallingQmlGlobal(); + static Local GetCallingScriptData(); /** * Sets the security token for the context. To access an object in diff --git a/src/api.cc b/src/api.cc index 39767f4..ff74efb 100644 --- a/src/api.cc +++ b/src/api.cc @@ -3976,6 +3976,18 @@ v8::Local Context::GetCallingQmlGlobal() { } } +v8::Local Context::GetCallingScriptData() +{ + i::Isolate* isolate = i::Isolate::Current(); + if (IsDeadCheck(isolate, "v8::Context::GetCallingScriptData()")) { + return Local(); + } + + i::JavaScriptFrameIterator it; + if (it.done()) return Local(); + i::Handle script(i::Script::cast(i::JSFunction::cast(it.frame()->function())->shared()->script())); + return Utils::ToLocal(i::Handle(script->data())); +} v8::Local Context::Global() { if (IsDeadCheck(i::Isolate::Current(), "v8::Context::Global()")) { -- 1.7.4.4