diff --git a/Lib/javascript/v8/javascripthelpers.swg b/Lib/javascript/v8/javascripthelpers.swg index 5de11feb3..9a80a6552 100644 --- a/Lib/javascript/v8/javascripthelpers.swg +++ b/Lib/javascript/v8/javascripthelpers.swg @@ -43,4 +43,20 @@ void SWIGV8_AddStaticVariable(v8::Handle obj, const char* symbol, v8 obj->SetAccessor(v8::String::NewSymbol(symbol), getter, setter); } +void JS_veto_set_variable(v8::Local property, v8::Local value, const v8::AccessorInfo& info) +{ + char buffer[256]; + char msg[512]; + int res; + + property->WriteUtf8(buffer, 256); + res = sprintf(msg, "Tried to write read-only variable: %s.", buffer); + + if(res<0) { + SWIG_exception(SWIG_ERROR, "Tried to write read-only variable."); + } else { + SWIG_exception(SWIG_ERROR, msg); + } +} + %} // v8_helper_functions diff --git a/Source/Modules/javascript.cxx b/Source/Modules/javascript.cxx index 5f3e01a42..28c4b96b7 100644 --- a/Source/Modules/javascript.cxx +++ b/Source/Modules/javascript.cxx @@ -1591,12 +1591,15 @@ private: String* GLOBAL; String* NULL_STR; + String *VETO_SET; + }; V8Emitter::V8Emitter() : JSEmitter(), GLOBAL(NewString("global")), - NULL_STR(NewString("0")) + NULL_STR(NewString("0")), + VETO_SET(NewString("JS_veto_set_variable")) { } @@ -1604,6 +1607,7 @@ V8Emitter::~V8Emitter() { Delete(GLOBAL); Delete(NULL_STR); + Delete(VETO_SET); } int V8Emitter::initialize(Node *n) @@ -1761,7 +1765,7 @@ int V8Emitter::enterVariable(Node* n) JSEmitter::enterVariable(n); state.variable(GETTER, NULL_STR); - state.variable(SETTER, NULL_STR); + state.variable(SETTER, VETO_SET); return SWIG_OK; }